From 986de7437c400dd11083d1ddb4618350e5f67d2b Mon Sep 17 00:00:00 2001 From: Mike Khiretskiy Date: Wed, 23 Sep 2015 17:08:35 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BD=D0=B5=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7?= =?UTF-8?q?=D1=83=D0=B5=D1=82=D1=81=D1=8F=20=D0=BB=D0=B8=20=D0=BE=D0=B1?= =?UTF-8?q?=D1=80=D0=B0=D0=B7,=20=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B?= =?UTF-8?q?=D0=B9=20=D0=B4=D0=BE=D0=BB=D0=B6=D0=B5=D0=BD=20=D0=B1=D1=8B?= =?UTF-8?q?=D1=82=D1=8C=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B7=D0=B0=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D0=B0=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pym/builder/variables/builder.py | 93 ++++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 17 deletions(-) diff --git a/pym/builder/variables/builder.py b/pym/builder/variables/builder.py index 7d7c3b1..31d97bf 100644 --- a/pym/builder/variables/builder.py +++ b/pym/builder/variables/builder.py @@ -37,19 +37,23 @@ from calculate.lib.datavars import Variable, VariableError, ReadonlyVariable, \ TableVariable from functools import wraps -_ = lambda x:x +_ = lambda x: x from calculate.lib.cl_lang import setLocalTranslate -setLocalTranslate('cl_builder3',sys.modules[__name__]) + +setLocalTranslate('cl_builder3', sys.modules[__name__]) + def debug(func): @wraps(func) def _wrapped_func(*args, **kw): ret = func(*args, **kw) - print "MYDEBUG",ret + print "MYDEBUG", ret return ret + return _wrapped_func + def is_action(*available_action, **action_kwargs): def decorator(func): @wraps(func) @@ -58,13 +62,17 @@ def is_action(*available_action, **action_kwargs): return func(self, *args, **kw) else: return action_kwargs.get('default_value', '') + return _wrapped_func + return decorator + def as_list(func): @wraps(func) def _wrapped_func(self, *args, **kw): return list(func(self, *args, **kw)) + return _wrapped_func @@ -109,16 +117,19 @@ class BaseBuildId(Variable): self.label = _("Build ID") self.help = _("build ID") + class VariableClBuilderVideoDriverPath(Variable): """ Имя файла, содержащего данные об установки драйверов во время загрузки """ + def get(self): builder_path = self.Get('cl_builder_path') return path.join( builder_path, 'var/cache/calculate/video_drivers') + class VariableClBuilderVideodrvSet(Variable): """ Нужно ли скачивать пакеты в дистрибутив для установки проприетарных @@ -177,7 +188,7 @@ class VariableClBuilderSourceFilename(Variable): if subname: subname = " %s" % subname if ver: - ver = " %s"%ver + ver = " %s" % ver arch = self.Get('os_builder_arch_machine') build = self.Get('os_builder_linux_build') @@ -213,12 +224,14 @@ class VariableClBuilderSource(ReadonlyVariable): return filename.getType() return filename + class VariableClBuilderPreparePath(Variable): """ Путь по умолчанию для собираемой системы """ value = "/var/calculate/builder" + class VariableClBuilderDiskDev(Variable): """ Диск или директория, куда будет развёрнут образ @@ -235,8 +248,8 @@ class VariableClBuilderDiskDev(Variable): def get_builder_image_dn(self): if self.Get('os_root_type') != "livecd": default_path = self.Get('cl_builder_prepare_path') - for i in range(1,9999): - dn = "image%d"%i + for i in range(1, 9999): + dn = "image%d" % i full_dn = path.join(default_path, dn) if not path.exists(full_dn) or not isMount(full_dn): return full_dn @@ -307,6 +320,7 @@ class VariableClBuilderDiskSize(DiskFreeHelper): """ """ + def init(self): self.label = _("Free disk space") @@ -322,10 +336,12 @@ class VariableClBuilderDiskSize(DiskFreeHelper): return str(self.get_free_for(device)) return "0" + class VariableClBuilderPrepareFreeSize(DiskFreeHelper): """ Свободное место используемое для подготовки образа """ + def init(self): self.label = _("Free disk space for ISO building") @@ -334,10 +350,12 @@ class VariableClBuilderPrepareFreeSize(DiskFreeHelper): dn = self.Get('cl_builder_iso_base_path') return str(self.get_free_for(dn)) + class VariableClBuilderImageFreeSize(DiskFreeHelper): """ Свободное место на диске, где создается iso образ """ + def init(self): self.label = _("Free disk space for ISO image") @@ -376,7 +394,7 @@ class VariableClBuilderLayeredSet(Variable): def check_on(self): if not self.check_kernel_option(): raise VariableError( - _("You need kernel with %s for use layers")%self.kernel_opt) + _("You need kernel with %s for use layers") % self.kernel_opt) if self.Get('cl_builder_disk_dev').startswith('/dev'): raise VariableError( _("Layers are used for building in a directory only")) @@ -394,6 +412,7 @@ class VariableClBuilderPath(ReadonlyVariable): """ Путь, где будет собираться дистрбутив """ + def get(self): image = self.Get('cl_builder_target') if image: @@ -461,6 +480,7 @@ class VariableClBuilderClearSet(Variable): self.label = _("Clear after unmount") self.help = _("clear data after unmount") + class VariableClBuilderClearPkgSet(Variable): """ Удалять бинарные пакеты при отключении сборки @@ -526,7 +546,7 @@ class VariableClBuilderNewId(BaseBuildId): if value and not re.match("^[A-Za-z][A-Za-z0-9/:_+-]+$", value): raise VariableError(_("Wrong symbols in the build ID")) if value in self.Get('cl_builder_storage'): - raise VariableError(_("Build %s already exists")%value) + raise VariableError(_("Build %s already exists") % value) class VariableClBuilderPreparedId(BaseBuildId): @@ -543,7 +563,7 @@ class VariableClBuilderPreparedId(BaseBuildId): for x in bs: build = bs.get_build(x) if (build and (action == Actions.Break or - build.status == Build.Status.Worked)): + build.status == Build.Status.Worked)): yield x def get(self): @@ -570,7 +590,7 @@ class VariableClBuilderPreparedId(BaseBuildId): if not l: raise VariableError(_("Build %s is not found") % value) if (self.Get('cl_builder_build').status == Build.Status.Broken and - self.Get('cl_action') != Actions.Break): + self.Get('cl_action') != Actions.Break): raise VariableError( _("Build %s is broken, try to restore build") % value) @@ -613,20 +633,24 @@ class VariableClBuilderBrokenId(BaseBuildId): if not l: raise VariableError(_("Build %s is not found") % value) + class VariableClBuilderIdPath(ReadonlyVariable): """ Преобразование сборки id в имя походящее для путей """ + def get(self): build_id = self.Get('cl_builder_id') if build_id: return re.sub("[/:]", "_", self.Get('cl_builder_id')) return "" + class VariableClBuilderId(ReadonlyVariable): """ Общий id сборки """ + def get(self): action = self.Get('cl_action') if action in Actions.NewAssemble: @@ -642,6 +666,7 @@ class VariableOsBuilderMakeopts(Variable): """ Параметры MAKEOPTS """ + def get(self): return self.Get('install.os_install_makeopts') @@ -666,10 +691,12 @@ class VariableClBuilderParentPath(ReadonlyVariable): """ Путь в ".." до родительской системы """ + def get(self): builder_path = self.Get('cl_builder_path') - return ("../"*len(filter(None, - builder_path.split('/'))))[:-1] + return ("../" * len(filter(None, + builder_path.split('/'))))[:-1] + class VariableClBuilderStageSet(ReadonlyVariable): """ @@ -682,10 +709,12 @@ class VariableClBuilderStageSet(ReadonlyVariable): if self.Get('os_builder_linux_shortname') == "Gentoo" else "off") + class VariableClBuilderPkgdir(Variable): """ Путь собираемых бинарных архивов """ + def fallback(self): return path.join(self.Get('cl_builder_base_path'), self.Get('cl_builder_id_path')) @@ -700,6 +729,7 @@ class VariableClBuilderPkgdir(Variable): else: return "" + class VariableClBuilderAction(ReadonlyVariable): """ Дополнительное действие по созданию образа: iso, squash. @@ -724,6 +754,11 @@ class VariableClBuilderImageFilename(Variable): def check(self, value): if not value: raise VariableError(_("You must specify image filename")) + for line in process("/bin/losetup", "-j", value): + lodev, op, line = line.partition(":") + if lodev: + raise VariableError( + _("Image %s is already used") % value) def _isoname(self, dn, rewrite=False): shortname = self.Get('os_builder_linux_shortname').lower() @@ -769,6 +804,7 @@ class VariableClBuilderIsoPath(ReadonlyVariable): """ Путь, где будут подготавливаться данные, которые будут запакованы в iso """ + def get(self): base_dn = self.Get('cl_builder_iso_base_path') build_id = self.Get('cl_builder_id') @@ -790,6 +826,7 @@ class VariableClBuilderSquashPath(ReadonlyVariable): """ Путь от iso до содержимого squash """ + @is_action(Actions.Image) def get(self): return path.relpath(self.Get('cl_builder_path'), @@ -800,6 +837,7 @@ class VariableClBuilderImage(ReadonlyVariable): """ Создаваемый образ """ + @is_action(Actions.Image) def get(self): image_name = self.Get('cl_builder_image_filename') @@ -830,6 +868,7 @@ class VariableClBuilderCdname(ReadonlyVariable): """ Type of iso (CD/DVD) """ + @is_action(Actions.Image) def get(self): squashfile = pathJoin(self.Get('cl_builder_iso_path'), @@ -857,6 +896,7 @@ class VariableClBuilderIsoLabel(Variable): """ LABEL для iso """ + @is_action(Actions.Image) def get(self): return "%s-%s" % (self.Get('os_builder_linux_shortname').upper(), @@ -886,6 +926,7 @@ class VariableClBuilderKernelCmd(ReadonlyVariable): """ value = "" + class KernelInfo(ReadonlyVariable): def get_current_kernel_src(self, prefix): src_path = "usr/src" @@ -895,10 +936,12 @@ class KernelInfo(ReadonlyVariable): raise ValueError("Failed to determine current kernel version") return path.join(src_path, os.readlink(symlink_kernel)) + class VariableClBuilderKernelConfig(KernelInfo): """ Конфиг ядра """ + def get(self): prefix = self.Get('cl_builder_path') if prefix: @@ -907,10 +950,12 @@ class VariableClBuilderKernelConfig(KernelInfo): return KernelConfig(path.join(prefix, config_path)) return "" + class VariableClBuilderKernelVer(KernelInfo): """ Текущая версия ядра """ + def init(self): self.label = _("Kernel version") @@ -918,7 +963,7 @@ class VariableClBuilderKernelVer(KernelInfo): prefix = self.Get('cl_builder_path') if prefix: current_src = self.get_current_kernel_src(prefix) - src = path.join(prefix,current_src) + src = path.join(prefix, current_src) return self.get_src_kernel_version(src) def get_config_version(self, configfile): @@ -1111,6 +1156,7 @@ class VariableClBuilderBranchName(Variable): return [branch for x in dv.Get('cl_update_rep_name')] return [] + class VariableClBuilderCompress(Variable): """ Тип сжатия образа squash @@ -1141,7 +1187,7 @@ class VariableClBuilderCompress(Variable): else: yield compress - weight = {'xz':2, 'gzip':1} + weight = {'xz': 2, 'gzip': 1} return list(sorted(generator(), key=lambda x: (-weight.get(x, 0), x))) @@ -1152,6 +1198,7 @@ class VariableClBuilderCompress(Variable): return values[0] return "" + class VariableClBuilderIsohybridSet(Variable): """ Преобразовать полученный iso образ в гибридный @@ -1164,6 +1211,7 @@ class VariableClBuilderIsohybridSet(Variable): self.help = _("create the ISO image with isohybrid") self.label = _("ISO hybrid feature") + class VariableClBuilderKeepTreeSet(Variable): """ Не удалять ебилды из портежей о оверлеев @@ -1176,6 +1224,7 @@ class VariableClBuilderKeepTreeSet(Variable): self.help = _("keep portage tree in image") self.label = _("Keep portage tree") + class VariableClBuilderSquashExclude(ReadonlyVariable): """ Список файлов, которые не будут запакованы в livecd.squashfs @@ -1206,6 +1255,7 @@ class VariableClBuilderSquashExclude(ReadonlyVariable): return list(generator()) return [] + class VariableClBuilderPrelinkSet(Variable): """ Выполнять ли prelink @@ -1220,6 +1270,7 @@ class VariableClBuilderPrelinkSet(Variable): def get(self): return "on" if self.GetBool('cl_builder_binary_set') else "off" + class VariableClBuilderRebuildChangedSet(Variable): """ Выполнять ли prelink @@ -1232,6 +1283,7 @@ class VariableClBuilderRebuildChangedSet(Variable): self.help = _("rebuild changed packages") self.label = _("Rebuild changed packages") + class VariableClBuilderRescratchSet(ReadonlyVariable): """ Сборка iso образа на самой флешке @@ -1247,6 +1299,7 @@ class VariableClBuilderRescratchSet(ReadonlyVariable): return "on" return "off" + class VariableClBuilderFlashRepository(ReadonlyVariable): """ Хранилище по умолчанию для iso образов на flash @@ -1256,6 +1309,7 @@ class VariableClBuilderFlashRepository(ReadonlyVariable): def get(self): return path.join(self.Get('cl_builder_flash_path'), "iso") + class VariableClBuilderFlashDevPath(Variable): """ Путь до устройства flash @@ -1287,14 +1341,14 @@ class VariableClBuilderFlashDevPath(Variable): else: choices = [] return choices + \ - [(x,x) for x in self.select('install.os_disk_dev', - install_os_disk_format="vfat")] + [(x, x) for x in self.select('install.os_disk_dev', + install_os_disk_format="vfat")] def check(self, value): if not value: raise VariableError(_("Please specify Flash drive")) if not path.exists(value): - raise VariableError(_("Flash drive %s not found")%value) + raise VariableError(_("Flash drive %s not found") % value) try: image = IsoDistributive(value) image.getIsoContentDirectory() @@ -1302,6 +1356,7 @@ class VariableClBuilderFlashDevPath(Variable): except DistributiveError as e: raise VariableError(str(e).strip()) + class VariableClBuilderFlashDev(ReadonlyVariable): """ Устройство flash @@ -1317,10 +1372,12 @@ class VariableClBuilderFlashDev(ReadonlyVariable): return "" return "" + class VariableClBuilderFlashPath(ReadonlyVariable): """ Путь, куда подключена flash (загрузка либо с флешки, либо с iso) """ + def get(self): try: iso = self.Get('cl_builder_flash_dev') @@ -1330,10 +1387,12 @@ class VariableClBuilderFlashPath(ReadonlyVariable): return "" return "" + class VariableClBuilderFlashUuid(ReadonlyVariable): """ UUID flash, используется для перестроения меню """ + def get(self): flash_path = self.Get('cl_builder_flash_path') dev = isMount(flash_path)