From 90532bd31fd6e8e1d39446b0528fea3c8ad0fb43 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Mon, 26 Mar 2012 13:01:01 +0400 Subject: [PATCH] Migrate to new variables. --- install/cl_distr.py | 23 +- install/cl_install.py | 7 +- install/datavars.py | 6 +- install/variables/X11.py | 182 ++--- install/variables/__init__.py | 51 +- install/variables/action.py | 63 +- install/variables/disk.py | 1286 ++++++++++++++++++--------------- install/variables/distr.py | 374 +++++----- install/variables/kernel.py | 140 ++-- install/variables/linux.py | 104 ++- install/variables/locale.py | 214 +++--- install/variables/net.py | 504 +++++++------ install/variables/system.py | 500 ++++++------- 13 files changed, 1889 insertions(+), 1565 deletions(-) diff --git a/install/cl_distr.py b/install/cl_distr.py index 25d92be..3ab0623 100644 --- a/install/cl_distr.py +++ b/install/cl_distr.py @@ -32,7 +32,7 @@ from calculate.lib.utils.files import (runOsCommand,isMount,removeDir, from calculate.lib.utils.common import getTupleVersion,cmpVersion from calculate.lib.utils.device import (detectDeviceForPartition, getUdevDeviceInfo, countPartitions) -from calculate.lib.variables import Linux +from calculate.lib.variables.linux import LinuxDataVars from calculate.lib.cl_vars_share import varsShare from calculate.lib.cl_template import _terms @@ -451,21 +451,10 @@ class Distributive(object, SignalInterrupt): d['march']= 'i686' else: d['march'] = '' - d["name"] = Linux.getShortnameByMakeprofile(directory) or \ - Linux.detectOtherShortname(directory) or "" - d['ver'] = \ - Linux.getVersionFromMetapackage(directory,d["name"]) or "0" - reOsLinuxBuild = re.compile("^os_linux_build\s*=\s*(\S+)\s*$") - os_linux_build = \ - map(lambda x:x.groups()[0], - filter(lambda x:x, - map(reOsLinuxBuild.search, - readLinesFile(path.join(directory, - "etc/calculate/calculate2.env"))))) - if os_linux_build: - d['build'] = os_linux_build[-1] - else: - d['build'] = "" + dv = LinuxDataVars(systemRoot=directory) + d["name"] = dv.Get('os_linux_name') + d['ver'] = dv.Get('os_linux_ver') + d['build'] = dv.Get('os_linux_build') return d.copy() def getInfo(self,filename=None): @@ -717,7 +706,7 @@ class PartitionDistributive(Distributive): pathname = self.getDirectory() except: return False - return Linux.detectOtherShortname(pathname) + return Linux().detectOtherShortname(pathname) def _mountPartition(self,partition,directory,opts=""): """Mount partition to directory""" diff --git a/install/cl_install.py b/install/cl_install.py index d09e4b5..554ea0e 100644 --- a/install/cl_install.py +++ b/install/cl_install.py @@ -14,9 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "3.0.0" -__app__ = "calculate-install" - import os import re import sys @@ -39,7 +36,7 @@ from calculate.lib.utils.device import (detectDeviceForPartition, from calculate.lib.cl_vars_share import varsShare from calculate.lib import cl_overriding from calculate.lib.utils import ip -from datavars import DataVarsInstall +from datavars import DataVarsInstall, __version__,__app__ from cl_kernel_utils import KernelConfig,InitRamFs @@ -61,7 +58,7 @@ def pop_install_errors(): defaultExit = cl_overriding.exit defaultPrintERROR = cl_overriding.printERROR -from calculate.lib.variables import Locale +from calculate.lib.variables.locale import Locale from calculate.lib.cl_template import Template,TemplatesError from calculate.lib.datavars import DataVars from calculate.lib.cl_print import color_print diff --git a/install/datavars.py b/install/datavars.py index 34d5452..80c910a 100644 --- a/install/datavars.py +++ b/install/datavars.py @@ -14,6 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +__app__ = 'calculate-install' +__version__ = '3.0.0' + import os import sys from calculate.lib.datavars import DataVars @@ -26,4 +29,5 @@ class DataVarsInstall(DataVars): def importInstall(self, **args): """Import install variables""" - self.importData('calculate.install.cl_vars_install') + self.importData() + self.importData('calculate.install.variables') diff --git a/install/variables/X11.py b/install/variables/X11.py index 9b4a5a0..91d9e4e 100644 --- a/install/variables/X11.py +++ b/install/variables/X11.py @@ -18,8 +18,7 @@ import os import sys import re from os import path -from calculate.lib.datavars import Variables,VariableError -from calculate.lib.variables import X11 +from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable from calculate.lib.utils.portage import isPkgInstalled from calculate.lib.utils.files import process,STDOUT,getProgPath from calculate.lib.utils.common import (getVideoFromXorgLog, @@ -31,44 +30,71 @@ from calculate.lib.utils.common import (getVideoFromXorgLog, from calculate.lib.cl_lang import setLocalTranslate setLocalTranslate('cl_install',sys.modules[__name__]) -class InstallX11(X11): - vars = ["os_install_x11_resolution","os_install_x11_video_drv", - "os_install_x11_composite","os_install_fb_resolution","hr_video_id"] - # xorg resolution - os_install_x11_resolution = {'mode':'w', - 'type':'choiceedit', - 'opt':['-X'], - 'metavalue':"x", - 'help':_("set Xorg resolution"), - 'label':_("Screen resolution")} - - # Video driver used by xorg - os_install_x11_video_drv = {'mode':'w', - 'type':'choice', - 'opt':['--video'], - 'metavalue':"VIDEODRV", - 'help':_("set the video driver"), - 'label':_("{0} video driver").format("Xorg")} - - # on/off composite - os_install_x11_composite = {'mode':'w', - 'type':'bool', - 'opt':['--composite'], - 'help':_("set composite"), - 'label':_("Composite")} - - # fb resolution - os_install_fb_resolution = {'mode':'w', - 'type':'choiceedit', - 'opt':['--fb'], - 'metavalue':"x", - 'help':_("set framebuffer resolution"), - 'label':_("Framebuffer resolution")} - - # busid of video card - hr_video_id = {'value':""} - - def choice_os_install_x11_video_drv(self): +class VideoVariable(Variable): + """ + Video variables not using for flash installation + """ + def uncompatible(self): + """ + Video setting up unavailable for flash installation + """ + if self.Get('os_install_root_type') == 'flash': + return \ + _("Video configuration unavailable for flash installation") + return "" + +class ResolutionVariable(VideoVariable): + """ + Abstract resolution variable + """ + def choice(self): + return ["800x600", "800x480", "640x480", "2560x1600", "2560x1440", + "2048x1152", "1920x1200", "1920x1080", "1680x945", "1680x1050", + "1600x900", "1600x768", "1600x1200", "1440x900", "1400x1050", + "1368x768", "1366x768", "1360x768", "1280x800", "1280x768", + "1280x720", "1280x1024", "1200x800", "1024x600", "1024x576", + "1024x768"] + + def check(self,value): + """ + Check resolution format 1234x567 + """ + if not re.match('^\d+x\d+$',value): + raise VariableError( + _("Wrong resolution {resolution} {example}").format( + resolution=value, + example="(%s:%s)"%(_("Example"),"1024x768"))) + + +class VariableOsInstallX11Resolution(ResolutionVariable): + """ + X.org resolution + """ + type = 'choiceedit' + opt = ['-X'] + metavalue = "x" + help = _("set Xorg resolution") + label = _("Screen resolution") + + def get(self): + # get resolution from xorg.log + res = self.Get('os_x11_resolution') + if res or self.Get('os_install_root_type') in ('livecd','usb-hdd'): + return res + else: + return self.choice()[-1] + +class VariableOsInstallX11VideoDrv(VideoVariable): + """ + Video driver used by xorg + """ + type = 'choice' + opt = ['--video'] + metavalue = "VIDEODRV" + help = _("set the video driver") + label = _("{0} video driver").format("Xorg") + + def choice(self): """Get available (already installed or installable drivers""" image = self.Get('cl_image') if image: @@ -78,8 +104,7 @@ class InstallX11(X11): return getAvailableVideo(prefix=distrPath)+['other'] return [] - def get_os_install_x11_video_drv(self): - """Get install video drv""" + def get(self): # get available videodriver list from install or configure distributive list_video = self.Choice('os_install_x11_video_drv')#getAvailableVideo(distrPath) if not list_video: @@ -102,33 +127,23 @@ class InstallX11(X11): return drv return "other" - def choice_os_install_x11_resolution(self): - """Sample resolutions""" - return ["800x600", "800x480", "640x480", "2560x1600", "2560x1440", - "2048x1152", "1920x1200", "1920x1080", "1680x945", "1680x1050", - "1600x900", "1600x768", "1600x1200", "1440x900", "1400x1050", - "1368x768", "1366x768", "1360x768", "1280x800", "1280x768", - "1280x720", "1280x1024", "1200x800", "1024x600", "1024x576", - "1024x768"] - - def check_os_install_x11_resolution(self,value): - """Check resolution""" - if not re.match('^\d+x\d+$',value): - raise VariableError( - _("Wrong resolution {resolution} {example}").format( - resolution=value, - example="(%s:%s)"%(_("Example"),"1024x768"))) - - def get_os_install_x11_resolution(self): - """Xorg resolution""" - # get resolution from xorg.log - res = self.Get('os_x11_resolution') - if res or self.Get('os_install_root_type') in ('livecd','usb-hdd'): - return res - else: - return self.Choice('os_install_x11_resolution')[-1] - - def get_os_install_x11_composite(self): +class VariableHrVideoId(ReadonlyVariable): + """ + BusID of video card + TODO: need realization + """ + value = "" + +class VariableOsInstallX11Composite(VideoVariable): + """ + on/off composite + """ + type = 'bool' + opt = ['--composite'] + help = _("set composite") + label = _("Composite") + + def get(self): """On/off composite""" defaultCompositeOn = ("nvidia","intel","fglrx","nouveau","radeon") composite = getValueFromCmdLine("calculate",5) @@ -151,10 +166,17 @@ class InstallX11(X11): state = None return composite or state or defaultComposite - choice_os_install_fb_resolution = choice_os_install_x11_resolution - check_os_install_fb_resolution = check_os_install_x11_resolution - - def get_os_install_fb_resolution(self): +class VariableOsInstallFbResolution(ResolutionVariable): + """ + Framebuffer resolution + """ + type = 'choiceedit' + opt = ['--fb'] + metavalue = "x" + help = _("set framebuffer resolution") + label = _("Framebuffer resolution") + + def get(self): """Get current framebuffer resolution""" resolution = "" fbres = getProgPath('/sbin/fbres') @@ -170,17 +192,3 @@ class InstallX11(X11): int(cxx11) >= int(cxfb) and int(cyx11) >= int(cyfb): resolution = "%s-32"%textLines[0] return resolution or "1024x768-32@60" - - def uncompatible_video_vars(self): - """ - Network setting up unavailable for flash installation - """ - if self.Get('os_install_root_type') == 'flash': - return \ - _("Video configuration unavailable for flash installation") - return "" - - uncompatible_os_install_x11_video_drv = \ - uncompatible_os_install_x11_resolution = \ - uncompatible_os_install_fb_resolution = \ - uncompatible_video_vars diff --git a/install/variables/__init__.py b/install/variables/__init__.py index c3434fb..a4c8def 100644 --- a/install/variables/__init__.py +++ b/install/variables/__init__.py @@ -1,9 +1,42 @@ -from action import InstallAction -from disk import InstallDisk -from distr import Distro -from kernel import InstallKernel -from linux import InstallLinux -from locale import InstallLocale -from net import InstallNet -from system import InstallSystem -from X11 import InstallX11 +#-*- coding: utf-8 -*- + +# Copyright 2008-2012 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. + +from calculate.install.datavars import __version__,__app__ +from calculate.lib.datavars import ReadonlyVariable + +import action +import disk +import locale +import linux +import distr +import kernel +import net +import system +import X11 + +section = "install" + +class VariableClName(ReadonlyVariable): + """ + Package name + """ + value = __app__ + +class VariableClVer(ReadonlyVariable): + """ + Package version + """ + value = __version__ diff --git a/install/variables/action.py b/install/variables/action.py index 29c051c..2fd45ea 100644 --- a/install/variables/action.py +++ b/install/variables/action.py @@ -17,41 +17,16 @@ import os import sys from os import path -from calculate.lib.datavars import Variables +from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable from calculate.lib.cl_lang import setLocalTranslate setLocalTranslate('cl_install',sys.modules[__name__]) -class InstallAction(Variables): - vars = ["ac_install_merge","ac_install_system","ac_install_flash", - "ac_install_live","ac_install_pxe"] +class VariableAcInstallMerge(ReadonlyVariable): """ Action variable which has value "up" by default and not flash installation """ - ac_install_merge = {} - - """ - Action variable which has value "up" for installation on hdd - """ - ac_install_system = {} - - """ - Action variable which has value "up" for USB flash - """ - ac_install_flash = {} - - """ - Action which "up" value describe dinamic templates - """ - ac_install_live = {} - - """ - Action variable which has value "up" for PXE installation - """ - ac_install_pxe = {'value':''} - - def get_ac_install_merge(self): - """Need perform templates for install:merge or install:unmerge""" + def get(self): actionsMap = {'merge':'up', 'system':'up'} cl_action = self.Get('cl_action') @@ -60,23 +35,32 @@ class InstallAction(Variables): return "" return actionsMap.get(cl_action,'') - def get_ac_install_system(self): - """Need perform templates for install:system""" +class VariableAcInstallSystem(ReadonlyVariable): + """ + Action variable which has value "up" for installation on hdd + """ + def get(self): if self.Get('cl_action') == 'system' and \ self.Get('os_install_root_type') != "flash": return "up" else: return "" - def get_ac_install_flash(self): - """Need perform templates for install:flash""" +class VariableAcInstallFlash(ReadonlyVariable): + """ + Action variable which has value "up" for USB flash + """ + def get(self): clAction = self.Get('cl_action') if clAction == 'system' and self.Get('os_install_root_type') == 'flash': return "up" return "" - def get_ac_install_live(self): - """Need perform templates for install:live""" +class VariableAcInstallLive(ReadonlyVariable): + """ + Action which "up" value describe dinamic templates + """ + def get(self): if self.Get('ac_install_merge') == "up" and \ self.Get('cl_chroot_status') == "off" or \ self.Get('cl_action') == 'live': @@ -84,3 +68,14 @@ class InstallAction(Variables): else: return "" +class VariableAcInstallPxe(ReadonlyVariable): + """ + Action variable which has value "up" for PXE installation + """ + def get_ac_install_pxe(self): + return "" + #clAction = self.Get('cl_action') + #if clAction == 'system' and self.Get('os_install_pxe') == 'on': + # return "up" + #return "" + diff --git a/install/variables/disk.py b/install/variables/disk.py index 64f0871..5656761 100644 --- a/install/variables/disk.py +++ b/install/variables/disk.py @@ -18,8 +18,7 @@ import os import sys import re from os import path -from calculate.lib.datavars import Variables,VariableError -#from calculate.lib.utils import ../calculate-lib3/calculate/lib/utils/device.py +from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable from calculate.lib.utils.device import (getUdevDeviceInfo,getDeviceType, getPartitionType,getPartitionDevice,getRaidPartitions, getLvmPartitions,getPartitionSize,getUUIDDict) @@ -30,234 +29,114 @@ from calculate.install.cl_install import FileSystemManager from calculate.lib.cl_lang import setLocalTranslate setLocalTranslate('cl_install',sys.modules[__name__]) -class InstallDisk(Variables): - vars = ["os_device_data","os_disk_data","os_disk_dev", - "os_install_root_type", "os_install_root_dev", - "os_install_disk_mount","os_disk_mount","os_disk_content", - "os_disk_format","os_disk_type","os_disk_parent", - "os_install_disk_format","os_install_disk_data", - "os_install_disk_perform_format","os_install_disk_uuid", - "os_install_disk_use","cl_uuid_set","os_install_disk_id", - "os_disk_uuid","os_disk_id","os_install_mbr","os_disk_grub", - "os_disk_part", - "os_disk_size","os_disk_name","os_disk_options","os_device_dev", - "os_device_type","os_device_map","os_device_table","os_device_name", - "os_install_disk_options","os_bind_data","os_bind_path", - "os_bind_mountpoint", - "os_install_bind_data","os_install_bind_path", - "os_install_bind_mountpoint", - "os_install_fstab_mount_conf","os_install_fstab_swap_conf", - "os_location_source", "os_location_dest", "os_location_format", - "os_location_perform_format", "os_location_data", - "os_install_disk_name", "os_install_disk_size", - "os_install_disk_type", "os_install_disk_dev", - "os_install_disk_part", "os_install_disk_parent"] - - # infomation about disk in hash - os_disk_data = {'type':'table', - 'source':['os_disk_dev', - 'os_disk_uuid', - 'os_disk_name', - 'os_disk_size', - 'os_disk_part', - 'os_disk_format', - 'os_disk_type', - 'os_disk_parent', - 'os_disk_id', - 'os_disk_grub']} - - # list of available partition devices - os_disk_dev = {'type':"list"} - - # list mounted points for current operation system - os_disk_mount = {'type':"list"} - - # partition content - os_disk_content = {'type':"list"} - - # list filesystem for partition devices - os_disk_format = {'type':"list"} - - # list type (lvm,raid,partition,disk) - os_disk_type = {'type':"list"} - - # list uudi for partition devices - os_disk_uuid = {'type':"list"} - - # list parent deivces for partition - os_disk_parent = {'type':"list"} - - # partition's system id - os_disk_id = {'type':"list"} - - # list grub id for partition devices - os_disk_grub = {'type':"list"} - - # type of partition devices - # if msdos then(primary, extended or logical) - # if gpt then gpt - os_disk_part = {'type':"list"} - - # partition size - os_disk_size = {'type':"list"} - - # label of partitions - os_disk_name = {'type':"list"} - - # list mount options - os_disk_options = {'type':"list"} - - # disk variable - os_location_data = { - '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"), - 'mode':"w", - 'source':["os_location_source", - "os_location_dest", - "os_location_format", - "os_location_perform_format"]} - - os_location_source = {'type':"choiceedit-list", - 'label':_("Disk or directory"), - 'mode':"w"} - - os_location_dest = {'type':"choiceedit-list", - 'label':_("Mount point"), - 'mode':"w"} - - os_location_format = {'type':"choice-list", - 'label':_("File system"), - 'mode':"w"} - - os_location_perform_format = {'type':"bool-list", - 'label':_("Format"), - 'mode':"w"} - - cl_uuid_set = {'value':'on', - 'type':'bool', - 'label':_("Use UUID"), - 'opt':["--uuid"], - 'help':_("use UUID"), - 'mode':'w'} - - os_install_disk_data = {'type':"table", - 'source':['os_install_disk_dev', - 'os_install_disk_mount', - 'os_install_disk_format', - 'os_install_disk_perform_format', - 'os_install_disk_options', - 'os_install_disk_id', - 'os_install_disk_uuid', - 'os_install_disk_use', - "os_install_disk_name", - "os_install_disk_size", - "os_install_disk_type", - "os_install_disk_part", - "os_install_disk_parent" - ]} - - # disks for installation - os_install_disk_dev = {'type':"list"} - - # uudi for install - os_install_disk_uuid = {'type':"list"} - - # list mounted points for installed system - os_install_disk_mount = {'type':"list"} - - # /dev/sd or UUID= list (by cl_uuid_set) - os_install_disk_use = {'type':"list"} - - # list mount options of installed os - os_install_disk_options = {'type':"list"} - - # install list filesystem for partition devices - os_install_disk_format = {'type':"choice-list"} - - # need format - os_install_disk_perform_format = {'type':"bool-list"} - - # install partition's system id - os_install_disk_id = {'type':"list"} - - # new labels for disk - os_install_disk_name = {'type':"list", - 'mode':"w"} - - # new partition sizes (for feature change partition) - os_install_disk_size = {'type':"list"} - - # new partition scheme (for feature change partition) - os_install_disk_type = {'type':"list"} - - # new partition type - os_install_disk_part = {'type':"list"} - - # partition parent - os_install_disk_parent = {'type':"list"} - # disk for boot mbr - os_install_mbr = {'type':"list", - 'opt':['--mbr'], - 'metavalue':'MBR', - 'label':"Disk for install", - 'mode':"w"} - - # devices - os_device_data = {'type':'table', - 'source':['os_device_dev', - 'os_device_table', - 'os_device_type', - 'os_device_map', - 'os_device_name']} - - os_device_dev = {'type':'list'} +class DeviceHelper: + sysBlockPath = '/sys/block' + rePassDevice = re.compile("^(?!%s)"%"|".join(['fd','ram','loop'])) - # device type (hdd,cdrom,usb-flash) - os_device_type = {'type':'list'} + def getDeviceFromSysPath(self): + """Get interest devices from sys block path""" + return filter(self.rePassDevice.search, + listDirectory(self.sysBlockPath)) - # map number for grub - os_device_map = {'type':'list'} + def separateDevice(self,device): + """ + Separate device word and number on tuple - # table for device - os_device_table = {'type':'list'} + Using for sort. (Example: sda2 ("sda",2), md5p1 ("md",5,"p",1) + """ + return map(lambda x: int(x) if x.isdigit() else x, + re.findall('\d+|\D+',device)) - # name of device - os_device_name = {'type':'list'} + def mapUdevProperty(self,var,prop,default): + """Get each element from var through udev [prop]""" + return map(lambda x:getUdevDeviceInfo(name=x).get(prop,default), + self.Get(var)) - os_bind_data = {'type':'table', - 'source':['os_bind_path', - 'os_bind_mountpoint']} +####################################################### +# Devices variables +####################################################### +class VariableOsDeviceData(ReadonlyVariable): + """ + Information about disk devices + """ + type = 'table' + source = ['os_device_dev', + 'os_device_table', + 'os_device_type', + 'os_device_map', + 'os_device_name'] + +class VariableOsDeviceDev(ReadonlyVariable,DeviceHelper): + """ + Disk devices + """ + type = "list" + + def get(self): + """Get device /dev name""" + def _getDiskName(devpath): + """Get devname only for by udevadm that devpath is device (disk)""" + prop = getUdevDeviceInfo(devpath) + if prop.get("ID_TYPE","")=="disk" and \ + prop.get("DEVTYPE","")=="disk": + return prop.get('DEVNAME','') - # directories for bind - os_bind_path = {'type':"list"} + # get devices from /sys/block directories(discard mem,sr,loop and other) + return sorted( + filter(lambda x:x, + map(_getDiskName, + map(lambda x:path.join(self.sysBlockPath,x), + self.getDeviceFromSysPath()))), + key=self.separateDevice) - # mountpoint for directories bind - os_bind_mountpoint = {'type':"list"} +class VariableOsDeviceType(ReadonlyVariable): + """ + Device type (hdd,cdrom,usb-flash) + """ + type = "list" + + def getType(self,device): + if path.basename(device) in self.usbdevices: + # check for usb flash (removeable fiel in sysfs contains "1") + removablePath = '/sys/block/%s/removable'%path.basename(device) + if readFile(removablePath).strip() == "1": + return "flash" + else: + return "usb-hdd" + else: + return "hdd" - os_install_bind_data = {'type':"table", - 'source':['os_install_bind_path', - 'os_install_bind_mountpoint']} + def get(self): + # get usb device by '/dev/disk/by-id'(usb devices contain 'usb' in name) + diskIdPath = '/dev/disk/by-id' + if path.exists(diskIdPath): + self.usbdevices = \ + map(lambda x: \ + os.readlink(path.join(diskIdPath,x)).rpartition('/')[2], + filter(lambda x: x.startswith('usb-'),listDirectory(diskIdPath))) + else: + self.usbdevices = [] + return map(self.getType, + self.Get('os_device_dev')) - # install directories for bind - os_install_bind_path = {'type':"list"} +class VariableOsDeviceMap(ReadonlyVariable): + """ + Map number for grub - # mountpoint for install directories bind - os_install_bind_mountpoint = {'type':"list"} + Using for legecy grub (DEPRECATATED) + """ + type = "list" - # information about mount points for fstab - os_install_fstab_mount_conf = {} + def get(self): + return map(lambda x:x[0], + enumerate(self.Get('os_device_dev'))) - # information about swap for fstab - os_install_fstab_swap_conf = {} - sysBlockPath = '/sys/block' - rePassDevice = re.compile("^(?!%s)"%"|".join(['fd','ram','loop'])) +class VariableOsDeviceTable(ReadonlyVariable): + """ + Table on device + """ + type = "list" def getTableByChild(self,device): """Get table by child partitions""" @@ -272,29 +151,7 @@ class InstallDisk(Variables): return getUdevDeviceInfo(path=child).get('ID_PART_ENTRY_SCHEME','') return "" - def separateDevice(self,device): - return map(lambda x: int(x) if x.isdigit() else x, - re.findall('\d+|\D+',device)) - - def get_os_device_dev(self): - """Get device /dev name""" - def getDiskName(devpath): - """Get devname only for by udevadm that devpath is device (disk)""" - prop = getUdevDeviceInfo(devpath) - if prop.get("ID_TYPE","")=="disk" and \ - prop.get("DEVTYPE","")=="disk": - return prop.get('DEVNAME','') - - # get devices from /sys/block directories(discard mem,sr,loop and other) - return sorted( - filter(lambda x:x, - map(getDiskName, - map(lambda x:path.join(self.sysBlockPath,x), - filter(self.rePassDevice.search, - listDirectory(self.sysBlockPath))))), - key=self.separateDevice) - - def get_os_device_table(self): + def get(self): """Get device partition table""" def getTable(device): prop = getUdevDeviceInfo(name=device) @@ -303,109 +160,114 @@ class InstallDisk(Variables): return map(getTable, self.Get('os_device_dev')) - def get_os_device_type(self): - """Get device type (hdd,usb-hdd,flash)""" - # get usb device by '/dev/disk/by-id'(usb devices contain 'usb' in name) - diskIdPath = '/dev/disk/by-id' - if path.exists(diskIdPath): - usbdevices = \ - map(lambda x: \ - os.readlink(path.join(diskIdPath,x)).rpartition('/')[2], - filter(lambda x: x.startswith('usb-'),listDirectory(diskIdPath))) - else: - usbdevices = [] - def getType(device): - if path.basename(device) in usbdevices: - # check for usb flash (removeable fiel in sysfs contains "1") - removablePath = '/sys/block/%s/removable'%path.basename(device) - if readFile(removablePath).strip() == "1": - return "flash" - else: - return "usb-hdd" - else: - return "hdd" - return map(getType, - self.Get('os_device_dev')) - def get_os_device_map(self): - """Get device map for legecy grub""" - return map(lambda x:x[0], - enumerate(self.Get('os_device_dev'))) +class VariableOsDeviceName(ReadonlyVariable): + """ + Name of device + """ + type = "list" + + def getName(self,device): + prop = getUdevDeviceInfo(name=device) + devicepath = prop.get("DEVPATH","") + if devicepath: + if not devicepath.startswith("/sys"): + devicepath = pathJoin("/sys",devicepath) + pathVendor = "%s/device/vendor"%devicepath + pathModel = "%s/device/model"%devicepath + return ("%s %s"% \ + (readFile(pathVendor).strip(), + readFile(pathModel).strip())).strip() + else: + return "" - def get_os_device_name(self): - """Get device name""" - def getName(device): - prop = getUdevDeviceInfo(name=device) - devicepath = prop.get("DEVPATH","") - if devicepath: - if not devicepath.startswith("/sys"): - devicepath = pathJoin("/sys",devicepath) - pathVendor = "%s/device/vendor"%devicepath - pathModel = "%s/device/model"%devicepath - return ("%s %s"% \ - (readFile(pathVendor).strip(), - readFile(pathModel).strip())).strip() - else: - return "" - return map(getName, + def get(self): + return map(self.getName, self.Get('os_device_dev')) - def get_os_disk_dev(self): - """Get list of partition devices""" - def selfOrPartition(devpath): - """Return self device or partitions if it has them""" - # search partition in device - # get devices in sysfs which startswith devname - partitions = \ - filter(lambda x:x.startswith(path.basename(devpath)), - listDirectory(devpath)) - # if partition found then return them or partition on them - if partitions: - return filter(lambda x:x, - map(lambda x:selfOrPartition(path.join(devpath,x)), - partitions)) - else: - return devpath +############################################# +# Disk variables +############################################# +class VariableOsDiskData(ReadonlyVariable): + """ + Information about current system partition and mounts + """ + type = "table" + source = ['os_disk_dev', + 'os_disk_uuid', + 'os_disk_name', + 'os_disk_size', + 'os_disk_part', + 'os_disk_format', + 'os_disk_type', + 'os_disk_parent', + 'os_disk_id', + 'os_disk_grub'] + +class VariableOsDiskDev(ReadonlyVariable,DeviceHelper): + """ + List of available partition devices + """ + type = "list" + + def selfOrPartition(self,devpath): + """Return self device or partitions if it has them""" + # search partition in device + # get devices in sysfs which startswith devname + partitions = \ + filter(lambda x:x.startswith(path.basename(devpath)), + listDirectory(devpath)) + # if partition found then return them or partition on them + if partitions: + return filter(lambda x:x, + map(lambda x:self.selfOrPartition(path.join(devpath,x)), + partitions)) + else: + return devpath - # get disks from sys block which not contains partitions + def get(self): return list(sorted( filter(lambda x:x, map(lambda x:getUdevDeviceInfo(x).get('DEVNAME',''), - reduce(lambda x,y:x+ ([y] if type(y) == str else y), - map(lambda x:selfOrPartition( + reduce(lambda x,y:x+([y] if type(y) == str else y), + map(lambda x:self.selfOrPartition( path.join(self.sysBlockPath,x)), - filter(self.rePassDevice.search, - listDirectory(self.sysBlockPath))),[]))))) + self.getDeviceFromSysPath()),[]))))) - def mapUdevProperty(self,var,prop,default): - """Get each element from var through udev [prop]""" - return map(lambda x:getUdevDeviceInfo(name=x).get(prop,default), - self.Get(var)) +class VariableOsDiskMount(ReadonlyVariable,DeviceHelper): + """ + List mounted points for current operation system + """ + type = "list" - def get_os_disk_uuid(self): - """Get disk uuid""" - return self.mapUdevProperty('os_disk_dev','ID_FS_UUID','') + def get(self): + disk_hash = self.Get('os_disk_dev') + fstab = FStab('/etc/fstab') + rootdev = self.Get('os_root_dev') + return map(lambda x: '/' if x == rootdev else fstab.getBy(eq=x) or "", + sorted(self.Get('os_disk_dev'), + key=self.separateDevice)) - def get_os_disk_name(self): - """Get disk label""" - return self.mapUdevProperty('os_disk_dev','ID_FS_LABEL','') +class VariableOsDiskContent(ReadonlyVariable): + """ + Partition content + """ + type = "list" - def get_os_disk_part(self): - """Get type of partition""" - return map(lambda x:getPartitionType(getUdevDeviceInfo(name=x)), + def get(self): + """ + TODO: need to write + """ + return map(lambda x:"", self.Get('os_disk_dev')) - def get_os_disk_id(self): - """Get disk id""" - mapTypeUUID = {'ebd0a0a2-b9e5-4433-87c0-68b6b72699c7':'0700', - '0657fd6d-a4ab-43c4-84e5-0933c84b4f4f':'8200', - 'a19d880f-05fc-4d3b-a006-743f0f84911e':'FD00', - '21686148-6449-6e6f-744e-656564454649':'EF02'} - return map(lambda x:mapTypeUUID.get(x,x), - map(lambda x:x.rpartition("x")[2], - self.mapUdevProperty('os_disk_dev','ID_PART_ENTRY_TYPE',''))) +class VariableOsDiskFormat(ReadonlyVariable): + """ + Filesystem on device partitions + """ + type = "list" - def get_os_disk_format(self): + def get(self): """Get current disk file system""" fstab = FStab('/etc/fstab') def getFormat(device): @@ -416,15 +278,13 @@ class InstallDisk(Variables): return map(getFormat, self.Get('os_disk_dev')) - def get_os_disk_options(self): - """Get current disk file system""" - fstab = FStab('/etc/fstab') - def getFormat(device): - return fstab.getBy(what=fstab.OPTS,eq=device) - return map(getFormat, - self.Get('os_disk_dev')) +class VariableOsDiskType(ReadonlyVariable): + """ + List type (lvm,raid,partition,disk) + """ + type = "list" - def get_os_disk_type(self): + def get(self): """Get partition scheme""" types = map(lambda x:(x,getDeviceType(name=x)), self.Get('os_disk_dev')) @@ -456,13 +316,51 @@ class InstallDisk(Variables): map(forMember, types)) - def get_os_disk_parent(self): +class VariableOsDiskUuid(ReadonlyVariable,DeviceHelper): + """ + List uudi for partition devices + """ + + type = "list" + + def get(self): + return self.mapUdevProperty('os_disk_dev','ID_FS_UUID','') + +class VariableOsDiskParent(ReadonlyVariable): + """ + List parent deivces for partition + """ + type = "list" + + def get(self): """Get disk parent""" return map(getPartitionDevice, map(lambda x:getUdevDeviceInfo(name=x).get('DEVPATH',''), self.Get('os_disk_dev'))) - def get_os_disk_grub(self): +class VariableOsDiskId(ReadonlyVariable,DeviceHelper): + """ + Partition's system id + """ + type = "list" + + def get(self): + """Get disk id""" + mapTypeUUID = {'ebd0a0a2-b9e5-4433-87c0-68b6b72699c7':'0700', + '0657fd6d-a4ab-43c4-84e5-0933c84b4f4f':'8200', + 'a19d880f-05fc-4d3b-a006-743f0f84911e':'FD00', + '21686148-6449-6e6f-744e-656564454649':'EF02'} + return map(lambda x:mapTypeUUID.get(x,x), + map(lambda x:x.rpartition("x")[2], + self.mapUdevProperty('os_disk_dev','ID_PART_ENTRY_TYPE',''))) + +class VariableOsDiskGrub(ReadonlyVariable): + """ + List grub id for partition devices + """ + type = "list" + + def get(self): """Get disk grub map""" devicesMap = dict(zip(self.Get('os_device_dev'), self.Get('os_device_map'))) @@ -478,220 +376,119 @@ class InstallDisk(Variables): zip(self.Get('os_disk_dev'), self.Get('os_disk_parent'))) - def get_os_disk_size(self): +class VariableOsDiskPart(ReadonlyVariable): + """ + Type of partition devices + If msdos then(primary, extended or logical) + If gpt then gpt + """ + type = "list" + + def get(self): + return map(lambda x:getPartitionType(getUdevDeviceInfo(name=x)), + self.Get('os_disk_dev')) + +class VariableOsDiskSize(ReadonlyVariable): + """ + Partition size + """ + type = "list" + + def get(self): """Get disk size""" - def debug(x): - print x - return x return map(lambda x:getPartitionSize(name=x), self.Get('os_disk_dev')) - def get_os_disk_mount(self): - """List mounted points for current operation system""" - disk_hash = self.Get('os_disk_dev') +class VariableOsDiskName(ReadonlyVariable,DeviceHelper): + """ + Label of partitions + """ + type = "list" + + def get(self): + """Get disk label""" + return self.mapUdevProperty('os_disk_dev','ID_FS_LABEL','') + +class VariableOsDiskOptions(ReadonlyVariable): + """ + List mount options + """ + type = "list" + + def get(self): fstab = FStab('/etc/fstab') - rootdev = self.Get('os_root_dev') - return map(lambda x: '/' if x == rootdev else fstab.getBy(eq=x) or "", - sorted(self.Get('os_disk_dev'), - key=self.separateDevice)) + def getFormat(device): + return fstab.getBy(what=fstab.OPTS,eq=device) + return map(getFormat, + self.Get('os_disk_dev')) - def get_os_bind_path(self): - """Get source bind path""" +################################################ +# Bind mount points +################################################ +class VariableOsBindData(ReadonlyVariable): + """ + Table of bind mount points + """ + type = "table" + source = ['os_bind_path', + 'os_bind_mountpoint'] + +class VariableOsBindPath(ReadonlyVariable): + """ + List source bind path + """ + type = "list" + + def get(self): fstab = FStab('/etc/fstab') return fstab.getBy(what=fstab.NAME,where=fstab.OPTS, _in="bind",allentry=True) - def get_os_bind_mountpoint(self): - """Get destination bind path""" +class VariableOsBindMountpoint(ReadonlyVariable): + """ + Mountpoints for directories bind + """ + type = "list" + + def get(self): fstab = FStab('/etc/fstab') return fstab.getBy(what=fstab.DIR,where=fstab.OPTS, _in="bind",allentry=True) - def get_os_location_source(self): +###################################################################### +# Userselect partion parameters +###################################################################### +class VariableOsLocationData(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"] + +class VariableOsLocationSource(Variable): + """ + Source disk or directory + """ + type = "choiceedit-list" + label = _("Disk or directory") + + def get(self): return self.Get('os_disk_dev')+self.Get('os_bind_path') - def get_os_location_dest(self): - installFrom = self.Get('os_install_dev_from') - def installMountPoint(info): - dev,mount = info - if self.Get('cl_action') == 'system': - if dev == installFrom: - return "/" - elif mount == "/": - return "" - return mount - return map(installMountPoint, - zip(self.Get('os_disk_dev'), - self.Get('os_disk_mount')))+\ - self.Get('os_bind_mountpoint') - - def get_os_location_format(self): - mount = self.Get("os_location_dest") - source = self.Get("os_location_source") - value = [""]*len(source) - return map(self.default_os_location_format(), - zip(source,mount,value)) - - def get_os_location_perform_format(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.default_os_location_perform_format(), - zip(source,mount,fs,value)) - - def get_os_install_bind_mountpoint(self): - """Get install bind destination""" - return map(lambda x:x[1], - filter(lambda x:not x[0].startswith('/dev/') and x[1], - zip(self.Get('os_location_source'), - self.Get('os_location_dest')))) - - def get_os_install_bind_path(self): - """Get install bind source""" - return map(lambda x:x[0], - filter(lambda x:not x[0].startswith('/dev/') and x[1], - zip(self.Get('os_location_source'), - self.Get('os_location_dest')))) - - def get_os_install_disk_dev(self): - """Get installation disks""" - return map(lambda x:x[0], - filter(lambda x:x[0].startswith('/dev/') and x[1], - zip(self.Get('os_location_source'), - self.Get('os_location_dest')))) - - def get_os_install_disk_mount(self): - """Get install disk dest""" - return map(lambda x:x[1], - filter(lambda x:x[0].startswith('/dev/') and x[1], - zip(self.Get('os_location_source'), - self.Get('os_location_dest')))) - - def get_os_install_disk_format(self): - """Get install disk filesystem""" - return map(lambda x:x[2], - filter(lambda x:x[0].startswith('/dev/') and x[1], - zip(self.Get('os_location_source'), - self.Get('os_location_dest'), - self.Get('os_location_format')))) - - def get_os_install_disk_perform_format(self): - """Get install disk perform format""" - return map(lambda x:x[2], - filter(lambda x:x[0].startswith('/dev/') and x[1], - zip(self.Get('os_location_source'), - self.Get('os_location_dest'), - self.Get('os_location_perform_format')))) - - def get_os_install_disk_id(self): - """List id for partition after installation""" - diskId = dict(zip(self.Get('os_disk_dev'), - self.Get('os_disk_id'))) - def getIdByFS(fs,parttable,oldid): - if parttable == "gpt": - return PartitionDistributive.formatIdGpt.get(fs,oldid) - elif parttable in ("primary","extended","logical"): - return PartitionDistributive.formatId.get(fs,oldid) - return oldid - return map(lambda x:getIdByFS(x[0], - x[1], diskId.get(x[2],'')), - zip(self.Get('os_install_disk_format'), - self.Get('os_install_disk_part'), - self.Get('os_install_disk_dev'))) - - def get_os_install_disk_uuid(self): - """Install disk UUID""" - diskDev = self.Get('os_install_disk_dev') - hashUUID = getUUIDDict(revers=True) - return map(lambda x:hashUUID.get(x,"")[5:],diskDev) - - def get_os_install_disk_use(self): - """Get real id (by cl_uuid_set) device""" - if self.Get('cl_uuid_set') == "on": - return map(lambda x:"UUID=%s"%x[0] if x[0] else x[1], - zip(self.Get('os_install_disk_uuid'), - self.Get('os_install_disk_dev'))) - else: - return self.Get('os_install_disk_dev') - - def get_os_install_disk_name(self): - """Get new labels for disks""" - diskLabel = dict(zip(self.Get('os_disk_dev'), - self.Get('os_disk_name'))) - def changeLabel(info): - dev,mount = info - if mount == '/': - return "%s-%s"%(self.Get('os_install_linux_shortname'), - self.Get('os_install_linux_ver')) - else: - return diskLabel.get(dev,'') - return map(changeLabel, - zip(self.Get('os_install_disk_dev'), - self.Get('os_install_disk_mount'))) - - def get_os_install_disk_size(self): - """Get new size for disks""" - diskSize = dict(zip(self.Get('os_disk_dev'), - self.Get('os_disk_size'))) - return map(lambda x:diskSize.get(x,''), - self.Get('os_install_disk_dev')) - - def get_os_install_disk_type(self): - """Get new disks sceheme""" - diskType = dict(zip(self.Get('os_disk_dev'), - self.Get('os_disk_type'))) - return map(lambda x:diskType.get(x,''), - self.Get('os_install_disk_dev')) - - def get_os_install_disk_part(self): - """Get new type partitions""" - diskPart = dict(zip(self.Get('os_disk_dev'), - self.Get('os_disk_part'))) - return map(lambda x:diskPart.get(x,''), - self.Get('os_install_disk_dev')) - - def get_os_install_disk_parent(self): - """Get parent for install disk""" - diskParent = dict(zip(self.Get('os_disk_dev'), - self.Get('os_disk_parent'))) - return map(lambda x:diskParent.get(x,''), - self.Get('os_install_disk_dev')) - - def get_os_install_disk_options(self): - """TODO: get real options""" - diskOpts = dict(zip(self.Get('os_disk_dev'), - self.Get('os_disk_options'))) - return map(lambda x:diskOpts.get(x,''), - self.Get('os_install_disk_dev')) - - def get_os_install_root_type(self): - """Type of device for install""" - rootdev = self.Get('os_install_root_dev') - devicetype = getPartitionDevice( - getUdevDeviceInfo(name=rootdev).get('DEVPATH','')) - devicetype = map(lambda x: x[1], - filter(lambda x:x[0] == devicetype, - zip(self.Get('os_device_dev'), - self.Get('os_device_type')))) - if devicetype: - return devicetype[0] - else: - return self.Get('os_root_type') - - def get_os_install_root_dev(self): - """Get install root device""" - rootDevs = dict(zip(self.Get('os_install_disk_mount'), - self.Get('os_install_disk_dev'))) - return rootDevs.get('/','') - - def choice_os_location_source(self): + def choice(self): return self.Get('os_disk_dev') - def choice_os_location_dest(self): - return ['/','/boot','/var/calculate','/home','/usr','/var','/tmp','swap'] - - def check_os_location_source(self,value): + def check(self,value): """Check set location source""" disks = filter(lambda x:x.startswith('/dev/'),value) ########################### @@ -713,7 +510,39 @@ class InstallDisk(Variables): if dupDevices: raise VariableError(_("Device '%s' is used twice")%dupDevices[0]) - def check_os_location_dest(self,value): +class VariableOsLocationDest(Variable): + """ + Desination directory of install disk data + """ + type = "choiceedit-list" + lable = _("Mount point") + + def get(self): + installFrom = self.Get('os_install_dev_from') + def installMountPoint(info): + dev,mount = info + if self.Get('cl_action') == 'system': + if dev == installFrom: + return "/" + elif mount == "/": + return "" + return mount + return map(installMountPoint, + zip(self.Get('os_disk_dev'), + self.Get('os_disk_mount')))+\ + self.Get('os_bind_mountpoint') + + def set(self,value): + """Add abilitiy not specify root""" + if len(value) == 1 and value[0] == "": + return ["/"] + else: + return value + + def choice(self): + return ['/','/boot','/var/calculate','/home','/usr','/var','/tmp','swap'] + + def check(self,value): """Check set location source""" ################################ # check of root device specifing @@ -823,10 +652,21 @@ class InstallDisk(Variables): typepart=checkType.upper(), part=memberData[0][0])) - def choice_os_location_format(self): +class VariableOsLocationFormat(Variable): + type = "choiceedit-list" + 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)) + + def choice(self): return self.Get('os_format_type') - def default_os_location_format(self): + def defaultFormat(self): """Describe default value for filesystem""" diskFormat = dict(zip(self.Get('os_disk_dev'), (self.Get('os_disk_format')))) @@ -852,20 +692,45 @@ class InstallDisk(Variables): return fs return wrap - def set_os_location_format(self,value): + def set(self,value): mount = self.Get("os_location_dest") source = self.Get("os_location_source") - return map(self.default_os_location_format(), + return map(self.defaultFormat(), zip(source,mount,value)) - def set_os_location_dest(self,value): - """Add abilitiy not specify root""" - if len(value) == 1 and value[0] == "": - return ["/"] - else: - return value + def check(self,value): + osInstallRootType = self.Get('os_install_root_type') + devMpFs = zip(self.Get('os_location_source'), + self.Get('os_location_dest'),value) + for dev,mp,fs in devMpFs: + # check compatible fs for mount point only root dirs + if dev.startswith('/dev/') and mp and (mp.count('/') == 1 or + mp == '/var/calculate'): + if not FileSystemManager.checkFSForType(fs, + osInstallRootType): + raise VariableError( + _("File system for '%(mp)s' should not be '%(opt)s'") + %{'mp':mp, 'opt':fs}+" "+ + _("for {typedisk} installation").format( + typedisk=osInstallRootType)) + if mp == "swap" and fs != "swap": + raise VariableError( + _("Swap partition {dev} must be formatted as swap").format( + dev=dev)) + +class VariableOsLocationPerformFormat(Variable): + type = "bool-list" + 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)) - def check_os_location_perform_format(self,value): + def check(self,value): """Check perform format Check what format will perform for need partition. @@ -907,7 +772,7 @@ class InstallDisk(Variables): raise VariableError( _("Bind mount points should not be formatted")) - def default_os_location_perform_format(self): + def defaultPerformFormat(self): diskFormat = dict(zip(self.Get('os_disk_dev'), (self.Get('os_disk_format')))) def wrap(info): @@ -920,38 +785,266 @@ class InstallDisk(Variables): return isformat return wrap - def set_os_location_perform_format(self,value): + def set(self,value): """Default values for perform format""" DEV,MP,FS,FORMAT = 0,1,2,3 info = zip(self.Get('os_location_source'), self.Get('os_location_dest'), self.Get('os_location_format'), value) - test = map(self.default_os_location_perform_format(), + return map(self.defaultPerformFormat(), info) - return test - def check_os_location_format(self,value): - osInstallRootType = self.Get('os_install_root_type') - devMpFs = zip(self.Get('os_location_source'), - self.Get('os_location_dest'),value) - for dev,mp,fs in devMpFs: - # check compatible fs for mount point only root dirs - if dev.startswith('/dev/') and mp and (mp.count('/') == 1 or - mp == '/var/calculate'): - if not FileSystemManager.checkFSForType(fs, - osInstallRootType): - raise VariableError( - _("File system for '%(mp)s' should not be '%(opt)s'") - %{'mp':mp, 'opt':fs}+" "+ - _("for {typedisk} installation").format( - typedisk=osInstallRootType)) - if mp == "swap" and fs != "swap": - raise VariableError( - _("Swap partition {dev} must be formatted as swap").format( - dev=dev)) +class VariableClUuidSet(Variable): + """ + Use or not UUID for /etc/fstab + """ + type = "bool" + label = _("Use UUID") + opt = ["--uuid"] + help = _("use UUID") + value = "on" + +############################################################# +# Install disk parameters +############################################################# + +class VariableOsInstallDiskData(ReadonlyVariable): + """ + Table of install disk params + """ + type = "table" + source = ["os_install_disk_dev", + "os_install_disk_mount", + "os_install_disk_format", + "os_install_disk_perform_format", + "os_install_disk_options", + "os_install_disk_id", + "os_install_disk_uuid", + "os_install_disk_use", + "os_install_disk_name", + "os_install_disk_size", + "os_install_disk_type", + "os_install_disk_part", + "os_install_disk_parent"] + +class VariableOsInstallDiskDev(ReadonlyVariable): + """ + Disks for installation + """ + type = "list" + + def get(self): + return map(lambda x:x[0], + filter(lambda x:x[0].startswith('/dev/') and x[1], + zip(self.Get('os_location_source'), + self.Get('os_location_dest')))) + +class VariableOsInstallDiskUuid(ReadonlyVariable): + """ + Uudi for install + """ + type = "list" - def get_os_install_mbr(self): + def get(self): + diskDev = self.Get('os_install_disk_dev') + hashUUID = getUUIDDict(revers=True) + return map(lambda x:hashUUID.get(x,"")[5:],diskDev) + +class VariableOsInstallDiskMount(ReadonlyVariable): + """ + List mounted points for installed system + """ + type = "list" + + def get(self): + """Get install disk dest""" + return map(lambda x:x[1], + filter(lambda x:x[0].startswith('/dev/') and x[1], + zip(self.Get('os_location_source'), + self.Get('os_location_dest')))) + +class VariableOsInstallDiskUse(ReadonlyVariable): + """ + /dev/sd or UUID= list (by cl_uuid_set) + """ + type = "list" + + def get(self): + """Get real id (by cl_uuid_set) device""" + if self.Get('cl_uuid_set') == "on": + return map(lambda x:"UUID=%s"%x[0] if x[0] else x[1], + zip(self.Get('os_install_disk_uuid'), + self.Get('os_install_disk_dev'))) + else: + return self.Get('os_install_disk_dev') + +class VariableOsInstallDiskOptions(ReadonlyVariable): + """ + List mount options of installed os + """ + type = "list" + + def get(self): + """TODO: get real options""" + diskOpts = dict(zip(self.Get('os_disk_dev'), + self.Get('os_disk_options'))) + return map(lambda x:diskOpts.get(x,''), + self.Get('os_install_disk_dev')) + +class VariableOsInstallDiskFormat(ReadonlyVariable): + """ + Install list filesystem for partition devices + """ + type = "choice-list" + + def get(self): + return map(lambda x:x[2], + filter(lambda x:x[0].startswith('/dev/') and x[1], + zip(self.Get('os_location_source'), + self.Get('os_location_dest'), + self.Get('os_location_format')))) + +class VariableOsInstallDiskPerformFormat(ReadonlyVariable): + """ + List need for format + """ + type = "bool-list" + + def get(self): + return map(lambda x:x[2], + filter(lambda x:x[0].startswith('/dev/') and x[1], + zip(self.Get('os_location_source'), + self.Get('os_location_dest'), + self.Get('os_location_perform_format')))) + +class VariableOsInstallDiskId(ReadonlyVariable): + """ + Install partition's system id + """ + type = "list" + + def get(self): + diskId = dict(zip(self.Get('os_disk_dev'), + self.Get('os_disk_id'))) + def getIdByFS(fs,parttable,oldid): + if parttable == "gpt": + return PartitionDistributive.formatIdGpt.get(fs,oldid) + elif parttable in ("primary","extended","logical"): + return PartitionDistributive.formatId.get(fs,oldid) + return oldid + return map(lambda x:getIdByFS(x[0], + x[1], diskId.get(x[2],'')), + zip(self.Get('os_install_disk_format'), + self.Get('os_install_disk_part'), + self.Get('os_install_disk_dev'))) + +class VariableOsInstallDiskName(Variable): + """ + New labels for disk + """ + type = "list" + def get(self): + diskLabel = dict(zip(self.Get('os_disk_dev'), + self.Get('os_disk_name'))) + def changeLabel(info): + dev,mount = info + if mount == '/': + return "%s-%s"%(self.Get('os_install_linux_shortname'), + self.Get('os_install_linux_ver')) + else: + return diskLabel.get(dev,'') + return map(changeLabel, + zip(self.Get('os_install_disk_dev'), + self.Get('os_install_disk_mount'))) + +class VariableOsInstallDiskSize(ReadonlyVariable): + """ + New partition sizes (for feature change partition) + """ + type = "list" + + def get(self): + diskSize = dict(zip(self.Get('os_disk_dev'), + self.Get('os_disk_size'))) + return map(lambda x:diskSize.get(x,''), + self.Get('os_install_disk_dev')) + +class VariableOsInstallDiskType(ReadonlyVariable): + """ + New partition scheme (for feature change partition) + """ + type = "list" + + def get(self): + diskType = dict(zip(self.Get('os_disk_dev'), + self.Get('os_disk_type'))) + return map(lambda x:diskType.get(x,''), + self.Get('os_install_disk_dev')) + +class VariableOsInstallDiskParent(ReadonlyVariable): + """ + Partition parent devices using for install + """ + type = "list" + def get(self): + diskParent = dict(zip(self.Get('os_disk_dev'), + self.Get('os_disk_parent'))) + return map(lambda x:diskParent.get(x,''), + self.Get('os_install_disk_dev')) + +class VariableOsInstallDiskPart(ReadonlyVariable): + """ + Get new type partitions using for install + """ + type = "list" + def get(self): + diskPart = dict(zip(self.Get('os_disk_dev'), + self.Get('os_disk_part'))) + return map(lambda x:diskPart.get(x,''), + self.Get('os_install_disk_dev')) + +class VariableOsInstallBindData(ReadonlyVariable): + """ + Table of install bind mount points + """ + type = "table" + source = ['os_install_bind_path', + 'os_install_bind_mountpoint'] + +class VariableOsInstallBindPath(ReadonlyVariable): + """ + Install directories for bind + """ + type = "list" + + def get(self): + """Get install bind source""" + return map(lambda x:x[0], + filter(lambda x:not x[0].startswith('/dev/') and x[1], + zip(self.Get('os_location_source'), + self.Get('os_location_dest')))) + +class VariableOsInstallBindMountpoint(ReadonlyVariable): + """ + Mountpoint for install directories bind + """ + def get(self): + return map(lambda x:x[1], + filter(lambda x:not x[0].startswith('/dev/') and x[1], + zip(self.Get('os_location_source'), + self.Get('os_location_dest')))) + +class VariableOsInstallMbr(Variable): + """ + Disks for boot mbr + """ + type = "list" + opt = ["--mbr"] + metavalue = "MBR" + label = _("Disk for install") + + def get(self): """Get default Master boot record install TODO: add get list of devices if install on RAID @@ -984,6 +1077,51 @@ class InstallDisk(Variables): return [self.Get('os_device_dev')[0]] return [] + # information about mount points for fstab + os_install_fstab_mount_conf = {} + + # information about swap for fstab + os_install_fstab_swap_conf = {} + +class VariableOsInstallRootType(Variable): + """ + Type of installation + """ + label = _("Installation type") + opt = ["--type"] + metavalue = "DISKTYPE" + help = _("device type for the system bound for install") + type = "choice" + + def get(self): + rootdev = self.Get('os_install_root_dev') + devicetype = getPartitionDevice( + getUdevDeviceInfo(name=rootdev).get('DEVPATH','')) + devicetype = map(lambda x: x[1], + filter(lambda x:x[0] == devicetype, + zip(self.Get('os_device_dev'), + self.Get('os_device_type')))) + if devicetype: + return devicetype[0] + else: + return self.Get('os_root_type') + + def choice(self): + return [("hdd",_("Hard disk")), + ("flash",_("USB Flash")), + ("usb-hdd",_("USB Hard Disk"))] + +class VariableOsInstallRootDev(ReadonlyVariable): + def get(self): + """Get install root device""" + rootDevs = dict(zip(self.Get('os_install_disk_mount'), + self.Get('os_install_disk_dev'))) + return rootDevs.get('/','') + +class VariableOsInstallFstabMountConf(ReadonlyVariable,DeviceHelper): + """ + FStab.conf contains for mount and bind points + """ def _commentFstab(self,s,mp,dev): """Generate comment for /etc/fstab each line""" if s.startswith("UUID"): @@ -991,8 +1129,7 @@ class InstallDisk(Variables): else: return s - def get_os_install_fstab_mount_conf(self): - """Information about mount points for fstab""" + def get(self): devicesForFstab = sorted(filter(lambda x:x[1] != "" and x[1] != "swap", zip(self.Get('os_install_disk_use'), self.Get('os_install_disk_mount'), @@ -1019,8 +1156,11 @@ class InstallDisk(Variables): %(x[0],x[1]), bindData)) return "\n".join(filter(lambda x: x, [rootLine,otherLines,bindLines])) - def get_os_install_fstab_swap_conf(self): - """Information about swap for fstab""" +class VariableOsInstallFstabSwapConf(VariableOsInstallFstabMountConf): + """ + FStab.conf contains swap partition + """ + def get(self): return "\n".join(map(lambda x: "%s\tnone\tswap\tsw\t0 0"%\ self._commentFstab(x[0],"swap",x[2]), filter(lambda x: x[1] == "swap", diff --git a/install/variables/distr.py b/install/variables/distr.py index d95546a..9a670ea 100644 --- a/install/variables/distr.py +++ b/install/variables/distr.py @@ -19,179 +19,16 @@ import sys from os import path import re import operator -from calculate.lib.datavars import Variables,VariableError +from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable from calculate.lib.utils.common import getSupportArch,getTupleVersion from calculate.lib.utils.files import readLinesFile, listDirectory -from calculate.lib.variables import Linux +from calculate.lib.variables.linux import Linux from calculate.install.cl_distr import Distributive from calculate.lib.cl_lang import setLocalTranslate setLocalTranslate('cl_install',sys.modules[__name__]) -class Distro(Variables): - vars = ["cl_image","cl_image_path","cl_image_arch_machine", - "cl_image_linux_shortname","cl_image_linux_ver", - "cl_image_linux_build","cl_image_filename"] - # system image for installation - cl_image = {} - - cl_image_filename = {'mode':'w', - 'type':'choiceedit', - 'opt':['--iso'], - 'label':_("Installation image"), - 'help':_("ISO image for installation")} - - # filter by architecture - cl_image_arch_machine = {'mode':'w', - 'type':'choice', - 'opt':['--march'], - 'label':_("Preferred processor architecture"), - 'help':_("select the processor architecture")} - - # filter by shortname - cl_image_linux_shortname = {'mode':'w', - 'type':'choice', - 'opt':['--os','-s'], - 'label':_("Distributive"), - 'help':_("select the operation system")} - - # filter by version - cl_image_linux_ver = {'mode':'w', - 'type':'string', - 'label':_("Version"), - 'value':"", - 'help':_("select the operation system by version")} - - # filter by build - cl_image_linux_build = {'mode':'w', - 'type':'string', - 'label':_("Build"), - 'value':"", - 'help':_("select the operation system by build")} - - # path which contains images - cl_image_path = {'type':'list'} - - def get_cl_image_arch_machine(self): - return self.Get('os_arch_machine') - - def choice_cl_image_arch_machine(self): - return self.marches + ["auto"] - - def set_cl_image_arch_machine(self,march): - if march == "auto": - march = getSupportArch()[-1] - return march - - def get_cl_image_linux_shortname(self): - return self.Get('os_linux_shortname') - - def choice_cl_image_linux_shortname(self): - return Linux.dictLinuxName.keys() - - def get_cl_image_path(self): - """Get available images search path""" - # if current distributive is live - if self.Get('os_root_type') == "livecd": - # if builder from flash then this source path '/mnt/flash' - # may be this path will be '/mnt/builder' for install - # modified system - if self.Get('os_scratch') == "on" and path.exists('/mnt/flash'): - livedistr = ['/mnt/flash'] - # if system boot with kernel param 'docache' - elif path.exists('/mnt/squash'): - livedistr = ['/mnt/livecd'] - # standard livecd - else: - livedistr = ['/mnt/cdrom'] - else: - livedistr = [] - # search all partition for source installation distributive - rootDev = self.Get('os_install_root_dev') - livedistr += \ - map(lambda x:x[0], - filter(lambda x:" live" in x[1] and x[0] != rootDev, - zip(self.Get('os_disk_dev'), - self.Get('os_disk_content')))) - # add to standard path - return filter(path.exists, - ['/var/calculate/remote/linux', - '/var/calculate/linux'] + livedistr) - - def getImage(self,scratch,rootType,imagePath,march=None, - shortName=None,linuxVer=None,linuxBuild=None): - """Get image by parameters""" - # exclude directory distributive for flash and scratch install - if scratch == "on" or rootType == "flash": - discardType = ["dir"] - else: - discardType = [] - return self.getBestDistributive(imagePath, - march=march, - shortname=shortName, - discardType=discardType, - version=linuxVer, - build=linuxBuild) - - def get_cl_image(self): - """Get image file from distributive repository""" - if self.Get('cl_action') != 'system': - return Distributive.fromFile('/') - filename = self.Get('cl_image_filename') - if filename: - filename = Distributive.fromFile(filename) - return filename - - def human_image_name(self,distroinfo,filepath): - distroinfo['name'] = distroinfo['name'].upper() - return "{name} {march} {build} ({filepath})".format( - filepath=filepath,**distroinfo) - - def choice_cl_image_filename(self): - scratch = self.Get('os_install_scratch') - rootType = self.Get('os_install_root_type') - imagePath = self.Get('cl_image_path') - march = self.Get('cl_image_arch_machine') - shortName = self.Get('cl_image_linux_shortname') - linuxVer = self.Get('cl_image_linux_ver') - linuxBuild = self.Get('cl_image_linux_build') - if scratch == "on" or rootType == "flash": - discardType = ["dir"] - else: - discardType = [] - distros = self.getAvailableDristibutives(imagePath, - march=march, - shortname=shortName, - discardType=discardType, - version=linuxVer, - build=linuxBuild) - return map(lambda x:(x,self.human_image_name(self._getDistrInfo(x),x)), - distros) - - def get_cl_image_filename(self): - if self.Get('cl_action') != 'system': - return "" - return self.getImage(self.Get('os_install_scratch'), - self.Get('os_install_root_type'), - self.Get('cl_image_path'), - self.Get('cl_image_arch_machine'), - self.Get('cl_image_linux_shortname'), - self.Get('cl_image_linux_ver'), - self.Get('cl_image_linux_build')) - - def human_cl_image(self): - filename = self.Get('cl_image') - if filename: - return filename.getType() - return filename - - def check_cl_image_filename(self,isoimage): - """Set image file""" - imageData = Distributive().getInfo(isoimage) - if not("name" in imageData and imageData.get('build','') and \ - "march" in imageData): - raise VariableError(_("Wrong image file")) - +class DistroRepository(Linux): contentCache = {} marches = ['i686','x86_64'] @@ -226,6 +63,21 @@ class Distro(Variables): distdic["ver"] = "" return distdic + def getImage(self,scratch,rootType,imagePath,march=None, + shortName=None,linuxVer=None,linuxBuild=None): + """Get image by parameters""" + # exclude directory distributive for flash and scratch install + if scratch == "on" or rootType == "flash": + discardType = ["dir"] + else: + discardType = [] + return self.getBestDistributive(imagePath, + march=march, + shortname=shortName, + discardType=discardType, + version=linuxVer, + build=linuxBuild) + def _getAvailableShortnames(self,dirs): """Get available distributives shortnames""" distros = filter(lambda x:x, @@ -253,7 +105,7 @@ class Distro(Variables): version=None,build=None): """Get all distributives by filter""" def systemByName(name): - return Linux.dictNameSystem.get(name.upper(),"") + return self.dictNameSystem.get(name.upper(),"") verCmp, version = self.opcompareByString(version) if version: version = getTupleVersion(version) @@ -377,21 +229,103 @@ class Distro(Variables): (march,hardened),re.S) return self._findLatestFile(dirs,reStage,lambda x:x.groups()[0]) - def choice_cl_image_arch_machine(self): - """Get image arch""" - return ["i686","x86_64"] - def check_cl_image_linux_shortname(self,value): - if self.Get('cl_action') == 'system': - if not self.Get('cl_image'): - if not self.getImage(self.Get('os_install_scratch'), - self.Get('os_install_root_type'), - self.Get('cl_image_path'), - shortName=value): - raise VariableError( - _('Installation image of {0} not found').format(value)) +class VariableClImage(ReadonlyVariable): + """ + System image for installation + """ + def get(self): + """Get image file from distributive repository""" + if self.Get('cl_action') != 'system': + return Distributive.fromFile('/') + filename = self.Get('cl_image_filename') + if filename: + filename = Distributive.fromFile(filename) + return filename + + def humanReadable(self): + filename = self.Get('cl_image') + if filename: + return filename.getType() + return filename - def check_cl_image_arch_machine(self,value): +class VariableClImageFilename(Variable,DistroRepository): + """ + Distributive image filename + """ + type = 'choiceedit' + opt = ['--iso'] + label = _("Installation image") + help = _("ISO image for installation") + + + def get(self): + if self.Get('cl_action') != 'system': + return "" + return self.getImage(self.Get('os_install_scratch'), + self.Get('os_install_root_type'), + self.Get('cl_image_path'), + self.Get('cl_image_arch_machine'), + self.Get('cl_image_linux_shortname'), + self.Get('cl_image_linux_ver'), + self.Get('cl_image_linux_build')) + + def check(self,isoimage): + """Set image file""" + imageData = Distributive().getInfo(isoimage) + if not("name" in imageData and imageData.get('build','') and \ + "march" in imageData): + raise VariableError(_("Wrong image file")) + + def humanImageName(self,distroinfo,filepath): + distroinfo['name'] = distroinfo['name'].upper() + return "{name} {march} {build} ({filepath})".format( + filepath=filepath,**distroinfo) + + def choice(self): + scratch = self.Get('os_install_scratch') + rootType = self.Get('os_install_root_type') + imagePath = self.Get('cl_image_path') + march = self.Get('cl_image_arch_machine') + shortName = self.Get('cl_image_linux_shortname') + linuxVer = self.Get('cl_image_linux_ver') + linuxBuild = self.Get('cl_image_linux_build') + if scratch == "on" or rootType == "flash": + discardType = ["dir"] + else: + discardType = [] + distros = self.getAvailableDristibutives(imagePath, + march=march, + shortname=shortName, + discardType=discardType, + version=linuxVer, + build=linuxBuild) + return map(lambda x:(x,self.humanImageName(self._getDistrInfo(x),x)), + distros) + + +class VariableClImageArchMachine(Variable): + """ + Filter by architecture + """ + type = 'choice' + opt = ['--march'] + label = _("Preferred processor architecture") + help = _("select the processor architecture") + available_arch = ["i686","x86_64"] + + def get(self): + return self.Get('os_arch_machine') + + def set(self,march): + if march == "auto": + march = getSupportArch()[-1] + return march + + def choice(self): + return self.available_arch + ["auto"] + + def check(self,value): if self.Get('cl_action') == 'system': if not self.Get('cl_image'): if not self.getImage(self.Get('os_install_scratch'), @@ -405,7 +339,41 @@ class Distro(Variables): distro=self.Get('cl_image_linux_shortname'), arch=value)) - def check_cl_image_linux_ver(self,value): + +class VariableClImageLinuxShortname(Variable,Linux): + """ + Filter by shortname + """ + type = 'choice' + opt = ['--os','-s'] + label = _("Distributive") + help = _("select the operation system") + + def get(self): + return self.Get('os_linux_shortname') + + def choice(self): + return self.dictLinuxName.keys() + + def check(self,value): + if self.Get('cl_action') == 'system': + if not self.Get('cl_image'): + if not self.getImage(self.Get('os_install_scratch'), + self.Get('os_install_root_type'), + self.Get('cl_image_path'), + shortName=value): + raise VariableError( + _('Installation image of {0} not found').format(value)) + +class VariableClImageLinuxVer(Variable): + """ + Filter by version + """ + label = _("Version") + value = "" + help = _("select the operation system by version") + + def check(self,value): if self.Get('cl_action') == 'system': if value and not self.Get('cl_image'): if not self.getImage(self.Get('os_install_scratch'), @@ -422,9 +390,51 @@ class Distro(Variables): self.Get('cl_image_arch_machine')), ver=value)) - def check_cl_image_linux_build(self,value): +class VariableClImageLinuxBuild(Variable): + """ + Filter by build + """ + label = _("Build") + value = "" + help = _("select the operation system by build") + + def check(self,value): if self.Get('cl_action') == 'system': if value and not self.Get('cl_image'): raise VariableError( _('Installation image with build {build} not found').format( build=value)) + +class VariableClImagePath(ReadonlyVariable): + """ + Image search path + """ + type = "list" + + def get(self): + # if current distributive is live + if self.Get('os_root_type') == "livecd": + # if builder from flash then this source path '/mnt/flash' + # may be this path will be '/mnt/builder' for install + # modified system + if self.Get('os_scratch') == "on" and path.exists('/mnt/flash'): + livedistr = ['/mnt/flash'] + # if system boot with kernel param 'docache' + elif path.exists('/mnt/squash'): + livedistr = ['/mnt/livecd'] + # standard livecd + else: + livedistr = ['/mnt/cdrom'] + else: + livedistr = [] + # search all partition for source installation distributive + rootDev = self.Get('os_install_root_dev') + livedistr += \ + map(lambda x:x[0], + filter(lambda x:" live" in x[1] and x[0] != rootDev, + zip(self.Get('os_disk_dev'), + self.Get('os_disk_content')))) + # add to standard path + return filter(path.exists, + ['/var/calculate/remote/linux', + '/var/calculate/linux'] + livedistr) diff --git a/install/variables/kernel.py b/install/variables/kernel.py index b59b98c..2535670 100644 --- a/install/variables/kernel.py +++ b/install/variables/kernel.py @@ -17,7 +17,7 @@ import os import sys from os import path -from calculate.lib.datavars import Variables +from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable from calculate.lib.cl_lang import setLocalTranslate setLocalTranslate('cl_install',sys.modules[__name__]) @@ -25,43 +25,94 @@ setLocalTranslate('cl_install',sys.modules[__name__]) from calculate.lib.utils.files import readLinesFile from calculate.lib.utils.common import getKernelUid -class InstallKernel(Variables): - vars = ["os_install_kernel_scheduler","os_install_kernel_attr", - "os_install_kernel_resume","os_install_kernel","os_install_initrd", - "os_install_initrd_install","os_install_kernel_config", - "os_install_system_map","cl_install_kernel_uid", - "os_install_kernel_cpufreq"] - # install scheduler - os_install_kernel_scheduler = {} - - # install kernel attributes - os_install_kernel_attr = {} - - # install kernel resume - os_install_kernel_resume = {} - - # kernel filename - os_install_kernel = {} - - # optimized initramfs filename - os_install_initrd = {} - - # install initramfs filename - os_install_initrd_install = {} - - # install config kernel filename - os_install_kernel_config = {} - - # install system map filename - os_install_system_map = {} - - # install kernel uid - cl_install_kernel_uid = {} - - os_install_kernel_cpufreq = {} +class VariableOsInstallKernelScheduler(Variable): + """ + Install scheduler opts (cfq,bfq,none,deadline) + """ + def get(self): + """Get scheduler for install root device""" + root_dev = filter(lambda x: x[1] == '/', + zip(self.Get('os_install_disk_parent'), + self.Get('os_install_disk_mount'))) + if root_dev: + pathScheduler = '/sys/block/%s/queue/scheduler'%root_dev + if os.access(pathScheduler,os.R_OK): + res = re.search("\[([^\]]+)\]", + open(pathScheduler).read(),re.S) + if res: + return res.groups()[0] + return "cfq" + + +class VariableOsInstallKernelAttr(Variable): + """ + Install kernel attributes + """ + def get(self): + # on usb-hdd install must be "delay=5" + attr = "" + if self.Get('os_install_root_type') == 'usb-hdd': + attr = " scandelay=5" + if self.Get('os_install_mdadm_set') == 'on': + attr += " domdadm" + if self.Get('os_install_lvm_set') == 'on': + attr += " dolvm" + return attr + +class VariableOsInstallKernelResume(ReadonlyVariable): + """ + Install kernel resume + """ + def get(self): + """install kernel resume parameter""" + for dev, install in zip(self.Get('os_install_disk_use'), + self.Get('os_install_disk_mount')): + if install == "swap": + return "real_resume=%s"%dev + return "" + +class VariableOsInstallKernel(ReadonlyVariable): + """ + Kernel filename + """ + value = "" + +class VariableOsInstallInitrd(ReadonlyVariable): + """ + Optimized initramfs filename + """ + value = "" + +class VariableOsInstallInitrdInstall(ReadonlyVariable): + """ + Install initramfs filename + """ + value = "" + +class VariableOsInstallKernelConfig(ReadonlyVariable): + """ + Install config kernel filename + """ + value = "" + +class VariableOsInstallSystemMap(ReadonlyVariable): + """ + Install system map filename + """ + def get(self): + systemmapfile = self.Get('os_install_kernel').replace('vmlinuz', + 'System.map') + if systemmapfile.startswith('System.map') and path.exists( + path.join(self.Get('cl_chroot_path'),'boot',systemmapfile)): + return systemmapfile + else: + return "" - # value of conf.d/modules freq mod - def get_os_install_kernel_cpufreq(self): +class VariableOsInstallKernelCpufreq(ReadonlyVariable): + """ + Cpufreq modules + """ + def get(self): """Get cpufreq (and other from modules_3= param) from conf.d/modules""" cpufreqmods = map(lambda x:x.partition('=')[2].strip("\n '\""), filter(lambda x:x.startswith('modules_3'), @@ -71,15 +122,10 @@ class InstallKernel(Variables): else: return "" - def get_os_install_kernel_uid(self): +class VariableOsInstallKernelUid(ReadonlyVariable): + """ + Variable install kernel UID + """ + def get(self): return getKernelUid(self.Get('os_install_root_dev')) - def get_os_install_system_map(self): - systemmapfile = self.Get('os_install_kernel').replace('vmlinuz', - 'System.map') - if systemmapfile.startswith('System.map') and path.exists( - path.join(self.Get('cl_chroot_path'),'boot',systemmapfile)): - return systemmapfile - else: - return "" - diff --git a/install/variables/linux.py b/install/variables/linux.py index b27e525..1b90bc1 100644 --- a/install/variables/linux.py +++ b/install/variables/linux.py @@ -17,53 +17,14 @@ import os import sys from os import path -from calculate.lib.datavars import Variables -from calculate.lib.variables import Linux +from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable +from calculate.lib.variables.linux import (Linux,VariableOsLinuxName, + VariableOsLinuxSystem,VariableOsLinuxSubname) from calculate.lib.cl_lang import setLocalTranslate setLocalTranslate('cl_install',sys.modules[__name__]) class InstallLinux(Linux): - vars = ["os_install_linux_ver","os_install_linux_build", - "os_install_linux_subname","os_install_linux_shortname", - "os_install_linux_name","os_install_linux_system", - "os_install_arch_machine"] - # linux version of installation os - os_install_linux_ver = {'mode':'r'} - - # linux build of installation os - os_install_linux_build = {'mode':'r'} - - # subname of installation os - os_install_linux_subname = {'mode':'r'} - - # shortname of installation os - os_install_linux_shortname = {'mode':'r'} - - # name of installation os - os_install_linux_name = {'mode':'r'} - - # installation os system: server or desktop - os_install_linux_system = {} - - # install maching architecture - os_install_arch_machine = {'mode':'r'} - - def get_os_install_linux_system(self): - """Get linux system (server or desktop)""" - shortName = self.Get('os_install_linux_shortname') - return self.dictNameSystem.get(shortName,"") - - def get_os_install_linux_name(self): - """Name of installation os""" - linuxShortName = self.Get("os_install_linux_shortname") - return self.dictLinuxName.get(linuxShortName,"Linux") - - def get_os_install_linux_subname(self): - """Subname of installation os""" - linuxShortName = self.Get("os_install_linux_shortname") - return self.dictLinuxSubName.get(linuxShortName,"") - def __getFromImageOrCurrent(self,field,currentVar): """Get value from install image or current system""" if self.Get('cl_action') == 'system': @@ -76,15 +37,50 @@ class InstallLinux(Linux): else: return self.Get(currentVar) - def get_os_install_linux_shortname(self): - """Shortname of system""" - return self.__getFromImageOrCurrent('name','os_linux_shortname') - - def get_os_install_linux_ver(self): - return self.__getFromImageOrCurrent('ver','os_linux_ver') - - def get_os_install_linux_build(self): - return self.__getFromImageOrCurrent('build','os_linux_build') - - def get_os_install_arch_machine(self): - return self.__getFromImageOrCurrent('march','os_arch_machine') + # variable for get current system info (example: os_linux_shortname) + current_variable = "" + # field of distroinfo (name,ver,build,march and etc) + distroinfo_field = "" + + def get(self): + """Get by distroinfo or current info""" + return self.__getFromImageOrCurrent(self.distroinfo_field, + self.current_variable) + +class VariableOsInstallLinuxShortname(InstallLinux,ReadonlyVariable): + """Shortname of system""" + current_variable = "os_linux_shortname" + distroinfo_field = "name" + +class VariableOsInstallLinuxVer(InstallLinux,ReadonlyVariable): + """Shortname of system""" + current_variable = "os_linux_ver" + distroinfo_field = "ver" + +class VariableOsInstallLinuxBuild(InstallLinux,ReadonlyVariable): + """Shortname of system""" + current_variable = "os_linux_build" + distroinfo_field = "build" + +class VariableOsInstallArchMachine(InstallLinux,ReadonlyVariable): + """Shortname of system""" + current_variable = "os_arch_machine" + distroinfo_field = "march" + +class VariableOsInstallLinuxName(VariableOsLinuxName): + """ + Install distro name + """ + source_variable = "os_install_linux_shortname" + +class VariableOsInstallLinuxSystem(VariableOsLinuxSystem): + """ + Install system name + """ + source_variable = "os_install_linux_shortname" + +class VariableOsInstallLinuxSubname(VariableOsLinuxSubname): + """ + Install subname + """ + source_variable = "os_install_linux_shortname" diff --git a/install/variables/locale.py b/install/variables/locale.py index b378482..18ab481 100644 --- a/install/variables/locale.py +++ b/install/variables/locale.py @@ -17,64 +17,34 @@ import os import sys from os import path -from calculate.lib.datavars import Variables, VariableError -from calculate.lib.variables import Locale +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 calculate.lib.cl_lang import setLocalTranslate setLocalTranslate('cl_install',sys.modules[__name__]) -class InstallLocale(Locale): - vars = ["os_install_linguas", "os_install_locale_consolefont", - "os_install_locale_keymap", "os_install_locale_dumpkeys", - "os_install_locale_locale", "os_install_locale_lang", - "os_install_locale_language", "os_install_locale_xkb", - "os_install_locale_xkbname", "os_install_clock_timezone", - "os_install_clock_type"] - - # LINGUAS value - os_install_linguas = {'mode':'w'} - - # consolefont - os_install_locale_consolefont = {} - - # keymap of locale (used for /etc/conf.d/keymaps) - os_install_locale_keymap = {} - - # dumpkeys_charset for keymap - os_install_locale_dumpkeys = {} - - # locale (at example: ru_RU.UTF-8) - os_install_locale_locale = {} - - # full language (at example: ru_RU) - os_install_locale_lang = {'mode':'w', - 'type':'choice', - 'label':_("Language"), - 'opt':["--lang","-l"]} - - # short language (at example ru) - os_install_locale_language = {} - - # keyboard layout for X server - os_install_locale_xkb = {} - - # keyboard layout name for X server - os_install_locale_xkbname = {} - - # timezone for clock - os_install_clock_timezone = {'mode':'w', - 'type':'choiceedit', - 'label':_("Timezone"), - 'metavalue':"TIMEZONE", - 'opt':["--timezone"]} +class LocaleVariable(ReadonlyVariable,Locale): + """ + Locale variables not using for flash installation + """ + def uncompatible(self): + """ + Network setting up unavailable for flash installation + """ + if self.Get('os_install_root_type') == 'flash': + return \ + _("Locale configuration unavailable for flash installation") + return "" - # type of clock (UTC or local) - os_install_clock_type = {'mode':'w'} +class VariableOsInstallLinguas(LocaleVariable): + """ + Current LINGUAS value + """ + mode = "w" - def get_os_install_linguas(self): - """Current linguas""" + def get(self): def get_linguas(lines): linguas = map(lambda x:x.strip().rpartition('=')[-1].strip('"\''), filter(lambda x: x.startswith("LINGUAS="), @@ -91,38 +61,19 @@ class InstallLocale(Locale): process(*infocommand).readlines() or "").split())) or \ defaultLinguas - def get_os_install_clock_timezone(self): - """Timezone for clock""" - return self.Get('os_clock_timezone') - - def check_os_install_clock_timezone(self,value): - """Check timezone""" - if not value or not path.isfile(path.join( - "/usr/share/zoneinfo",value)): - raise VariableError(_("%s timezone is wrong")%value) - - def get_os_install_clock_type(self): - """type of clock (UTC or local)""" - clockTypeFile = ['/etc/conf.d/clock','/etc/conf.d/hwclock'] - for f in clockTypeFile: - clock = getValueFromConfig(f,"clock") - if clock: - if clock.upper() == 'UTC': - return clock.upper() - elif clock.lower() == 'local': - return clock.lower() - return "local" - - def choice_os_install_clock_type(self): - return ["local","UTC"] - - def get_os_install_locale_consolefont(self): - """consolefont""" +class VariableOsInstallLocaleConsolefont(LocaleVariable): + """ + Consolefont for locale + """ + def get(self): return self.getFieldByKeymap("consolefont", self.Get('os_install_locale_keymap')) - def get_os_install_locale_keymap(self): - """keymap of locale (used for /etc/conf.d/keymaps)""" +class VariableOsInstallLocaleKeymap(LocaleVariable): + """ + Keymap of locale (used for /etc/conf.d/keymaps) + """ + def get(self): # get keymap from boot calculate param (keymap specified # by lang) keymapConfd = '/etc/conf.d/keymaps' @@ -136,8 +87,11 @@ class InstallLocale(Locale): return self.getFieldByLang("keymap", self.Get("os_install_locale_lang")) - def get_os_install_locale_dumpkeys(self): - """dumpkeys charset for keymap""" +class VariableOsInstallLocaleDumpkeys(LocaleVariable): + """ + Dumpkeys_charset for keymap + """ + def get(self): # is specified keymap support by locale hash if self.Get('os_install_locale_keymap') in self.getFields('keymap'): return self.getFieldByKeymap("dumpkeys_charset", @@ -146,37 +100,77 @@ class InstallLocale(Locale): return self.getFieldByLang("dumpkeys_charset", self.Get('os_install_locale_lang')) - def get_os_install_locale_locale(self): +class VariableOsInstallLocaleLocale(LocaleVariable): + """ + Locale (at example: ru_RU.UTF-8) + """ + def get(self): """locale (example: ru_RU.UTF-8)""" return self.Get('os_locale_locale') - def get_os_install_locale_lang(self): +class VariableOsInstallLocaleLang(LocaleVariable): + """ + Full language (at example: ru_RU) + """ + mode = 'w' + type = 'choice' + label = _("Language") + opt = ["--lang","-l"] + + def get(self): """lang (example: ru_RU)""" return self.getLangByField("locale", self.Get('os_install_locale_locale')) - def get_os_install_locale_language(self): - """language (example: ru)""" + def choice(self): + return self.Get('os_lang') + +class VariableOsInstallLocaleLanguage(LocaleVariable): + """ + Short language (at example ru) + """ + def get(self): return self.getFieldByLang("language", self.Get('os_install_locale_lang')) - def get_os_install_locale_xkb(self): - """xkb layouts (example: en,ru)""" + +class VariableOsInstallLocaleXkb(LocaleVariable): + """ + Keyboard layout for X server + """ + def get(self): return self.getFieldByLang("xkblayout", self.Get('os_install_locale_lang')) - def get_os_install_locale_xkbname(self): - """названия используемых раскладок клавиатуры для X""" +class VariableOsInstallLocaleXkbname(LocaleVariable): + """ + Keyboard layout name for X server + """ + def get(self): localeXkb = self.Get("os_install_locale_xkb") if localeXkb: return localeXkb.split("(")[0] return "" - def choice_os_install_locale_lang(self): - """Choice of language""" - return self.Get('os_lang') +class VariableOsInstallClockTimezone(Variable): + """ + Installation timezone for clock + """ + mode = 'w' + type = 'choiceedit' + label = _("Timezone") + metavalue = "TIMEZONE" + opt = ["--timezone"] + + def get(self): + return self.Get('os_clock_timezone') + + def check(self,value): + if not value or not path.isfile(path.join( + "/usr/share/zoneinfo",value)): + raise VariableError(_("%s timezone is wrong")%value) - def choice_os_install_clock_timezone(self): + def choice(self): return ["Etc/GMT-12", "Pacific/Midway", "Pacific/Honolulu", "America/Anchorage", "Canada/Pacific", "America/Tijuana", "America/Phoenix", "America/Denver", "America/Mazatlan", @@ -207,15 +201,27 @@ class InstallLocale(Locale): "Australia/Hobart", "Asia/Magadan", "Asia/Kamchatka", "Pacific/Auckland", "Etc/GMT-13"] - def uncompatible_locale_vars(self): - """ - Network setting up unavailable for flash installation - """ - if self.Get('os_install_root_type') == 'flash': - return \ - _("Locale configuration unavailable for flash installation") - return "" +class VariableOsInstallClockType(Variable): + """ + Type of clock (UTC or local) + """ + mode = 'w' + type = 'choice' + label = _("Clock type") + opt = ["--clocktype"] + metavalue = "CLOCKTYPE" + + def get(self): + """type of clock (UTC or local)""" + clockTypeFile = ['/etc/conf.d/clock','/etc/conf.d/hwclock'] + for f in clockTypeFile: + clock = getValueFromConfig(f,"clock") + if clock: + if clock.upper() == 'UTC': + return clock.upper() + elif clock.lower() == 'local': + return clock.lower() + return "local" - uncompatible_os_install_locale_lang = \ - uncompatible_os_install_clock_timezone = \ - uncompatible_locale_vars + def choice(self): + return ["local","UTC"] diff --git a/install/variables/net.py b/install/variables/net.py index 9ce1331..08fd954 100644 --- a/install/variables/net.py +++ b/install/variables/net.py @@ -18,8 +18,8 @@ import os import sys import re from os import path -from calculate.lib.datavars import Variables,VariableError -from calculate.lib.variables import Net +from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable, \ + Readonly from calculate.lib.cl_lang import setLocalTranslate setLocalTranslate('cl_install',sys.modules[__name__]) @@ -27,203 +27,128 @@ setLocalTranslate('cl_install',sys.modules[__name__]) from calculate.lib.utils.ip import (getInterfaces,getIp,getMask,getMac, cidrToMask,maskToCidr,getIpNet,isDhcpIp,checkIp,checkMask) from calculate.lib.utils.device import lspci +from calculate.lib.utils.files import listDirectory,readLinesFile +from calculate.lib.utils import ip +from calculate.lib.utils.portage import isPkgInstalled + +class NetVariable(Variable): + """ + Network variables not using for flash installation + """ + def uncompatible(self): + """ + Network setting up unavailable for flash installation + """ + if self.Get('os_install_root_type') == 'flash': + return \ + _("Network configuration unavailable for flash installation") + return "" + +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" + +class VariableOsInstallProxy(NetVariable): + """ + Proxy for system + """ + value = "" + +class VariableOsInstallNetInterfaces(NetVariable): + """ + Net interface devices + """ + type = "list" + mode = Readonly + label = _("Interface") + + def get(self): + return getInterfaces() -class InstallNet(Net): - vars = ["os_net_interfaces_info","os_install_net_data", - "os_install_net_hostname","os_install_net_allow", - "os_install_net_interfaces","os_install_net_name", - "os_install_net_mac","os_install_net_ip","os_install_net_network", - "os_install_net_cidr","os_install_net_route_hash", - "os_install_net_mask", - "os_install_net_route_network","os_install_net_route_gw", - "os_install_net_route_dev","os_install_net_route_src", - "os_install_net_route","os_install_net_nmroute", - "os_install_net_dns","os_install_net_conf", - "os_install_net_settings","os_install_net_dhcp_set", - "os_install_net_dns_search","os_install_net_domain", - "os_install_net_fqdn"] - # inforamation about net interfaces + +class VariableOsNetInterfacesInfo(NetVariable): + """ + Inforamation about net interfaces + """ os_net_interfaces_info = {} - # hash for information about net - os_install_net_data = {'type':'table', - 'mode':'w', - 'opt':["--ip"], - 'metavalue':"IFACE:IP", - 'source':["os_install_net_interfaces", +class VariableOsInstallNetData(NetVariable): + """ + Hash for information about net + """ + type = "table" + opt = ["--ip"] + metavalue = "IFACE:IP:MASK" + source = ["os_install_net_interfaces", "os_install_net_dhcp_set", "os_install_net_ip", "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") } - - # computer hostname - os_install_net_hostname = {'mode':"w"} - - # allowed network - os_install_net_allow ={} - - # net interfaces - os_install_net_interfaces={ - 'type':'list', - 'mode':'r', - 'label':_("Interface")} - - # net device name - os_install_net_name={ - 'type':'list', - 'mode':'r', - 'label':_("Name")} - - # net devices mac - os_install_net_mac={ - 'type':'list', - 'mode':'r', - 'label':_("MAC")} - - # ip for all network interfaces - os_install_net_ip = { - 'type':'list', - 'mode':'w', - 'label':_("IP address")} - - # network for ip - os_install_net_network = { - 'type':'list', - 'mode':'r', - 'label':_("Network")} - - # ip cidr - os_install_net_cidr = { - 'type':'list', - 'mode':'r', - 'label':_("CIDR")} - - os_install_net_mask = { - 'type':'choiceedit-list', - 'mode':'w', - 'label':_("Mask")} - - # dhcp or not - os_install_net_dhcp_set = { - 'type':'bool-list', - 'mode':'w', - 'label':_("DHCP")} - - # routing - os_install_net_route_hash = {} - - # net for route - os_install_net_route_network = {'value':[]} - - # gw for route - os_install_net_route_gw = {'value':[]} - - # dev for route - os_install_net_route_dev = {'value':[]} - - # src for route - os_install_net_route_src = {'value':[]} - - # data by route for conf.d/net - os_install_net_route = {'hide':True} - - # data by route for NetworkManager - os_install_net_nmroute = {'hide':True} - - # dns servers - os_install_net_dns = {} - - # net setup (networkmanager or openrc) - os_install_net_conf = {} - - # net service configured - os_install_net_settings = {'mode':'w', - 'value':''} - - # dns search - os_install_net_dns_search = {'mode':"w"} - - # domain - os_install_net_domain = {'mode':"w"} - - os_install_net_fqdn = {'mode':"w", - 'opt':['--hostname'], - 'label':_("Hostname"), - 'help':_("set the short hostname or full hostname")} - - def set_os_install_net_fqdn(self,value): + "os_install_net_mac"] + help = _("ip address with net (example:%s)")%"192.168.1.1/24" + label = _("Addresses") + +class VariableOsInstallNetHostname(NetVariable): + """ + Computer hostname + """ + def get(self): + return self.Get('os_install_net_fqdn').partition('.')[0] + +class VariableOsInstallNetFqdn(NetVariable): + """ + Full host name + """ + opt = ['--hostname'] + label = _("Hostname") + help = _("set the short hostname or full hostname") + + def set(self,value): if "." in value: return value else: return "%s.%s"%(value,self.Get('os_install_net_domain')) - def check_os_install_net_fqdn(self,value): + def check(self,value): maxfqdn = 254 if len(value) > maxfqdn: raise VariableError( _("Hostname length should be less that %d")%maxfqdn) - def get_os_install_net_fqdn(self): + def get(self): return self.Get('os_net_fqdn') - def get_os_install_net_hostname(self): - return self.Get('os_install_net_fqdn').partition('.')[0] - - def get_os_install_net_domain(self): +class VariableOsInstallNetDomain(NetVariable): + """ + Domain on install system + """ + def get(self): return self.Get('os_install_net_fqdn').partition('.')[2] - def get_os_install_net_interfaces(self): - return getInterfaces() - - def get_os_install_net_ip(self): - """ - Get ip for interface (Example:192.168.1.1) - """ - return map(lambda x:getIp(x),self.Get('os_install_net_interfaces')) - - def get_os_install_net_cidr(self): - """ - Get CIDR of ip,net (Example: 24) - """ - return map(lambda x:maskToCidr(x), - self.Get('os_install_net_mask')) - - def get_os_install_net_mask(self): - """ - Get mask for interfaces (Example: 255.255.0.0) - """ - return map(lambda x:cidrToMask(getMask(x)), - self.Get('os_install_net_interfaces')) - def get_os_install_net_mac(self): - """ - Get MAC for interfaces (Example: 01:02:03:04:05:06) - """ - return map(lambda x:getMac(x), - self.Get('os_install_net_interfaces')) +class VariableOsInstallNetAllow(NetVariable): + """ + Allowed network + """ + def get(self): + """Allowed network""" + return self.Get("os_net_allow") - def get_os_install_net_network(self): - """ - Get networks (Example:192.168.0.0/16) - """ - return map(lambda x:getIpNet(x[0],x[1]) if x[0] else "", - zip(self.Get('os_install_net_ip'), - self.Get('os_install_net_mask'))) +class VariableOsInstallNetName(NetVariable): + """ + Net device names + """ + type = "list" + mode = Readonly + label = _("Name") - def get_os_install_net_dhcp_set(self): - """ - Get method of receiving ip (dhcp on/off) - """ - return map(lambda x:"on" if isDhcpIp(x) else "off", - self.Get('os_install_net_interfaces')) - - def get_os_install_net_name(self): - """ - Get name for interfaces - """ + def get(self): rePci = re.compile(r"(\d\d:\d\d\.\d)(?:/[^/]+){2}$") def getPci(interface): pathname = path.realpath(path.join('/sys/class/net', @@ -240,15 +165,74 @@ class InstallNet(Net): 'name':_("vendor")}), self.Get('os_install_net_interfaces'))) - def check_os_install_net_ip(self,value): - """ - Check ip address - """ +class VariableOsInstallNetMac(NetVariable): + """ + Net devices mac (Example: 01:02:03:04:05:06) + """ + type = "list" + mode = Readonly + label = _("MAC") + + def get(self): + return map(lambda x:getMac(x), + self.Get('os_install_net_interfaces')) + +class VariableOsInstallNetIp(NetVariable): + """ + IP for all network interfaces + """ + type = "list" + label = _("IP address") + + def get(self): + return map(lambda x:getIp(x), + self.Get('os_install_net_interfaces')) + + def check(self,value): wrongIp = filter(lambda x:not checkIp(x),value) if wrongIp: raise VariableError(_("Wrong IP address %s")%wrongIp[0]) - def set_os_install_net_mask(self,value): +class VariableOsInstallNetNetwork(NetVariable): + """ + Network for ip (Example:192.168.0.0/16) + """ + type = "list" + mode = Readonly + label = _("Network") + + def get(self): + return map(lambda x:getIpNet(x[0],x[1]) if x[0] else "", + zip(self.Get('os_install_net_ip'), + self.Get('os_install_net_mask'))) + +class VariableOsInstallNetCidr(NetVariable): + """ + CIDR of interfaces + """ + type = "list" + mode = Readonly + label = _("CIDR") + + def get(self): + """ + Get CIDR of ip,net (Example: 24) + """ + return map(lambda x:maskToCidr(x), + self.Get('os_install_net_mask')) + +class VariableOsInstallNetMask(NetVariable): + """ + Net mask of interfaces (Example:255.255.0.0) + """ + type = "choiceedit-list" + label = _("Mask") + + def get(self): + return map(lambda x:cidrToMask(getMask(x)), + self.Get('os_install_net_interfaces')) + + def set(self,value): """ Convert to mask CIDR value """ @@ -260,25 +244,31 @@ class InstallNet(Net): res = map(convertCidrToMask,value) return res - def check_os_install_net_mask(self,value): - """ - Check mask address - """ + def check(self,value): wrongIp = filter(lambda x:not checkMask(x),value) if wrongIp: raise VariableError(_("Wrong mask %s")%wrongIp[0]) - def choice_os_install_net_mask(self): - """ - List value of mask - """ + def choice(self): return ["255.255.255.255", "255.255.255.0", "255.255.0.0", "255.0.0.0", "0.0.0.0"] - def set_os_install_net_dhcp_set(self,value): + +class VariableOsInstallNetDhcpSet(NetVariable): + """ + Describe ip was get by DHCP or manualy + """ + type = "bool-list" + label = _("DHCP") + + def get(self): + return map(lambda x:"on" if isDhcpIp(x) else "off", + self.Get('os_install_net_interfaces')) + + def set(self,value): """ Get method of receiving ip (dhcp on/off) """ @@ -287,21 +277,127 @@ class InstallNet(Net): zip(self.Get('os_install_net_interfaces'), value)) - def get_os_install_net_allow(self): - """Allowed network""" - return self.Get("os_net_allow") - def uncompatible_net_vars(self): +class VariableOsInstallNetRouteData(NetVariable): + """ + Route table data + """ + type = "table" + source = ['os_install_net_route_network', + 'os_install_net_route_gw', + 'os_install_net_route_dev', + 'os_install_net_route_src'] + +class VariableOsInstallNetRouteNetwork(NetVariable): + """ + Net for route table record + """ + type = "list" + value = [] + +class VariableOsInstallNetRouteGw(NetVariable): + """ + Gateway for route table record + """ + type = "list" + value = [] + +class VariableOsInstallNetRouteDev(NetVariable): + """ + Device for route table record + """ + type = "list" + value = [] + +class VariableOsInstallNetRouteSrc(NetVariable): + """ + Source ip for route table record + """ + type = "list" + value = [] + +class VariableOsInstallNetRoute(NetVariable): + """ + Data by route for conf.d/net + """ + mode = Readonly + value = "" + +class VariableOsInstallNetNmroute(NetVariable): + """ + Data by route for NetworkManager + """ + mode = Readonly + value = "" + +class VariableOsInstallNetConf(NetVariable): + """ + Net setup (networkmanager or openrc) + """ + type = "choice" + + def get(self): + """Net setup (networkmanager or openrc)""" + if filter(lambda x:x.lower() == ("networkmanager"), + listDirectory('/etc/runlevels/boot')+ + listDirectory('/etc/runlevels/default')) \ + or self.Get('os_install_root_type') == "livecd": + if isPkgInstalled("net-misc/networkmanager", + prefix=self.Get('cl_chroot_path')): + return "networkmanager" + return "openrc" + + def choice(self): + mapNetConf = (('networkmanager','net-misc/networkmanager'), + ('openrc','')) + return map(lambda x:x[0], + filter(lambda x:isPkgInstalled(x[1], + prefix=self.Get('cl_chroot_path')), + mapNetConf)) + +class VariableOsInstallNetDnsSearch(NetVariable): + """ + Dns search + """ + def isDNSByDHCP(self): """ - Network setting up unavailable for flash installation + If first interface get ip by DHCP dns must be DHCP """ - if self.Get('os_install_root_type') == 'flash': - return \ - _("Network configuration unavailable for flash installation") - return "" - - uncompatible_os_install_net_data = \ - uncompatible_os_install_net_ip = \ - uncompatible_os_install_net_mask = \ - uncompatible_os_install_net_hostname = \ - uncompatible_net_vars + dhcps = self.Get('os_install_net_dhcp_set') + if dhcps: + if dhcps[0] == "on": + return True + return False + + def get(self): + """Get current name servers""" + dnsSearch = " ".join( + map(lambda x:x.strip().partition("search")[2].strip(), + filter(lambda x:x.lstrip().startswith("search"), + readLinesFile('/etc/resolv.conf')))) + return "" if self.isDNSByDHCP() else dnsSearch + + +class VariableOsInstallNetDns(VariableOsInstallNetDnsSearch): + """ + Dns servers + """ + type = "list" + + def get(self): + dnsIps = filter(ip.checkIp, + map(lambda x:x.strip().partition("nameserver")[2].strip(), + filter(lambda x:x.lstrip().startswith("nameserver"), + readLinesFile('/etc/resolv.conf')))) + return "" if self.isDNSByDHCP() else dnsIps + + def check(self,value): + reIp = re.compile(ip.IP_ADDR) + if filter(reIp.match,value): + raise VariableError(_("Wrong DNS IP addresses")) + +class VariableOsInstallNetSettings(NetVariable): + """ + Net service configured + """ + value = "" diff --git a/install/variables/system.py b/install/variables/system.py index 83df4e8..5c4f37d 100644 --- a/install/variables/system.py +++ b/install/variables/system.py @@ -18,8 +18,8 @@ import os import sys import re from os import path -from calculate.lib.datavars import Variables,VariableError -from calculate.lib.variables import System +from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable +from calculate.install.variables.net import NetVariable from calculate.install.cl_install import FileSystemManager from calculate.lib.utils.files import readFile,getProgPath,process from calculate.lib.utils.common import getPasswdUsers @@ -29,133 +29,38 @@ from calculate.lib.encrypt import encrypt from calculate.lib.cl_lang import setLocalTranslate setLocalTranslate('cl_install',sys.modules[__name__]) -class InstallSystem(System): - vars = ["os_install_scratch","cl_autoupdate_set", - "cl_install_autoupdate_set", - "os_install_proxy","os_install_ntp", - "os_install_dev_from","os_install_lvm_set", - "os_install_mdadm_set","os_grub_conf","os_grub2_path", - "cl_chroot_grub","os_install_grub_devicemap_conf", - "cl_distfiles_path","cl_pkgdir_path","os_format_type", - "os_format_use","os_install_makeopts","cl_migrate_user", - "cl_migrate_data", - "cl_migrate_user_pwd","os_nvidia_mask","cl_autologin"] - - # install system in scratch mode - os_install_scratch = {'mode':'w', - 'type':'bool', - 'opt':['--build'], - 'label':_("Builder mode"), - 'help':_("installation for assemble")} - - # filesystem format support by calcualte-install - os_format_type = {'mode':'r', - 'type':"list"} - - # avialable format by mkfs utility - os_format_use = {'mode':'r', - 'type':"list"} - # (on or off) autoupdate config from install program - cl_autoupdate_set = {'value': "off", - 'type': "bool", - 'value': "off"} - - # (on or off) autoupdate config from install program for install - cl_install_autoupdate_set = {'mode':'w', - 'type': "bool", - 'value': "off"} - - # proxy server for system - os_install_proxy = {'mode':'w', - 'value':''} - - # nt server for system - os_install_ntp = {'mode':'w', - 'label':_("NTP server"), - 'opt':['--ntp'], - 'help':_("set the ntp server for the system"), - 'metavalue':"NTP", - 'value':'ntp0.zenon.net'} - - # type of device for install - os_install_root_type = {'mode':'w'} - # root device of installed os - os_install_root_dev = {} - - # using lvm - os_install_lvm_set = {'mode':'r', - 'type':"bool"} - - # using mdadm - os_install_mdadm_set = {'mode':'r', - 'type':"bool"} - - # current grub - os_grub_conf = {} - - # grub2 install path - os_grub2_path = {'mode':'w'} - - # grub chroot need for grub-mkconfig - cl_chroot_grub = {} - - # content of device.map file for grub - os_install_grub_devicemap_conf = {} +class UserVariable(Variable): + """ + Locale variables not using for flash installation + """ + def uncompatible(self): + """ + User setting up unavailable for flash installation + """ + if self.Get('os_install_root_type') == 'flash': + return \ + _("User configuration unavailable for flash installation") + return "" - # DISTFILES value - cl_distfiles_path = {'mode':'w', - 'value':'/var/calculate/remote/distfiles'} - # PKGDIR value - cl_pkgdir_path = {'mode':'w'} - - # makeconf makeopts - os_install_makeopts = {'mode':'w'} - - # user migrate data table - cl_migrate_data = {'type':'table', - 'mode':'w', - 'opt':["--users","-u"], - 'metavalue':'USERS', - 'source':['cl_migrate_user', - 'cl_migrate_user_pwd'], - 'help':_("add a user to the installed system"), - 'label':_("Migration users")} - - # migrate users - cl_migrate_user = {'type':'list', - 'label':_("Login"), - 'mode':'w'} - - # migrate users who need to change passwords - cl_migrate_user_pwd = {'type':'password-list', - 'label':_("Password"), - 'mode':'w'} - - # nvidia-drivers atom mask - os_nvidia_mask = {} - - # variable for autologin - cl_autologin = {'type':'choiceedit', - 'mode':'w', - 'label':_("Autologin"), - 'opt':["--autologin",'-A'], - 'metavalue':"USER", - 'help':_("add an autologin user to the installed system") - } - - # root device of previous installed os - os_install_dev_from = {'mode':'w'} - - def get_os_install_scratch(self): - """Install system in scratch mode""" +class VariableOsInstallScratch(Variable): + """ + Install system in scratch mode + """ + type = "bool" + opt = ['--build'] + label = _("Builder mode") + help = _("installation for assemble") + + def get(self): + # for installation default - normal system if self.Get('cl_action') == 'system': return "off" else: return self.Get('os_scratch') - def check_os_install_scratch(self,value): - """Check abality install in scratch mode""" + def check(self,value): if value == "on": + # scratch not use for falsh and multipartition if self.Get('os_install_root_type') == "flash": raise VariableError( _("Installation to flash disk is not supported" @@ -164,21 +69,212 @@ class InstallSystem(System): raise VariableError( _("Builder mode does not support multipartition install")) - def get_os_format_type(self): +class VariableOsFormatType(ReadonlyVariable): + """ + Filesystem format support by calcualte-install + """ + type = "list" + + def get(self): """Filesystem format support by calcualte-install""" return FileSystemManager.supportFS.keys() - def get_os_format_use(self): - """Avialable format by mkfs utility""" +class VariableOsFormatUse(ReadonlyVariable): + """ + Avialable format by mkfs utility + """ + type = "list" + # (on or off) autoupdate config from install program + cl_autoupdate_set = {'value': "off", + 'type': "bool", + 'value': "off"} + + def get(self): return map(lambda x:"yes" if path.exists(FileSystemManager.supportFS[x]["format"]) else "no", self.Get('os_format_type')) - def get_cl_pkgdir_path(self): +class VariableClMigrateData(UserVariable): + """ + User migrate data table + """ + 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'] + +class VariableClMigrateUser(UserVariable): + """ + Migrate users list + """ + type = 'list' + label = _("Login") + + def get(self): + """ + Migration users (root and users above 1000 uid) + """ + return getPasswdUsers() + +class VariableClMigrateUserPwd(UserVariable): + """ + Migrate users who need to change passwords + """ + type = 'password-list' + label = _("Password") + + def get(self): + """ + Migration users passwords + """ + retList = [] + fileName = "/etc/shadow" + if os.access(fileName, os.R_OK): + migrateusers = self.Get("cl_migrate_user") + if migrateusers: + lenData=9 + shadowData = filter(lambda x: len(x)==lenData, + map(lambda x: x.rstrip().split(":"), + open(fileName))) + shadowData = filter(lambda x: x[0] in migrateusers, shadowData) + shadowData = map(lambda x: (x[0], x[1]), shadowData) + shadowUsers = map(lambda x: x[0], shadowData) + for userName in migrateusers: + if userName in ("root",): + if userName in shadowUsers: + userData = filter(lambda x: x[0]==userName, + shadowData) + hashPwd = userData[0][1] + salt = "".join(hashPwd.rpartition("$")[:1]) + if salt and crypt(userName, salt) == hashPwd: + retList.append("") + else: + retList.append(hashPwd) + else: + retList.append("") + else: + if userName in shadowUsers: + userData = filter(lambda x: x[0]==userName, + shadowData) + hashPwd = userData[0][1] + retList.append(hashPwd) + else: + retList.append("") + return retList + + def check(self,value): + """ + Check exists password for all migrate users + """ + for user,pwd in zip(self.Get('cl_migrate_user'),value): + if not pwd: + raise VariableError( + _("Missed a password for the user %s")%user) + + def set(self,value): + """ + Encrypt passwords + """ + reCheck = re.compile("^\$[^$]+\$[^$]+\$.*$") + encryptObj = encrypt() + + return map(lambda x:x if reCheck.match(x) or not x else \ + encryptObj.getHashPasswd(x, "shadow_ssha256"), + value) + +class VariableClAutologin(UserVariable): + """ + Autologin variable (contains user name for autologin) or + + empty string if disable + """ + type = 'choiceedit' + label = _("Autologin") + opt = ["--autologin",'-A'] + metavalue = "USER" + help = _("add an autologin user to the installed system") + + def get(self): + # autologin enable for livecd and all install type CMC + if self.Get('os_install_root_type') == "livecd" or \ + self.Get('os_install_linux_shortname') == "CMC": + nonRootUsers = filter(lambda x: x != "root", + self.Get('cl_migrate_user')) + if nonRootUsers: + return nonRootUsers[0] + else: + return "" + return "" + + def choice(self): + return filter(lambda x:x != "root",self.Get('cl_migrate_user'))+[""] + + def check(self,value): + """ + Autologin only for migrated non-root users + """ + if value and not value in self.Get('cl_migrate_user'): + raise VariableError(_("User %s is not exists")%value) + if value == "root": + raise VariableError(_("Autologin is imposible for %s user")%value) + +class VariableClInstallAutoupdateSet(Variable): + """ + (on or off) autoupdate config from install program for install + """ + type = "bool" + value = "off" + +class VariableOsInstallMakeopts(Variable): + """ + Make.conf makeopts + """ + def get(self): + cpunum = self.Get('hr_cpu_num') + if cpunum == "1": + return "-j1" + else: + return "-j%d"%(int(cpunum)+1) + +class VariableOsGrubConf(ReadonlyVariable): + """ + DEPRICATED content of current grub.conf + """ + +class VariableOsInstallGrubDevicemapConf(ReadonlyVariable): + """ + DEPRICATED content of device.map file for grub + """ + os_install_grub_devicemap_conf = {} + +class VariableClDistfilesPath(Variable): + """ + DISTFILES path + """ + value = '/var/calculate/remote/distfiles' + +class VariableClPkgdirPath(Variable): + """ + PKGDIR path + """ + def get(self): return "/var/calculate/remote/packages/%s/%s" % ( self.Get('os_install_linux_shortname'), self.Get('os_install_arch_machine')) +class VariableOsInstallDevFrom(Variable): + """ + Root device of previous installed os + """ + # TODO: may be check or set for ini file + pass + +class VariableClInstallAutoupdateSet(Variable): + """ + Autoupdate for install or configure system + """ def get_cl_install_autoupdate_set(self): """Get autoupdate default value""" if self.Get('ac_install_system') == "up": @@ -189,8 +285,11 @@ class InstallSystem(System): else: return self.Get('cl_autoupdate_set') - def get_os_nvidia_mask(self): - """Get nvidia card mask versions""" +class VariableOsNvidiaMask(ReadonlyVariable): + """ + Get nvidia card mask versions + """ + def get(self): image = self.Get('cl_image') try: if image: @@ -234,36 +333,48 @@ class InstallSystem(System): image.close() return "" - def get_os_install_lvm_set(self): - """Using lvm""" +class VariableOsInstallLvmSet(ReadonlyVariable): + """ + Using lvm + """ + type = "bool" + + def get(self): for typeDisk in self.Get('os_install_disk_type'): if "lvm" in typeDisk: return "on" else: return "off" - def get_os_install_mdadm_set(self): - """Using mdadm""" +class VariableOsInstallMdadmSet(ReadonlyVariable): + """ + Using mdadm + """ + type = "bool" + + def get(self): for typeDisk in self.Get('os_install_disk_type'): if "lvm" in typeDisk: return "on" else: return "off" - def get_cl_chroot_grub(self): - """ - Chroot for grub-mkconfig - TODO: check for install scratch system. - """ +class VariableClChrootGrub(ReadonlyVariable): + """ + Chroot for grub-mkconfig + TODO: check for install scratch system. + """ + def get(self): if self.Get('os_install_scratch') == "on": return path.join(self.Get('cl_chroot_path'),"mnt/scratch") else: return self.Get('cl_chroot_path') - def get_os_grub2_path(self): - """ - Get Grub2 Install cmd - """ +class VariableOsGrub2Path(Variable): + """ + Get Grub2 Install cmd (grub-install or grub2-install) + """ + def get(self): # find grub2-install grubInstall = getProgPath('/sbin/grub2-install') if grubInstall: @@ -274,110 +385,3 @@ class InstallSystem(System): process(grubInstall,'-v')): return grubInstall return "" - - def get_cl_migrate_user(self): - """ - Migration users (root and users above 1000 uid) - """ - return getPasswdUsers() - - def get_cl_migrate_user_pwd(self): - """ - Migration users passwords - """ - retList = [] - fileName = "/etc/shadow" - if os.access(fileName, os.R_OK): - migrateusers = self.Get("cl_migrate_user") - if migrateusers: - lenData=9 - shadowData = filter(lambda x: len(x)==lenData, - map(lambda x: x.rstrip().split(":"), - open(fileName))) - shadowData = filter(lambda x: x[0] in migrateusers, shadowData) - shadowData = map(lambda x: (x[0], x[1]), shadowData) - shadowUsers = map(lambda x: x[0], shadowData) - for userName in migrateusers: - if userName in ("root",): - if userName in shadowUsers: - userData = filter(lambda x: x[0]==userName, - shadowData) - hashPwd = userData[0][1] - salt = "".join(hashPwd.rpartition("$")[:1]) - if salt and crypt(userName, salt) == hashPwd: - retList.append("") - else: - retList.append(hashPwd) - else: - retList.append("") - else: - if userName in shadowUsers: - userData = filter(lambda x: x[0]==userName, - shadowData) - hashPwd = userData[0][1] - retList.append(hashPwd) - else: - retList.append("") - return retList - - def check_cl_migrate_user_pwd(self,value): - """ - Check exists password for all migrate users - """ - for user,pwd in zip(self.Get('cl_migrate_user'),value): - if not pwd: - raise VariableError( - _("Missed a password for the user %s")%user) - - def set_cl_migrate_user_pwd(self,value): - """ - Encrypt passwords - """ - reCheck = re.compile("^\$[^$]+\$[^$]+\$.*$") - encryptObj = encrypt() - - return map(lambda x:x if reCheck.match(x) or not x else \ - encryptObj.getHashPasswd(x, "shadow_ssha256"), - value) - - def get_cl_autologin(self): - """ - Autologin - """ - if self.Get('os_install_root_type') == "livecd" or \ - self.Get('os_install_linux_shortname') == "CMC": - nonRootUsers = filter(lambda x: x != "root", - self.Get('cl_migrate_user')) - if nonRootUsers: - return nonRootUsers[0] - else: - return "" - return "" - - def choice_cl_autologin(self): - """ - List of valid users - """ - return filter(lambda x:x != "root",self.Get('cl_migrate_user'))+[""] - - def check_cl_autologin(self,value): - """ - Autologin only migrated users - """ - if value and not value in self.Get('cl_migrate_user'): - raise VariableError(_("User %s is not exists")%value) - if value == "root": - raise VariableError(_("Autologin is imposible for %s user")%value) - - def uncompatible_user_vars(self): - """ - Network setting up unavailable for flash installation - """ - if self.Get('os_install_root_type') == 'flash': - return \ - _("User configuration unavailable for flash installation") - return "" - - uncompatible_cl_autologin = \ - uncompatible_cl_migrate_data = \ - uncompatible_user_vars