diff --git a/pym/builder/variables/builder.py b/pym/builder/variables/builder.py index 337b5b4..2d6810e 100644 --- a/pym/builder/variables/builder.py +++ b/pym/builder/variables/builder.py @@ -123,12 +123,21 @@ class VariableClBuilderVideodrvSet(Variable): """ type = "bool" opt = ["--video", "-V"] - value = "off" + autodetect = False + default_value = "off" def init(self): self.label = _("Include proprietary video drivers") self.help = _("include proprietary video drivers") + def get(self): + if self.autodetect: + fn = self.Get('cl_builder_video_driver_path') + return "on" if path.exists(fn) else "off" + else: + return self.default_value + + class VariableClBuilderSourceFilename(Variable): """ Названия файла исходного дистрибутива diff --git a/pym/builder/variables/images.py b/pym/builder/variables/images.py index c7d3198..4755797 100644 --- a/pym/builder/variables/images.py +++ b/pym/builder/variables/images.py @@ -14,5 +14,237 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os +from os import path import sys +from calculate.lib.utils.portage import isPkgInstalled +from calculate.lib.variables.linux import LinuxDataVars +from calculate.install.distr import IsoDistributive, DistributiveError +from calculate.lib.utils.files import listDirectory +from calculate.lib.datavars import ReadonlyVariable, \ + ReadonlyTableVariable, FieldValue, VariableError, Variable +from calculate.install.variables.system import VariableOsInstallX11ServerSet +from builder import (VariableClBuilderPath, VariableClBuilderKernel, + VariableClBuilderKernelVer, VariableClBuilderInitrdInstall, + VariableClBuilderVideoDriverPath, VariableClBuilderVideodrvSet) +_ = lambda x:x + +from calculate.lib.cl_lang import setLocalTranslate + +setLocalTranslate('cl_builder3', sys.modules[__name__]) + +class VariableClBuilderIsoLabel(ReadonlyVariable): + """ + Метка в syslinux образе + """ + fullname_format = "{name} {ver}{subname} {arch} {build}" + + def get(self): + name = self.Get('os_linux_name') + subname = self.Get('os_linux_subname') + if subname: + subname = " %s" % subname + ver = self.Get('os_linux_ver') + build = self.Get('os_linux_build') + arch = self.Get('os_arch_machine') + return self.fullname_format.format( + name=name, ver=ver, subname=subname, arch=arch, build=build) + +class VariableClBuilderSplash(ReadonlyVariable): + """ + Тип splash в образе + """ + def get(self): + prefix = self.Get('cl_builder_path') + if isPkgInstalled('media-gfx/splashutils', prefix=prefix): + return "splashutils" + elif isPkgInstalled("media-gfx/plymouth-themes-calculate", + prefix=prefix): + return "plymouth" + else: + return "" + +class DataVarsBuilderImage(LinuxDataVars): + def variables(self): + l = super(DataVarsBuilderImage, self).variables() + return l + [ + VariableClBuilderPath(), + VariableClBuilderKernel(), + VariableClBuilderInitrdInstall(), + VariableClBuilderKernelVer(), + VariableOsInstallX11ServerSet(image=False, + prefix_variable="cl_builder_path"), + VariableClBuilderVideoDriverPath(), + VariableClBuilderVideodrvSet(autodetect=True), + VariableClBuilderIsoLabel(), + VariableClBuilderSplash(), + ] + + def init_variables(self): + self['cl_builder_path'] = self.systemRoot + return True + +class VariableClBuilderLiveBasePath(ReadonlyVariable): + """ + Путь, куда подключена flash + """ + value = "/run/initramfs/live" + +class VariableClBuilderImagePath(ReadonlyVariable): + """ + Путь до iso образов + """ + def get(self): + return path.join(self.Get('cl_builder_live_base_path'), "iso") + +class VariableClBuilderImageBootparam(Variable): + """ + Стандартная строка загрзки live образа + """ + + +class VariableClBuilderImageData(ReadonlyTableVariable): + """ + Информация о прочих репозиториях + """ + source = ['cl_builder_image_id', + 'cl_builder_image_label', + 'cl_builder_image_iso', + 'cl_builder_image_vmlinuz_orig', + 'cl_builder_image_vmlinuz', + 'cl_builder_image_initrd_orig', + 'cl_builder_image_initrd', + 'cl_builder_image_xorg', + 'cl_builder_image_drivers', + 'cl_builder_image_splash', + ] + + def generate_name(self, basename, namelist): + if basename not in namelist: + return basename + for n in range(1, 99): + newname = "%s-%d"%(basename,n) + if newname not in namelist: + return newname + raise VariableError(_("Failed to generate kernel name")) + + def generator(self): + isopath = self.Get('cl_builder_image_path') + n = 1 + for iso_image in [x for x in listDirectory(isopath, fullPath=True) + if x.endswith('.iso')]: + try: + with IsoDistributive(iso_image) as image: + dn = image.getDirectory() + dv = DataVarsBuilderImage(dn) + + kernel = dv['cl_builder_kernel'] + kernel_copy = "vmlinuz-%d" % n + initrd = dv['cl_builder_initrd_install'] + initrd_copy = "initrd-%d" % n + + yield ["cl-%d"%n, + dv['cl_builder_iso_label'], + iso_image, + kernel, kernel_copy, + initrd, initrd_copy, + dv['os_install_x11_server_set'], + dv['cl_builder_videodrv_set'], + dv['cl_builder_splash'], + ] + n += 1 + except DistributiveError: + pass + + def get(self, hr=False): + return list(self.generator()) + + +class VariableClBuilderImageId(FieldValue, ReadonlyVariable): + """ + Идентификаторы образов + """ + type = "list" + source_variable = "cl_builder_image_data" + column = 0 + + +class VariableClBuilderImageLabel(FieldValue, ReadonlyVariable): + """ + Идентификаторы образов + """ + type = "list" + source_variable = "cl_builder_image_data" + column = 1 + + +class VariableClBuilderImageIso(FieldValue, ReadonlyVariable): + """ + Пути до iso образов + """ + type = "list" + source_variable = "cl_builder_image_data" + column = 2 + + +class VariableClBuilderImageVmlinuzOrig(FieldValue, ReadonlyVariable): + """ + Пути до vmlinuz + """ + type = "list" + source_variable = "cl_builder_image_data" + column = 3 + + +class VariableClBuilderImageVmlinuz(FieldValue, ReadonlyVariable): + """ + Пути до vmlinuz + """ + type = "list" + source_variable = "cl_builder_image_data" + column = 4 + + +class VariableClBuilderImageInitrdOrig(FieldValue, ReadonlyVariable): + """ + Пути до initrd + """ + type = "list-bool" + source_variable = "cl_builder_image_data" + column = 5 + + +class VariableClBuilderImageInitrd(FieldValue, ReadonlyVariable): + """ + Пути до initrd + """ + type = "list-bool" + source_variable = "cl_builder_image_data" + column = 6 + + +class VariableClBuilderImageXorg(FieldValue, ReadonlyVariable): + """ + Содержит ли образ xorg-server + """ + type = "list-bool" + source_variable = "cl_builder_image_data" + column = 7 + + +class VariableClBuilderImageDrivers(FieldValue, ReadonlyVariable): + """ + Содержит ли образ проприетарные видеодраверы + """ + type = "list" + source_variable = "cl_builder_image_data" + column = 8 + +class VariableClBuilderImageSplash(FieldValue, ReadonlyVariable): + """ + Какой сплэш содержит образ + """ + type = "list" + source_variable = "cl_builder_image_data" + column = 9 diff --git a/pym/builder/variables/linux.py b/pym/builder/variables/linux.py index 5a179ae..792d3c4 100644 --- a/pym/builder/variables/linux.py +++ b/pym/builder/variables/linux.py @@ -245,6 +245,7 @@ class VariableOsBuilderLinuxSystem(BuilderLinux): variable = "os_linux_system" + class VariableOsBuilderLinuxFullname(ReadonlyVariable): """ Полное название системы