From 1857bddc10082a562c12398a5ba176b9bd76494f Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Wed, 4 Apr 2012 12:33:56 +0400 Subject: [PATCH] Add autopartition variables. --- install/cl_install.py | 2 + install/cl_wsdl_install.py | 32 +++- install/variables/X11.py | 24 ++- install/variables/autopartition.py | 262 +++++++++++++++++++++++++++-- install/variables/disk.py | 229 ++++++++++++++++++------- install/variables/distr.py | 29 ++-- install/variables/kernel.py | 8 +- install/variables/locale.py | 51 +++++- install/variables/net.py | 78 ++++++--- install/variables/system.py | 26 ++- 10 files changed, 602 insertions(+), 139 deletions(-) diff --git a/install/cl_install.py b/install/cl_install.py index c220749..ff1f321 100644 --- a/install/cl_install.py +++ b/install/cl_install.py @@ -822,6 +822,8 @@ class Install(color_print, SignalInterrupt): sourceDistr = None try: self.clVars.printVars() + if self.Get('cl_autopartition_scheme'): + raise InstallError(_('Autopartitioning is not supported')) targetDistr = self.clVars.Get('cl_target') sourceDistr = self.clVars.Get('cl_image') # cmd options diff --git a/install/cl_wsdl_install.py b/install/cl_wsdl_install.py index c020819..46a5ed5 100644 --- a/install/cl_wsdl_install.py +++ b/install/cl_wsdl_install.py @@ -68,6 +68,12 @@ class InstallInfo(ClassSerializer): os_install_fb_resolution = String os_install_clock_timezone = String os_install_kernel_scheduler = String + + cl_autopartition_device = String + cl_autopartition_scheme = String + cl_autopartition_table = String + cl_autopartition_root_size = String + #default = Array(String) CheckOnly = Boolean @@ -88,10 +94,10 @@ def catchExcept(): group = GroupField(name=_("Error"),last=True) group.fields = [] group.fields.append(Field( - name = "error_label", + name = "error", label = str(e), default = 'color:red;', - element = "label")) + element = "error")) view.groups.append(group) print "!!!!EXCEPTION!!!!" for i in apply(traceback.format_exception, sys.exc_info()): @@ -102,15 +108,20 @@ def catchExcept(): class Wsdl: def check_params (self, dv, info,allvars=False,ordered=None): errors = [] - keys = filter(lambda x:x.lower() == x, - info._type_info.keys()) + keys = sorted(filter(lambda x:x.lower() == x, + info._type_info.keys())) if ordered: keys = ordered + filter(lambda x:not x in ordered, keys) + print "333333333333333:",info.cl_autopartition_scheme + print "222222222222222:",info.cl_autopartition_device for var in keys: + # get value of variable from info val = info.__getattribute__(var) + # check value if value send of check allvariables if val != None or allvars: try: + # if value not send, then get from datavars if val == None: val = dv.Get(var) else: @@ -144,7 +155,10 @@ class Wsdl: dv.flIniFile() initfunc(dv) errors = self.check_params(dv, info, - ordered=['cl_image_linux_shortname', + ordered=['cl_autopartition_scheme', + 'cl_autopartition_device', + 'cl_autopartition_root_size', + 'cl_image_linux_shortname', 'cl_image_arch_machine', 'cl_image_linux_ver', 'cl_image_linux_build'], @@ -181,6 +195,7 @@ class Wsdl: @rpc(Integer, Integer, Boolean,_returns = ViewInfo) @catchExcept() def install_view (self, sid, step,expert): + curThread = threading.currentThread() dv = self.get_cache(sid,"install","vars") if not dv: reload(cl_install) @@ -194,6 +209,11 @@ class Wsdl: ('cl_image_linux_shortname','cl_image_arch_machine', 'cl_image_linux_ver','cl_image_linux_build'), _("Next")), \ + (_("Autopartition"), \ + ('cl_autopartition_device', + 'cl_autopartition_scheme'), + ('cl_autopartition_table','cl_autopartition_root_size'), + _("Next")), \ (_("Partitioning"), \ ('os_location_data','os_install_scratch','cl_uuid_set'), ('os_install_root_type','os_install_mbr', @@ -212,7 +232,7 @@ class Wsdl: (_("Video"), \ ('os_install_x11_video_drv', 'os_install_x11_composite', 'os_install_x11_resolution', 'os_install_fb_resolution'),(), \ - _("Done")), + _("Install")), ],step,expert) self.set_cache(sid, 'install', "vars",dv,smart=False) return view diff --git a/install/variables/X11.py b/install/variables/X11.py index e53cde4..b16ef2c 100644 --- a/install/variables/X11.py +++ b/install/variables/X11.py @@ -78,8 +78,10 @@ class VariableOsInstallX11Resolution(ResolutionVariable): type = 'choiceedit' opt = ['-X'] metavalue = "x" - help = _("set Xorg resolution") - label = _("Screen resolution") + + def init(self): + self.help = _("set Xorg resolution") + self.label = _("Screen resolution") def get(self): # get resolution from xorg.log @@ -96,8 +98,10 @@ class VariableOsInstallX11VideoDrv(VideoVariable): type = 'choice' opt = ['--video'] metavalue = "VIDEODRV" - help = _("set the video driver") - label = _("{0} video driver").format("Xorg") + + def init(self): + self.help = _("set the video driver") + self.label = _("{0} video driver").format("Xorg") def choice(self): """Get available (already installed or installable drivers""" @@ -145,8 +149,10 @@ class VariableOsInstallX11Composite(VideoVariable): """ type = 'bool' opt = ['--composite'] - help = _("set composite") - label = _("Composite") + + def init(self): + self.help = _("set composite") + self.label = _("Composite") def get(self): """On/off composite""" @@ -178,10 +184,12 @@ class VariableOsInstallFbResolution(ResolutionVariable): type = 'choiceedit' opt = ['--fb'] metavalue = "x" - help = _("set framebuffer resolution") - label = _("Framebuffer resolution") xorg_need = False + def init(self): + self.help = _("set framebuffer resolution") + self.label = _("Framebuffer resolution") + def get(self): """Get current framebuffer resolution""" resolution = "" diff --git a/install/variables/autopartition.py b/install/variables/autopartition.py index 6b7c20a..ab5f5f4 100644 --- a/install/variables/autopartition.py +++ b/install/variables/autopartition.py @@ -21,7 +21,8 @@ from os import path from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable from calculate.lib.utils.device import (getUdevDeviceInfo,getDeviceType, getPartitionType,getPartitionDevice,getRaidPartitions, - getLvmPartitions,getPartitionSize,getUUIDDict) + getLvmPartitions,getPartitionSize,getUUIDDict, + humanreadableSize) from calculate.lib.utils.files import (listDirectory,pathJoin,readFile,FStab, readLinesFile) from calculate.install.cl_distr import PartitionDistributive @@ -42,15 +43,7 @@ class AutoPartition: "{rootsize}:/;{rootsize}:;{allsize}:/var/calculate;" "/var/calculate:/home", _("Manual partition"):""} - device = None - scheme = None - args = {'memory':0, - 'rootsize':10, - 'allsize':0} - def initArgs(self): - self.args['memory'] = self.Get('hr_memory_size') - self.args['rootsize'] = self.Get('cl_autopartition_root_size') class VariableHrMemorySize(ReadonlyVariable): """ @@ -76,13 +69,19 @@ class VariableClAutopartitionDevice(Variable): """ type = "choice" value = "" - label = _("Install device") opt = ["-D"] metavalue = "DEVICE" - help = _("set autopartition device") + + def init(self): + self.help = _("set autopartition device") + self.label = _("Install device") def choice(self): - return self.Get('os_device_dev') + return [""]+self.Get('os_device_dev') + + def check(self,value): + if self.Get('cl_autopartition_scheme') and not value: + raise VariableError(_("For autopartition need select install device")) class VariableClAutopartitionScheme(Variable,AutoPartition): """ @@ -91,10 +90,12 @@ class VariableClAutopartitionScheme(Variable,AutoPartition): type = "choice" value = "" element = "radio" - lable = _("Install scheme") opt = ["--autopart"] metavalue = "AUTOPARTMODE" - help = _("autopartition scheme") + + def init(self): + self.help = _("autopartition scheme") + self.label = _("Install scheme") def choice(self): return map(lambda x:(x[1],x[0]), @@ -105,6 +106,12 @@ class VariableClAutopartitionRootSize(Variable): Root partition size for autopartition """ type = "int" + opt = ["--root-size"] + metavalue = "SIZE" + + def init(self): + self.label = _("Root partition size") + self.help = _("set root partition size for autopartition") def get(self): if self.Get('os_install_linux_system') == 'server': @@ -112,11 +119,238 @@ class VariableClAutopartitionRootSize(Variable): else: return str(1024*10) + def check(self,value): + if self.Get('cl_autopartition_device') and \ + self.Get('cl_autopartition_scheme') and \ + self.Get('cl_autopartition_free_size') <= 0: + raise VariableError(_("Selected size is too large")) + class VariableClAutopartitionTable(Variable): """ Partition table for autopartition """ + type = "choice" value = "dos" + opt = ["--partition-table"] + metavalue = "TABLE" + + def init(self): + self.label = _("Partition table") + self.help = _("set partition table for autopartition") def choice(self): return ["dos","gpt"] + +class VariableClAutopartitionDiskData(ReadonlyVariable): + """ + New partition data for autopart device + """ + type = "table" + source = ['cl_autopartition_disk_dev', + 'cl_autopartition_disk_mount', + 'cl_autopartition_disk_format', + 'cl_autopartition_disk_size', + 'cl_autopartition_disk_part'] + +class VariableClAutopartitionDiskDev(ReadonlyVariable): + """ + Autopartition virtual disk on device + """ + type = "list" + + def generateDisks(self,dos,device,scheme,number=0): + """ + Generate disks for automount scheme + """ + number = 1 + for line in scheme.split(';'): + if dos and number == 4: + number += 1 + sizeOrBind, mp = line.split(':') + if not sizeOrBind.startswith('/'): + yield "%s%d"%(device,number) + number += 1 + + def get(self): + scheme = self.Get('cl_autopartition_scheme') + device = self.Get('cl_autopartition_device') + if scheme and device: + res = list(self.generateDisks( + self.Get('cl_autopartition_table')=='dos', + device,scheme)) + return res + return [] + +class VariableClAutopartitionDiskMount(ReadonlyVariable): + """ + Autopartition mount points + """ + type = "list" + + def generateMounts(self,scheme): + """ + Generate mount points for automount scheme + """ + for line in scheme.split(';'): + if not line.startswith('/'): + source, mp = line.split(':') + yield mp + + def get(self): + scheme = self.Get('cl_autopartition_scheme') + device = self.Get('cl_autopartition_device') + if scheme and device: + return list(self.generateMounts(scheme)) + return [] + +class VariableClAutopartitionDiskFormat(ReadonlyVariable): + """ + Autopartition disk file system + """ + type = "list" + + def generateFormat(self,scheme): + """ + Generate filesystems for automount scheme + """ + for line in scheme.split(';'): + source,mp = line.split(':') + if not source.startswith('/'): + if mp == "swap": yield "swap" + else: yield FileSystemManager.defaultFS['hdd'] + + def get(self): + scheme = self.Get('cl_autopartition_scheme') + device = self.Get('cl_autopartition_device') + if scheme and device: + return list(self.generateFormat(scheme)) + return [] + +class VariableClAutopartitionDiskPart(ReadonlyVariable): + """ + Autopartition partition type (primary,extended,logical,gpt) + """ + type = "list" + + def generatePart(self,scheme,dos): + """ + Generate part type for automount scheme + """ + number = 1 + for line in scheme.split(';'): + sizeOrBind, mp = line.split(':') + if not sizeOrBind.startswith('/'): + if dos: + if number < 4: yield "primary" + else: yield "logical" + number += 1 + else: + yield "gpt" + + def get(self): + scheme = self.Get('cl_autopartition_scheme') + table = self.Get('cl_autopartition_table') + if scheme: + return list(self.generatePart(scheme, + self.Get('cl_autopartition_table')=='dos')) + return [] + +class VariableClAutopartitionDiskType(ReadonlyVariable): + """ + Autopartition partition scheme (simple - disk-partition) + """ + type = "list" + + def get(self): + return map(lambda x:"disk-partition", + self.Get('cl_autopartition_disk_dev')) + +class VariableClAutopartitionDiskSize(ReadonlyVariable): + """ + Autopartition disk size + """ + type = "list" + + def generateSize(self,scheme,memory,rootsize): + args = {'memory':memory, + 'rootsize': rootsize, + 'allsize':"allfree" + } + for line in scheme.split(';'): + size,mp = line.split(':') + if not size.startswith('/'): + yield size.format(**args) + + def get(self): + scheme = self.Get('cl_autopartition_scheme') + device = self.Get('cl_autopartition_device') + if scheme and device: + return list(self.generateSize(scheme,self.Get('hr_memory_size'), + str(int(self.Get('cl_autopartition_root_size')) + *1024*1024))) + return [] + + def humanReadable(self): + allSize = self.Get('cl_autopartition_free_size') + return map(humanreadableSize, + map(lambda x:allSize if x == "allfree" else x, + self.Get())) + +class VariableClAutopartitionFreeSize(ReadonlyVariable): + """ + Freesize of device with current root_size and memory + """ + type = "int" + + def get(self): + device = self.Get('cl_autopartition_device') + if not device: + return 0 + sizeDevice = self.Select('os_device_size', + where='os_device_dev', + eq=device,limit=1) + sizes = self.Get('cl_autopartition_disk_size') + return reduce(lambda x,y: x - int(y) if y.isdigit() else x, + sizes,int(sizeDevice)) + +class VariableClAutopartitionBindData(ReadonlyVariable): + """ + Autopartition bind data + """ + type = "table" + source = ['cl_autopartition_bind_path', + 'cl_autopartition_bind_mountpoint'] + +class VariableClAutopartitionBindPath(ReadonlyVariable): + """ + Autopartition bind points + """ + type = "list" + + def generatePath(self,scheme): + for line in scheme.split(';'): + source,mp = line.split(':') + if source.startswith('/'): + yield source + + def get(self): + scheme = self.Get('cl_autopartition_scheme') + device = self.Get('cl_autopartition_device') + return list(self.generatePath(scheme)) + +class VariableClAutopartitionBindMountpoint(ReadonlyVariable): + """ + Autopartition bind points + """ + type = "list" + + def generateMountPoint(self,scheme): + for line in scheme.split(';'): + source,mp = line.split(':') + if source.startswith('/'): + yield mp + + def get(self): + scheme = self.Get('cl_autopartition_scheme') + device = self.Get('cl_autopartition_device') + return list(self.generateMountPoint(scheme)) diff --git a/install/variables/disk.py b/install/variables/disk.py index 70de301..a4d3796 100644 --- a/install/variables/disk.py +++ b/install/variables/disk.py @@ -155,11 +155,18 @@ class VariableOsDeviceTable(ReadonlyVariable): def get(self): """Get device partition table""" + autopartition = self.Get('cl_autopartition_scheme') + autoDevice = self.Get('cl_autopartition_device') def getTable(device): prop = getUdevDeviceInfo(name=device) return prop.get('ID_PART_TABLE_TYPE', self.getTableByChild(device)) - return map(getTable, + def getByAutopartition(device): + if autopartition and autoDevice == device: + return self.Get('cl_autopartition_table') + else: + return getTable(device) + return map(getByAutopartition, self.Get('os_device_dev')) class VariableOsDeviceName(ReadonlyVariable): @@ -481,29 +488,48 @@ class VariableOsBindMountpoint(ReadonlyVariable): ###################################################################### # Userselect partion parameters ###################################################################### -class VariableOsLocationData(Variable): +class LocationVariable: + """ + Location variable + """ + + def uncompatible(self): + """ + Network setting up unavailable for flash installation + """ + if self.Get('cl_autopartition_scheme'): + return \ + _("Location not available with autopartitioning") + return "" + +class VariableOsLocationData(LocationVariable,Variable): """ Select installation disk variable """ type = "table" opt = ["--disk","-d"] metavalue = 'DISKS' - help = _("DISK for installation, will be mounted to DIR. " - "DIR set to 'none' will cancel the mount point " - "transfer. For creating bind mount point you have " - "to specify the source directory as DISK") - label = _("Locations") source = ["os_location_source", "os_location_dest", "os_location_format", - "os_location_perform_format"] + "os_location_perform_format", + "os_location_size"] + + def init(self): + self.help = _("DISK for installation, will be mounted to DIR. " + "DIR set to 'none' will cancel the mount point " + "transfer. For creating bind mount point you have " + "to specify the source directory as DISK") + self.label = _("Locations") -class VariableOsLocationSource(Variable): +class VariableOsLocationSource(LocationVariable,Variable): """ Source disk or directory """ type = "choiceedit-list" - label = _("Disk or directory") + + def init(self): + self.label = _("Disk or directory") def availDevs(self): """ @@ -520,10 +546,39 @@ class VariableOsLocationSource(Variable): return self.Get('os_disk_dev')+self.Get('os_bind_path') def get(self): - return self.availDevs() + print "LocationSource" + if self.Get('cl_autopartition_scheme'): + print "Scheme" + print self.Get('cl_autopartition_disk_dev') + \ + self.Get('cl_autopartition_bind_path') + return self.Get('cl_autopartition_disk_dev') + \ + self.Get('cl_autopartition_bind_path') + else: + print "Avail" + return self.availDevs() def choice(self): - return self.availDevs() + [""] + return self.fixOsDiskDev(self.availDevs()) + [""] + + def fixOsDiskDev(self,sourcelist=None): + """ + Fix os_disk_dev by autopartitions + """ + if not sourcelist: + sourcelist = self.Get('os_disk_dev') + scheme = self.Get('cl_autopartition_scheme') + if scheme: + excludeDisks = self.Select('os_disk_dev', + where='os_disk_parent', + eq=self.Get('cl_autopartition_device')) + appendDisks = self.Get('cl_autopartition_disk_dev')+ \ + self.Get('cl_autopartition_bind_path') + else: + excludeDisks = [] + appendDisks = [] + return list((set(sourcelist) + -set(excludeDisks)) + |set(appendDisks)) def check(self,value): """Check set location source""" @@ -537,7 +592,7 @@ class VariableOsLocationSource(Variable): ########################### disks = filter(lambda x:x.startswith('/dev/'),value) wrongDevices = list(set(disks) - \ - set(self.Get('os_disk_dev'))) + set(self.fixOsDiskDev())) if wrongDevices: raise VariableError(_("Incorrect device '%s'")%wrongDevices[0]) wrongSource = filter(lambda x:x and not x.startswith('/'),value) @@ -552,33 +607,39 @@ class VariableOsLocationSource(Variable): if dupDevices: raise VariableError(_("Device '%s' is used twice")%dupDevices[0]) -class VariableOsLocationDest(Variable): +class VariableOsLocationDest(LocationVariable,Variable): """ Desination directory of install disk data """ type = "choiceedit-list" - label = _("Mount point") + + def init(self): + self.label = _("Mount point") def get(self): - source = self.Get('os_location_source') - installFrom = self.Get('os_install_dev_from') - singleDevice = self.Get('os_install_disk_single') - def installMountPoint(info): - dev,mount = info - if self.Get('cl_action') == 'system': - if self.Get('cl_install_type') == 'flash': - if dev == singleDevice: return "/" - else: return "" - else: - if dev == installFrom: return "/" - elif mount == "/": return "" - return mount - return map(installMountPoint, - filter(lambda x:x[0] in source, - zip(self.Get('os_disk_dev'), - self.Get('os_disk_mount'))+\ - zip(self.Get('os_bind_path'), - self.Get('os_bind_mountpoint')))) + if self.Get('cl_autopartition_scheme'): + return self.Get('cl_autopartition_disk_mount') + \ + self.Get('cl_autopartition_bind_mountpoint') + else: + source = self.Get('os_location_source') + installFrom = self.Get('os_install_dev_from') + singleDevice = self.Get('os_install_disk_single') + def installMountPoint(info): + dev,mount = info + if self.Get('cl_action') == 'system': + if self.Get('cl_install_type') == 'flash': + if dev == singleDevice: return "/" + else: return "" + else: + if dev == installFrom: return "/" + elif mount == "/": return "" + return mount + return map(installMountPoint, + filter(lambda x:x[0] in source, + zip(self.Get('os_disk_dev'), + self.Get('os_disk_mount'))+\ + zip(self.Get('os_bind_path'), + self.Get('os_bind_mountpoint')))) def set(self,value): """Add abilitiy not specify root""" @@ -702,16 +763,22 @@ class VariableOsLocationDest(Variable): typepart=checkType.upper(), part=memberData[0][0])) -class VariableOsLocationFormat(Variable): +class VariableOsLocationFormat(LocationVariable,Variable): type = "choice-list" - label = _("File system") + + def init(self): + self.label = _("File system") def get(self): - mount = self.Get("os_location_dest") - source = self.Get("os_location_source") - value = [""]*len(source) - return map(self.defaultFormat(), - zip(source,mount,value)) + if self.Get('cl_autopartition_scheme'): + return self.Get('cl_autopartition_disk_format') + \ + map(lambda x:"",self.Get('cl_autopartition_bind_path')) + else: + mount = self.Get("os_location_dest") + source = self.Get("os_location_source") + value = [""]*len(source) + return map(self.defaultFormat(), + zip(source,mount,value)) def choice(self): if self.Get('cl_install_type') == "flash": @@ -770,17 +837,25 @@ class VariableOsLocationFormat(Variable): _("Swap partition {dev} must be formatted as swap").format( dev=dev)) -class VariableOsLocationPerformFormat(Variable): +class VariableOsLocationPerformFormat(LocationVariable,Variable): type = "bool-list" - label = _("Format") + + def init(self): + self.label = _("Format") def get(self): - mount = self.Get("os_location_dest") - source = self.Get("os_location_source") - fs = self.Get("os_location_format") - value = [""]*len(source) - return map(self.defaultPerformFormat(), - zip(source,mount,fs,value)) + if self.Get('cl_autopartition_scheme'): + return map(lambda x:"on", + self.Get('cl_autopartition_disk_format')) + \ + map(lambda x:"", + self.Get('cl_autopartition_bind_path')) + else: + mount = self.Get("os_location_dest") + source = self.Get("os_location_source") + fs = self.Get("os_location_format") + value = [""]*len(source) + return map(self.defaultPerformFormat(), + zip(source,mount,fs,value)) def check(self,value): """Check perform format @@ -846,16 +921,36 @@ class VariableOsLocationPerformFormat(Variable): return map(self.defaultPerformFormat(), info) +class VariableOsLocationSize(LocationVariable,ReadonlyVariable): + """ + Location size + """ + type = "list" + + def init(self): + self.label = _("Size") + + def get(self): + mapDevSize = dict(self.ZipVars('os_disk_dev','os_disk_size')) + mapDevSize.update( + zip(self.Get('cl_autopartition_disk_dev'), + self.Get('cl_autopartition_disk_size',humanreadable=True))) + + return map(lambda x:mapDevSize.get(x,''), + self.Get('os_location_source')) + class VariableClUuidSet(Variable): """ Use or not UUID for /etc/fstab """ type = "bool" - label = _("Use UUID") opt = ["--uuid"] - help = _("use UUID") value = "on" + def init(self): + self.label = _("Use UUID") + self.help = _("use UUID") + ############################################################# # Install disk parameters ############################################################# @@ -978,6 +1073,8 @@ class VariableOsInstallDiskId(ReadonlyVariable): def get(self): diskId = dict(zip(self.Get('os_disk_dev'), self.Get('os_disk_id'))) + diskId.update(zip(self.Get('cl_autopartition_disk_dev'), + [""]*len(self.Get('cl_autopartition_disk_dev')))) def getIdByFS(fs,parttable,oldid): if parttable == "gpt": return PartitionDistributive.formatIdGpt.get(fs,oldid) @@ -1016,7 +1113,7 @@ class VariableOsInstallDiskSize(ReadonlyVariable): type = "list" def get(self): - diskSize = dict(self.ZipVars('os_disk_dev','os_disk_size')) + diskSize = dict(self.ZipVars('os_location_source','os_location_size')) return map(lambda x:diskSize.get(x,''), self.Get('os_install_disk_dev')) @@ -1028,6 +1125,8 @@ class VariableOsInstallDiskType(ReadonlyVariable): def get(self): diskType = dict(self.ZipVars('os_disk_dev','os_disk_type')) + diskType.update(self.ZipVars('cl_autopartition_disk_dev', + 'cl_autopartition_disk_type')) return map(lambda x:diskType.get(x,''), self.Get('os_install_disk_dev')) @@ -1038,6 +1137,10 @@ class VariableOsInstallDiskParent(ReadonlyVariable): type = "list" def get(self): diskParent = dict(self.ZipVars('os_disk_dev','os_disk_parent')) + # replace value for autopartition + diskParent.update(zip(self.Get('cl_autopartition_disk_dev'), + [self.Get('cl_autopartition_device')]* + len(self.Get('cl_autopartition_disk_dev')))) return map(lambda x:diskParent.get(x,''), self.Get('os_install_disk_dev')) @@ -1048,6 +1151,8 @@ class VariableOsInstallDiskPart(ReadonlyVariable): type = "list" def get(self): diskPart = dict(self.ZipVars('os_disk_dev','os_disk_part')) + diskPart.update(self.ZipVars('cl_autopartition_disk_dev', + 'cl_autopartition_disk_part')) return map(lambda x:diskPart.get(x,''), self.Get('os_install_disk_dev')) @@ -1080,14 +1185,16 @@ class VariableOsInstallBindMountpoint(ReadonlyVariable): where='os_location_source', func=lambda x:not x[0].startswith('/dev/') and x[1]) -class VariableOsInstallMbr(Variable): +class VariableOsInstallMbr(LocationVariable,Variable): """ Disks for boot mbr """ type = "choice-list" opt = ["--mbr"] metavalue = "MBR" - label = _("Disk for install") + + def init(self): + self.label = _("Disk for install") def get(self): """Get default Master boot record install @@ -1105,7 +1212,7 @@ class VariableOsInstallMbr(Variable): # if loaded system livecd if self.Get('os_root_type') == "livecd": # search /boot device or / device, by priority /boot,/ - bootDev=self.Select('os_disk_install_parent', + bootDev=self.Select('os_install_disk_parent', where='os_install_disk_mount', _in=('/','/boot'), sort="DESC",limit=1) @@ -1182,16 +1289,18 @@ class VariableOsInstallMbr(Variable): _("Legacy grub does not support booting from %s without " "separate /boot partition")%bootDiskFormat) -class VariableOsInstallRootType(Variable): +class VariableOsInstallRootType(LocationVariable,Variable): """ Type of installation """ - label = _("Installation type") opt = ["--type"] metavalue = "DISKTYPE" - help = _("device type for the system bound for install") type = "choice" + def init(self): + self.help = _("device type for the system bound for install") + self.label = _("Installation type") + def get(self): rootdev = self.Get('os_install_root_dev') devicetype = getPartitionDevice( @@ -1286,7 +1395,9 @@ class VariableOsInstallDiskSingle(Variable): Installation disk """ type = "choice" - label = _("Installation disk") + + def init(self): + self.label = _("Installation disk") def availDevs(self): """ diff --git a/install/variables/distr.py b/install/variables/distr.py index 1335e3d..456d9e1 100644 --- a/install/variables/distr.py +++ b/install/variables/distr.py @@ -263,9 +263,10 @@ class VariableClImageFilename(Variable,DistroRepository): type = 'file' element = 'file' opt = ['--iso'] - label = _("Installation image") - help = _("ISO image for installation") + def init(self): + self.label = _("Installation image") + self.help = _("ISO image for installation") def get(self): if self.Get('cl_action') != 'system': @@ -313,9 +314,11 @@ class VariableClImageArchMachine(Variable,DistroRepository): """ type = 'choice' opt = ['--march'] - label = _("Preferred processor architecture") - help = _("select the processor architecture") available_arch = ["i686","x86_64"] + + def init(self): + self.label = _("Preferred processor architecture") + self.help = _("select the processor architecture") def set(self,march): if march == "auto": @@ -331,8 +334,10 @@ class VariableClImageLinuxShortname(Variable,Linux,DistroRepository): """ type = 'choice' opt = ['--os','-s'] - label = _("Distributive") - help = _("select the operation system") + + def init(self): + self.label = _("Distributive") + self.help = _("select the operation system") def choice(self): return self.dictLinuxName.keys() @@ -341,17 +346,21 @@ class VariableClImageLinuxVer(Variable,DistroRepository): """ Filter by version """ - label = _("Version") value = "" - help = _("select the operation system by version") + + def init(self): + self.label = _("Version") + self.help = _("select the operation system by version") class VariableClImageLinuxBuild(Variable,DistroRepository): """ Filter by build """ - label = _("Build") value = "" - help = _("select the operation system by build") + + def init(self): + self.label = _("Build") + self.help = _("select the operation system by build") class VariableClImagePath(ReadonlyVariable): """ diff --git a/install/variables/kernel.py b/install/variables/kernel.py index 7b3af45..e1022c7 100644 --- a/install/variables/kernel.py +++ b/install/variables/kernel.py @@ -35,8 +35,10 @@ class VariableOsInstallKernelScheduler(Variable): type = "choiceedit" opt = ["--scheduler"] metavalue = "SCHEDULER" - help = _("set I/O scheduler") - label = _("I/O scheduler") + + def init(self): + self.help = _("set I/O scheduler") + self.label = _("I/O scheduler") def get(self): """Get scheduler for install root device""" @@ -53,7 +55,7 @@ class VariableOsInstallKernelScheduler(Variable): return "cfq" def choice(self): - return ["cfg","deadline","none"] + return ["cfq","deadline","none"] class VariableOsInstallKernelAttr(Variable): """ diff --git a/install/variables/locale.py b/install/variables/locale.py index 09006a0..86465d4 100644 --- a/install/variables/locale.py +++ b/install/variables/locale.py @@ -21,6 +21,8 @@ from calculate.lib.datavars import Variable, VariableError, ReadonlyVariable from calculate.lib.variables.locale import Locale from calculate.lib.utils.files import readLinesFile, process from calculate.lib.utils.common import getValueFromCmdLine, getValueFromConfig +from pytz import timezone,country_timezones,UnknownTimeZoneError +from datetime import datetime from calculate.lib.cl_lang import setLocalTranslate setLocalTranslate('cl_install',sys.modules[__name__]) @@ -106,7 +108,8 @@ class VariableOsInstallLocaleLocale(LocaleVariable): """ def get(self): """locale (example: ru_RU.UTF-8)""" - return self.Get('os_locale_locale') + return self.getFieldByLang("locale", + self.Get('os_install_locale_lang')) class VariableOsInstallLocaleLang(LocaleVariable): """ @@ -114,16 +117,17 @@ class VariableOsInstallLocaleLang(LocaleVariable): """ mode = 'w' type = 'choice' - label = _("Language") opt = ["--lang","-l"] + def init(self): + self.label = _("Language") + def get(self): """lang (example: ru_RU)""" - return self.getLangByField("locale", - self.Get('os_install_locale_locale')) + return self.Get('os_locale_lang') def choice(self): - return self.Get('os_lang') + return zip(self.Get('os_lang'),self.Get('os_lang',humanreadable=True)) class VariableOsInstallLocaleLanguage(LocaleVariable): """ @@ -133,7 +137,6 @@ class VariableOsInstallLocaleLanguage(LocaleVariable): return self.getFieldByLang("language", self.Get('os_install_locale_lang')) - class VariableOsInstallLocaleXkb(LocaleVariable): """ Keyboard layout for X server @@ -152,16 +155,19 @@ class VariableOsInstallLocaleXkbname(LocaleVariable): return localeXkb.split("(")[0] return "" + class VariableOsInstallClockTimezone(LocaleVariable): """ Installation timezone for clock """ mode = 'w' type = 'choiceedit' - label = _("Timezone") metavalue = "TIMEZONE" opt = ["--timezone"] + def init(self): + self.label = _("Timezone") + def get(self): return self.Get('os_clock_timezone') @@ -170,8 +176,24 @@ class VariableOsInstallClockTimezone(LocaleVariable): "/usr/share/zoneinfo",value)): raise VariableError(_("%s timezone is wrong")%value) + def generateComments(self,tzs): + """ + Generate comments by timezone names + """ + for tzname in tzs: + # add separator + if tzname == "---": + yield ("---","---") + continue + try: + tz = timezone(tzname) + strinfo = tz.localize(datetime.now()).strftime('%z') + yield (tzname,"%s (%s:%s)"%(tzname,strinfo[:3],strinfo[-2:])) + except UnknownTimeZoneError: + pass + def choice(self): - return ["Etc/GMT-12", "Pacific/Midway", "Pacific/Honolulu", + source = ["Etc/GMT-12", "Pacific/Midway", "Pacific/Honolulu", "America/Anchorage", "Canada/Pacific", "America/Tijuana", "America/Phoenix", "America/Denver", "America/Mazatlan", "America/Mazatlan", "America/Monterrey", "America/Monterrey", @@ -200,6 +222,15 @@ class VariableOsInstallClockTimezone(LocaleVariable): "Asia/Vladivostok", "Pacific/Guam", "Australia/Melbourne", "Australia/Hobart", "Asia/Magadan", "Asia/Kamchatka", "Pacific/Auckland", "Etc/GMT-13"] + try: + lang = self.Get('os_install_locale_lang').split('_')[1] + nativeTZ = map(lambda x:x.encode('utf-8'), + country_timezones[lang]) + source = nativeTZ + ["---"] + filter(lambda x:not x in nativeTZ, + source) + except (KeyError,IndexError) as e: + pass + return list(self.generateComments(source)) class VariableOsInstallClockType(Variable): """ @@ -207,10 +238,12 @@ class VariableOsInstallClockType(Variable): """ mode = 'w' type = 'choice' - label = _("Clock type") opt = ["--clocktype"] metavalue = "CLOCKTYPE" + def init(self): + self.label = _("Clock type") + def get(self): """type of clock (UTC or local)""" clockTypeFile = ['/etc/conf.d/clock','/etc/conf.d/hwclock'] diff --git a/install/variables/net.py b/install/variables/net.py index f1ed8a6..b695b95 100644 --- a/install/variables/net.py +++ b/install/variables/net.py @@ -63,12 +63,14 @@ class VariableOsInstallNtp(NetVariable): """ NTP server for system """ - label = _("NTP server") opt = ['--ntp'] - help = _("set the ntp server for the system") metavalue = "NTP" value = "ntp0.zenon.net" + def init(self): + self.label = _("NTP server") + self.help = _("set the ntp server for the system") + class VariableOsInstallProxy(NetVariable): """ Proxy for system @@ -81,7 +83,9 @@ class VariableOsInstallNetInterfaces(NetVariable): """ type = "list" mode = READONLY - label = _("Interface") + + def init(self): + self.label = _("Interface") def get(self): return getInterfaces() @@ -120,8 +124,10 @@ class VariableOsInstallNetData(NetVariable): "os_install_net_mask", "os_install_net_name", "os_install_net_mac"] - help = _("ip address with net (example:%s)")%"192.168.1.1/24" - label = _("Addresses") + + def init(self): + self.label = _("Addresses") + self.help = _("ip address with net (example:%s)")%"192.168.1.1/24" class VariableOsInstallNetHostname(NetVariable): """ @@ -135,8 +141,10 @@ class VariableOsInstallNetFqdn(NetVariable): Full host name """ opt = ['--hostname'] - label = _("Hostname") - help = _("set the short hostname or full hostname") + + def init(self): + self.label = _("Hostname") + self.help = _("set the short hostname or full hostname") def set(self,value): if "." in value: @@ -175,7 +183,9 @@ class VariableOsInstallNetName(NetVariable): """ type = "list" mode = READONLY - label = _("Name") + + def init(self): + self.label = _("Name") def get(self): rePci = re.compile(r"(\d\d:\d\d\.\d)(?:/[^/]+){2}$") @@ -200,7 +210,9 @@ class VariableOsInstallNetMac(NetVariable): """ type = "list" mode = READONLY - label = _("MAC") + + def init(self): + self.label = _("MAC") def get(self): return map(lambda x:getMac(x), @@ -211,7 +223,9 @@ class VariableOsInstallNetIp(NetVariable): IP for all network interfaces """ type = "list" - label = _("IP address") + + def init(self): + self.label = _("IP address") def get(self): return map(lambda x:getIp(x), @@ -228,7 +242,9 @@ class VariableOsInstallNetNetwork(NetVariable): """ type = "list" mode = READONLY - label = _("Network") + + def init(self): + self.label = _("Network") def get(self): return map(lambda x:getIpNet(x[0],x[1]) if x[0] else "", @@ -241,7 +257,9 @@ class VariableOsInstallNetCidr(NetVariable): """ type = "list" mode = READONLY - label = _("CIDR") + + def init(self): + self.label = _("CIDR") def get(self): """ @@ -255,7 +273,9 @@ class VariableOsInstallNetMask(NetVariable): Net mask of interfaces (Example:255.255.0.0) """ type = "choiceedit-list" - label = _("Mask") + + def init(self): + self.label = _("Mask") def get(self): return map(lambda x:cidrToMask(getMask(x)), @@ -291,7 +311,9 @@ class VariableOsInstallNetDhcpSet(NetVariable): Describe ip was get by DHCP or manualy """ type = "bool-list" - label = _("DHCP") + + def init(self): + self.label = _("DHCP") def get(self): return map(lambda x:"on" if isDhcpIp(x) else "off", @@ -311,16 +333,18 @@ class VariableOsInstallNetRouteData(NetVariable): """ Route table data """ - label = _("Routing") opt = ["--route"] metavalue = "NETWORK:[GATEWAY][:DEV[:SOURCE]]" - help = _("add a routing rule") type = "table" source = ['os_install_net_route_network', 'os_install_net_route_gw', 'os_install_net_route_dev', 'os_install_net_route_src'] + def init(self): + self.label = _("Routing") + self.help = _("add a routing rule") + def get(self): """Routing hash""" interfaces = self.Get('os_install_net_interfaces') @@ -343,10 +367,12 @@ class VariableOsInstallNetRouteNetwork(FieldValue,NetVariable): Net for route table record """ type = "choiceedit-list" - label = _("Network") source_variable = "os_install_net_route_data" column = 0 + def init(self): + self.label = _("Network") + def choice(self): return ["default"]+self.Get('os_install_net_network') @@ -363,10 +389,12 @@ class VariableOsInstallNetRouteGw(FieldValue,NetVariable): """ Gateway for route table record """ - label = _("Gateway") source_variable = "os_install_net_route_data" column = 1 + def init(self): + self.label = _("Gateway") + def check(self,value): ############################# # search unreachable gateways @@ -391,10 +419,12 @@ class VariableOsInstallNetRouteDev(FieldValue,NetVariable): Device for route table record """ type = "choice-list" - label = _("Interface") source_variable = "os_install_net_route_data" column = 2 + def init(self): + self.label = _("Interface") + def choice(self): return self.Get('os_install_net_interfaces') @@ -403,10 +433,12 @@ class VariableOsInstallNetRouteSrc(FieldValue,NetVariable): Source ip for route table record """ type = "choiceedit-list" - label = _("Source") source_variable = "os_install_net_route_data" column = 3 + def init(self): + self.label = _("Source") + def choice(self): return [""]+self.Get('os_install_net_ip') @@ -488,10 +520,12 @@ class VariableOsInstallNetConf(NetVariable): Net setup (networkmanager or openrc) """ type = "choice" - label = _("Network manager") opt = ["--netconf"] metavalue = "NETMANAGER" - help = _("network manager") + + def init(self): + self.label = _("Network manager") + self.help = _("network manager") def get(self): """Net setup (networkmanager or openrc)""" diff --git a/install/variables/system.py b/install/variables/system.py index 5c4f37d..05a895a 100644 --- a/install/variables/system.py +++ b/install/variables/system.py @@ -48,8 +48,10 @@ class VariableOsInstallScratch(Variable): """ type = "bool" opt = ['--build'] - label = _("Builder mode") - help = _("installation for assemble") + + def init(self): + self.label = _("Builder mode") + self.help = _("installation for assemble") def get(self): # for installation default - normal system @@ -101,16 +103,20 @@ class VariableClMigrateData(UserVariable): type = 'table' opt = ["--users","-u"] metavalue = 'USERS' - help = _("add a user to the installed system") - label = _("Migration users") source = ['cl_migrate_user','cl_migrate_user_pwd'] + def init(self): + self.help = _("add a user to the installed system") + self.label = _("Migration users") + class VariableClMigrateUser(UserVariable): """ Migrate users list """ type = 'list' - label = _("Login") + + def init(self): + self.label = _("Login") def get(self): """ @@ -123,7 +129,9 @@ class VariableClMigrateUserPwd(UserVariable): Migrate users who need to change passwords """ type = 'password-list' - label = _("Password") + + def init(self): + self.label = _("Password") def get(self): """ @@ -191,10 +199,12 @@ class VariableClAutologin(UserVariable): empty string if disable """ type = 'choiceedit' - label = _("Autologin") opt = ["--autologin",'-A'] metavalue = "USER" - help = _("add an autologin user to the installed system") + + def init(self): + self.label = _("Autologin") + self.help = _("add an autologin user to the installed system") def get(self): # autologin enable for livecd and all install type CMC