Migrate to new variables.

master3.3
Mike Hiretsky 12 years ago
parent d4710b2688
commit 90532bd31f

@ -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"""

@ -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

@ -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')

@ -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':"<width>x<height>",
'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':"<width>x<height>",
'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 = "<width>x<height>"
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 = "<width>x<height>"
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

@ -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__

@ -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 ""

File diff suppressed because it is too large Load Diff

@ -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)

@ -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 ""

@ -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"

@ -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"]

@ -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 = ""

@ -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

Loading…
Cancel
Save