parent
dc3c55e2f1
commit
22703407d2
@ -0,0 +1,77 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright 2015 Calculate Ltd. http://www.calculate-linux.org
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from calculate.core.server.func import Action, Tasks
|
||||||
|
from calculate.lib.cl_lang import setLocalTranslate, getLazyLocalTranslate
|
||||||
|
from calculate.lib.utils.files import FilesError
|
||||||
|
from ..datavars import BuilderError
|
||||||
|
from calculate.lib.utils.portage import GitError
|
||||||
|
from calculate.install.distr import DistributiveError, IsoDistributive
|
||||||
|
|
||||||
|
setLocalTranslate('cl_builder3', sys.modules[__name__])
|
||||||
|
__ = getLazyLocalTranslate(_)
|
||||||
|
|
||||||
|
|
||||||
|
class ClBuilderImageAction(Action):
|
||||||
|
"""
|
||||||
|
Действие обновление конфигурационных файлов
|
||||||
|
"""
|
||||||
|
# ошибки, которые отображаются без подробностей
|
||||||
|
native_error = (DistributiveError, FilesError, BuilderError, GitError)
|
||||||
|
|
||||||
|
successMessage = __("Image created successfully")
|
||||||
|
failedMessage = __("Creating the image is failed")
|
||||||
|
interruptMessage = __("Image creating manually interrupted")
|
||||||
|
|
||||||
|
# список задач для действия
|
||||||
|
tasks = [
|
||||||
|
# закрепить подключенные данные
|
||||||
|
{'name': 'detach',
|
||||||
|
'message': __("Detach target"),
|
||||||
|
'method': 'Builder.detach_target(cl_builder_target)',
|
||||||
|
},
|
||||||
|
{'name': 'umount_system',
|
||||||
|
'message': __("Umount build system resources"),
|
||||||
|
'method': 'Builder.umount_system(cl_builder_target)',
|
||||||
|
'condition': lambda Get: Get('cl_builder_build')
|
||||||
|
},
|
||||||
|
{'name': 'prepare_image',
|
||||||
|
'method': 'Builder.prepare_image(cl_builder_image)',
|
||||||
|
'condition': lambda Get: isinstance(Get('cl_builder_image'),
|
||||||
|
IsoDistributive)
|
||||||
|
},
|
||||||
|
{'name': 'squash_action',
|
||||||
|
'method': 'Builder.set_builder_action("squash")',
|
||||||
|
},
|
||||||
|
{'name': 'apply_template',
|
||||||
|
'message': __("Configuring squash"),
|
||||||
|
# наложить шаблоны в развернутый дистрибутив
|
||||||
|
'method': 'Builder.applyTemplates(cl_builder_target,False,False,None)',
|
||||||
|
},
|
||||||
|
{'name': 'squash_action',
|
||||||
|
'method': 'Builder.set_builder_action("iso")',
|
||||||
|
},
|
||||||
|
# распаковка дистрибутива
|
||||||
|
{'name': 'unpack',
|
||||||
|
'message': __("Pack squash"),
|
||||||
|
'method': 'Install.unpack(cl_builder_target, cl_builder_image, "0")',
|
||||||
|
},
|
||||||
|
{'name': 'umount_system!:mount_system',
|
||||||
|
'warning': _("Restore build system resources"),
|
||||||
|
'method': 'Builder.mount_target(cl_builder_target)',
|
||||||
|
'condition': lambda Get: Get('cl_builder_build')
|
||||||
|
}]
|
@ -0,0 +1,330 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright 2015 Calculate Ltd. http://www.calculate-linux.org
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
from os import path
|
||||||
|
from calculate.lib.datavars import (ReadonlyVariable, FieldValue, VariableError,
|
||||||
|
DataVarsError, Variable)
|
||||||
|
from calculate.lib.utils.portage import GitError
|
||||||
|
from calculate.lib.variables import linux as lib_linux
|
||||||
|
from calculate.install import distr
|
||||||
|
from calculate.update.variables import update
|
||||||
|
from calculate.update import profile as update_profile
|
||||||
|
|
||||||
|
|
||||||
|
from calculate.lib.cl_lang import setLocalTranslate
|
||||||
|
|
||||||
|
setLocalTranslate('cl_builder3', sys.modules[__name__])
|
||||||
|
|
||||||
|
class VariableClBuilderProfileStorage(ReadonlyVariable):
|
||||||
|
type = "object"
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
return update_profile.RepositoryStorageSet(
|
||||||
|
update_profile.CacheStorage('/var/calculate/tmp/update'))
|
||||||
|
|
||||||
|
|
||||||
|
class VariableClBuilderProfileUrl(update.VariableClUpdateProfileUrl):
|
||||||
|
"""
|
||||||
|
URL репозитория
|
||||||
|
"""
|
||||||
|
check_after = ["cl_builder_profile_branch"]
|
||||||
|
|
||||||
|
def check(self, value):
|
||||||
|
action = self.Get('cl_action')
|
||||||
|
if not value and action == 'create':
|
||||||
|
branch = self.Get('cl_builder_profile_branch')
|
||||||
|
if branch != update_profile.DEFAULT_BRANCH:
|
||||||
|
raise VariableError("Need to specify profile repository")
|
||||||
|
return
|
||||||
|
if not value:
|
||||||
|
raise VariableError("Need to specify profile repository")
|
||||||
|
try:
|
||||||
|
branch = self.Get('cl_builder_profile_branch')
|
||||||
|
self.Get('cl_builder_profile_storage').get_profiles(value, branch)
|
||||||
|
except GitError as e:
|
||||||
|
raise VariableError(str(e))
|
||||||
|
if not self.Get('cl_builder_profile_shortname'):
|
||||||
|
raise VariableError(_("Repository %s has no profiles")%value)
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
action = self.Get('cl_action')
|
||||||
|
if action == 'create':
|
||||||
|
return ""
|
||||||
|
if action in ("image"):
|
||||||
|
return update.VariableClUpdateProfileUrl.get(self)
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
class VariableClBuilderProfileBranch(update.VariableClUpdateProfileBranch):
|
||||||
|
"""
|
||||||
|
Текущая ветка репозитория
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
action = self.Get('cl_action')
|
||||||
|
if action in ("image"):
|
||||||
|
pass
|
||||||
|
#rep_set = self.Get('cl_update_profile_storage')
|
||||||
|
#url = self.Get('cl_update_profile_url')
|
||||||
|
##print url, rep_set.is_local(url, branch=None)
|
||||||
|
#if rep_set.is_local(url, branch=None):
|
||||||
|
# rep = rep_set.get_repository(url, branch=None)
|
||||||
|
# git = Git()
|
||||||
|
# return git.getBranch(rep.directory)
|
||||||
|
return update_profile.DEFAULT_BRANCH
|
||||||
|
|
||||||
|
class VariableClProfileCacheRepository(ReadonlyVariable):
|
||||||
|
"""
|
||||||
|
Репозиторий из которого будет извлечён список профилей
|
||||||
|
"""
|
||||||
|
type = "object"
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
url = self.Get('cl_builder_profile_url')
|
||||||
|
if not url:
|
||||||
|
return ""
|
||||||
|
try:
|
||||||
|
rep_set = self.Get('cl_builder_profile_storage')
|
||||||
|
branch = self.Get('cl_builder_profile_branch')
|
||||||
|
rep = rep_set.get_repository(url, branch)
|
||||||
|
#if rep and self.Get('cl_update_profile_sync_set') == 'on':
|
||||||
|
if rep:
|
||||||
|
rep.sync()
|
||||||
|
return rep_set.get_repository(url, branch) or ""
|
||||||
|
except GitError:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
class VariableClProfileCacheData(update.VariableClProfileData):
|
||||||
|
source = []
|
||||||
|
|
||||||
|
repository = "cl_profile_cache_repository"
|
||||||
|
|
||||||
|
class VariableClBuilderProfileData(update.VariableClProfileData):
|
||||||
|
type = "table"
|
||||||
|
source = ["cl_builder_profile_fullname",
|
||||||
|
"cl_builder_profile_shortname",
|
||||||
|
"cl_builder_profile_path",
|
||||||
|
"cl_builder_profile_arch"]
|
||||||
|
|
||||||
|
def init(self):
|
||||||
|
self.label = "test"
|
||||||
|
|
||||||
|
def get(self, hr=False):
|
||||||
|
url = self.Get('cl_builder_profile_url')
|
||||||
|
if not url:
|
||||||
|
dv = self.Get('cl_builder_linux_datavars')
|
||||||
|
if dv:
|
||||||
|
return dv['cl_profile_data']
|
||||||
|
return [[]]
|
||||||
|
else:
|
||||||
|
return self.Get('cl_profile_cache_data')
|
||||||
|
|
||||||
|
|
||||||
|
class VariableClBuilderProfileFullname(FieldValue, ReadonlyVariable):
|
||||||
|
"""
|
||||||
|
Полное название профиля
|
||||||
|
"""
|
||||||
|
type = "list"
|
||||||
|
source_variable = "cl_builder_profile_data"
|
||||||
|
column = 0
|
||||||
|
|
||||||
|
|
||||||
|
class VariableClBuilderProfileShortname(FieldValue, ReadonlyVariable):
|
||||||
|
"""
|
||||||
|
Полное название профиля
|
||||||
|
"""
|
||||||
|
type = "list"
|
||||||
|
source_variable = "cl_builder_profile_data"
|
||||||
|
column = 1
|
||||||
|
|
||||||
|
|
||||||
|
class VariableClBuilderProfilePath(FieldValue, ReadonlyVariable):
|
||||||
|
"""
|
||||||
|
Полное название профиля
|
||||||
|
"""
|
||||||
|
type = "list"
|
||||||
|
source_variable = "cl_builder_profile_data"
|
||||||
|
column = 2
|
||||||
|
|
||||||
|
|
||||||
|
class VariableClBuilderProfileArch(FieldValue, ReadonlyVariable):
|
||||||
|
"""
|
||||||
|
Полное название профиля
|
||||||
|
"""
|
||||||
|
type = "list"
|
||||||
|
source_variable = "cl_builder_profile_data"
|
||||||
|
column = 3
|
||||||
|
|
||||||
|
|
||||||
|
class VariableClBuilderProfileSystemShortname(Variable):
|
||||||
|
"""
|
||||||
|
Профиль системы
|
||||||
|
"""
|
||||||
|
type = "choice"
|
||||||
|
opt = ["--profile"]
|
||||||
|
untrusted = True
|
||||||
|
metavalue = "PROFILE"
|
||||||
|
|
||||||
|
def init(self):
|
||||||
|
self.label = _("System profile")
|
||||||
|
self.help = _("set the system profile")
|
||||||
|
|
||||||
|
def check_profile(self, path_profile, profile_fullname):
|
||||||
|
if path_profile:
|
||||||
|
dv = update.DataVarsUpdateProfile(path_profile)
|
||||||
|
if ":" in profile_fullname:
|
||||||
|
repo_name = profile_fullname.partition(":")[0]
|
||||||
|
else:
|
||||||
|
repo_name = ""
|
||||||
|
try:
|
||||||
|
if (not dv.Get('cl_update_rep_name') or
|
||||||
|
not dv.Get('cl_update_rep_url')):
|
||||||
|
raise VariableError(_("Repository variables "
|
||||||
|
"were not configured for the profile"))
|
||||||
|
if not dv.Get('os_linux_name'):
|
||||||
|
raise VariableError("")
|
||||||
|
if repo_name not in list(dv.Get('cl_update_rep_name')):
|
||||||
|
raise VariableError(
|
||||||
|
_("Overlay %s is not specified in cl_update_rep_name")%
|
||||||
|
repo_name)
|
||||||
|
except (DataVarsError, VariableError) as e:
|
||||||
|
if str(e):
|
||||||
|
message = ". " + str(e)
|
||||||
|
else:
|
||||||
|
message = ""
|
||||||
|
raise VariableError(_("The selected profile is not Calculate")
|
||||||
|
+ message)
|
||||||
|
else:
|
||||||
|
raise VariableError(_("Wrong Calculate profile"))
|
||||||
|
|
||||||
|
def check(self, profile):
|
||||||
|
if not profile:
|
||||||
|
raise VariableError(_("You must specify the profile"))
|
||||||
|
action = self.Get('cl_action')
|
||||||
|
if action == 'create':
|
||||||
|
url = self.Get('cl_builder_profile_url')
|
||||||
|
# внеший репозиторий профилей
|
||||||
|
if url:
|
||||||
|
path_profile, profile_fullname = \
|
||||||
|
path_profile = self.Select(
|
||||||
|
'cl_builder_profile_path',
|
||||||
|
where='cl_builder_profile_shortname',
|
||||||
|
eq=profile, limit=1)
|
||||||
|
profile_fullname = self.Select(
|
||||||
|
'cl_builder_profile_fullname',
|
||||||
|
where='cl_builder_profile_shortname',
|
||||||
|
eq=profile, limit=1)
|
||||||
|
self.check_profile(path_profile, profile_fullname)
|
||||||
|
# репозиторий в образе
|
||||||
|
else:
|
||||||
|
self.check_inner_profile(profile)
|
||||||
|
|
||||||
|
def check_inner_profile(self, profile):
|
||||||
|
"""
|
||||||
|
Проверка профиля находящегося в репозитории образа системы
|
||||||
|
"""
|
||||||
|
image = self.Get('cl_builder_source')
|
||||||
|
dv = self.Get('cl_builder_linux_datavars')
|
||||||
|
if not image or not dv:
|
||||||
|
raise VariableError(_("Failed to check profile: "
|
||||||
|
"wrong source"))
|
||||||
|
if image:
|
||||||
|
if isinstance(image, distr.ArchiveDistributive):
|
||||||
|
raise VariableError(_("Unavailable to use profile from "
|
||||||
|
"stage distributive"))
|
||||||
|
with image:
|
||||||
|
try:
|
||||||
|
distr_dn = image.getDirectory()
|
||||||
|
profile_dn = self.Select(
|
||||||
|
'cl_builder_profile_path',
|
||||||
|
where="cl_builder_profile_shortname",
|
||||||
|
eq=profile, limit=1)
|
||||||
|
profile_fullname = self.Select(
|
||||||
|
'cl_builder_profile_fullname',
|
||||||
|
where="cl_builder_profile_shortname",
|
||||||
|
eq=profile, limit=1)
|
||||||
|
if not profile_dn:
|
||||||
|
raise VariableError()
|
||||||
|
profile_dn = dv.change_root(profile_dn, distr_dn)
|
||||||
|
self.check_profile(profile_dn, profile_fullname)
|
||||||
|
except distr.DistributiveError:
|
||||||
|
raise VariableError(_("Failed to check profile: "
|
||||||
|
"failed to mount source"))
|
||||||
|
|
||||||
|
def get_by_url(self):
|
||||||
|
shortname = self.Get('cl_builder_profile_shortname')
|
||||||
|
if len(shortname) == 1:
|
||||||
|
return shortname[0]
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def get_from_image(self):
|
||||||
|
dv = self.Get('cl_builder_linux_datavars')
|
||||||
|
if dv:
|
||||||
|
try:
|
||||||
|
profile_system = dv["cl_profile_system"]
|
||||||
|
for (fullname, shortname,
|
||||||
|
_path, arch) in dv.Get('cl_profile_data'):
|
||||||
|
if _path == profile_system:
|
||||||
|
return shortname
|
||||||
|
except VariableError:
|
||||||
|
pass
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
action = self.Get('cl_action')
|
||||||
|
if action == 'create':
|
||||||
|
url = self.Get('cl_builder_profile_url')
|
||||||
|
if url:
|
||||||
|
return self.get_by_url()
|
||||||
|
else:
|
||||||
|
return self.get_from_image()
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def choice(self):
|
||||||
|
arch = self.Get('os_arch_machine_gentoo')
|
||||||
|
profiles = zip(*self.Select(['cl_builder_profile_shortname',
|
||||||
|
'cl_builder_profile_fullname'],
|
||||||
|
where='cl_builder_profile_arch', eq=arch))
|
||||||
|
if profiles:
|
||||||
|
short_name, full_name = profiles
|
||||||
|
return zip(short_name, full_name)
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
class VariableClBuilderProfileSystem(ReadonlyVariable):
|
||||||
|
def get(self):
|
||||||
|
action = self.Get('cl_action')
|
||||||
|
if action == 'create':
|
||||||
|
shortname = self.Get('cl_builder_profile_system_shortname')
|
||||||
|
profile = self.Select('cl_builder_profile_path',
|
||||||
|
where="cl_builder_profile_shortname",
|
||||||
|
eq=shortname, limit=1)
|
||||||
|
if profile:
|
||||||
|
return profile
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
class VariableClBuilderProfileName(lib_linux.VariableClProfileName):
|
||||||
|
"""
|
||||||
|
Install subname
|
||||||
|
"""
|
||||||
|
source_var = "cl_builder_profile_system"
|
||||||
|
|
||||||
|
def init(self):
|
||||||
|
self.label = _("System profile")
|
Loading…
Reference in new issue