Install refactoring.

master3.3
Mike Hiretsky 12 years ago
parent 3569d88499
commit e44f152208

@ -400,7 +400,7 @@ class Distributive(object, SignalInterrupt):
while path.exists(newDirectoryName):
newDirectoryName = "%s.%s"%(directory,self.rndString())
return newDirectoryName
def getInfoFromDirectory(self,directory):
d = {}
if path.lexists(path.join(directory,'lib64')):

@ -814,48 +814,6 @@ class fillVars(object, varsShare):
return clock.lower()
return "local"
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 "1024x768"
def get_os_install_x11_video_drv(self):
"""Video driver used by xorg"""
if self.Get('os_install_root_type') == 'usb-hdd':
prefix = self.Get('cl_chroot_path')
videoVal = self.getValueFromCmdLine("calculate","video")
videoVal = {'i915':'intel'}.get(videoVal,videoVal)
if not isPkgInstalled('xorg-server',
prefix=self.Get('cl_chroot_path')) or \
videoVal in getAvailableVideo(prefix=prefix):
return videoVal
return self.getVideoByDefault(getInstalledVideo(prefix=prefix))
else:
return self.Get('os_x11_video_drv')
def get_os_install_x11_composite(self):
"""On/off composite"""
defaultCompositeOn = ("nvidia","intel","fglrx","nouveau","radeon")
composite = self.getValueFromCmdLine("calculate",5)
videodrv = self.getValueFromCmdLine("calculate",4)
if videodrv != "auto":
composite = {'nocomposite':'off',
'off':'off',
'on':'on',
'composite':'on'}.get(composite)
else:
composite = None
if self.Get('os_x11_video_drv') in defaultCompositeOn:
defaultComposite = "on"
else:
defaultComposite = "off"
state = self.get_composite_from_xorgconf()
return composite or state or defaultComposite
def get_os_install_linguas(self):
"""Current linguas"""

@ -96,9 +96,6 @@ class DataVarsInstall(ClDataVars):
class FileSystemManager:
"""Convert dict install option"""
defaultFS = {'hdd':"ext4",
'flash':"vfat",
'usb-hdd':"ext4"}
defaultOpt = 'noatime'
defaultBindOpts = ['bind']
supportFS = {
@ -186,6 +183,26 @@ class FileSystemManager:
'msdos': '7',
'compatible':['ntfs']}}
@classmethod
def firstAvailable(cls,listFS):
for fs in listFS:
if path.exists(cls.supportFS['format']):
return fs
else:
return ""
defaultFS = {'hdd':"ext4" \
if path.exists(supportFS['ext4']['format']) else \
"reiserfs" \
if path.exists(supportFS['reiserfs']['format']) else \
"ext3",
'flash':"vfat",
'usb-hdd': "ext4" \
if path.exists(supportFS['ext4']['format']) else \
"reiserfs" \
if path.exists(supportFS['reiserfs']['format']) else \
"ext3"}
@classmethod
def getDefaultOpt(cls,fs):
return cls.supportFS.get(fs,{'defaultopt':''})['defaultopt']
@ -771,160 +788,7 @@ class Install(color_print, SignalInterrupt):
error = lambda *args,**kw: self.errlist.append(InstallError(*args,**kw))
# break perform if disk params empty and os_install_dev_from empty
if not (lDisks or lSwaps or lBinds):
error(_("For installation need specify root device"),
field="disk")
return False
# check for Incorrect device
wrongDevices = []
if lDisks + lSwaps:
usedDevices = zip(*(lDisks+lSwaps))[0]
else:
usedDevices = []
wrongDevices = list(set(usedDevices) - \
set(self.clVars.Get('os_disk_dev')))
if wrongDevices:
error(_("Incorrect device '%s'")%wrongDevices[0],
field="disk")
return False
usedMP = list(zip(*(map(lambda x:x+[""],lDisks+lBinds)))[1])
# check mount options for scratch
if filter(lambda x: x != '/', usedMP):
if self.clVars.Get('os_install_scratch') == "on":
error(
_("Builder mode does not support multipartition install"))
# detect using extended partition
extendedPartitions = map(lambda x: x[1],
filter(lambda x: x[0]=="extended",
zip(self.clVars.Get('os_disk_part'),
self.clVars.Get('os_disk_dev'))))
extendedPartitions = ['/dev/sda4']
usingExtPart = list(set(usedDevices)&set(extendedPartitions))
if usingExtPart:
error(
_("Unable to use the extended partition %s for installation")%
usingExtPart[0],field="disk")
# detect using CDROM disks
cdromPartitions = map(lambda x: x[1],
filter(lambda x: "cdrom" in x[0],
zip(self.clVars.Get('os_disk_type'),
self.clVars.Get('os_disk_dev'))))
usingCdromPart = list(set(usedDevices)&set(cdromPartitions))
if usingCdromPart:
error(_("Unable to use CDROM %s for installation")%
usingCdromPart[0],field="disk")
# detect using RAID member disks
raidMemberData = filter(lambda x: "raidmember" in x[0],
zip(self.clVars.Get('os_disk_type'),
self.clVars.Get('os_disk_dev')))
raidMemberPartitions = map(lambda x:x[1],raidMemberData)
usingRaidMemberPart = list(set(usedDevices)&set(raidMemberPartitions))
if usingRaidMemberPart:
raidMemberData = filter(lambda x:x[1] in usingRaidMemberPart,
raidMemberData)[0][0]
raidMemberData = raidMemberData.rpartition("raidmember(")[2]
raidMemberData = raidMemberData.partition(")")[0]
error(
_("Unable to use active {typepart} member {part} "
"for installation").format(
typepart="RAID",part=usingRaidMemberPart[0])
+"\n"+
_("To use this partition, you have to stop RAID %s")%
raidMemberData
+"\n"+
(" mdadm -S %s"%raidMemberData),field="disk")
# detect using LVM member disks
lvmMemberData = filter(lambda x: "lvmmember" in x[0],
zip(self.clVars.Get('os_disk_type'),
self.clVars.Get('os_disk_dev')))
lvmMemberPartitions = map(lambda x:x[1],lvmMemberData)
usingLvmMemberPart = list(set(usedDevices)&set(lvmMemberPartitions))
if usingLvmMemberPart:
lvmMemberData = filter(lambda x:x[1] in usingLvmMemberPart[0],
lvmMemberData)[0][0]
lvmMemberData = lvmMemberData.rpartition("lvmmember(")[2]
lvmMemberData = lvmMemberData.partition(")")[0]
prop = getUdevDeviceInfo(name=lvmMemberData)
vgName = prop.get('DM_VG_NAME','')
error(
_("Unable to use active {typepart} member {part} "
"for installation").format(
typepart="LVM",part=usingLvmMemberPart[0])
+"\n"+
_("To use this partition, you have to remove LVM %s")%
lvmMemberData
+"\n"+
(" vgremove %s"%vgName)
+"\n"+
(" pvremove %s"%usingLvmMemberPart[0]),field="disk")
# check bind mount points
srcMountPoints = map(lambda x:x[DEVICE],lBinds)
destMountPoints = map(lambda x:x[MP],lBinds)
wrongBind = filter(lambda x:x in destMountPoints,srcMountPoints)
if wrongBind:
incompBind = filter(lambda x:x[1]==wrongBind[0],
zip(srcMountPoints,destMountPoints))
error(
_("Source directory %(src)s already used "
"for binding '%(bindSrc)s' to '%(bindDst)s'")\
%{'src':wrongBind[0],
'bindSrc':incompBind[0][0],
'bindDst':incompBind[0][1]},field="disk")
wrongBind = filter(lambda x:not x[0].startswith("/") or
not x[1].startswith("/") and
x[1] != "none",
zip(srcMountPoints,destMountPoints))
if wrongBind:
error(
_("Incorrect mount point (bind '%(bindSrc)s' to "\
"'%(bindDst)s')")\
%{'bindSrc':wrongBind[0][0],
'bindDst':wrongBind[0][1]},field="disk")
# Check '/' in start path
wrongMP = filter(lambda x: not x.startswith("/") and x!="none",
usedMP) + \
filter(lambda x: not x.startswith("/"),
map(lambda x:x[DEVICE],lBinds))
if wrongMP:
error(_("Incorrect mount point '%s'")%wrongMP[0],
field="disk")
# detect duplicate devices
dupDevices = list(set(filter(lambda x:usedDevices.count(x)>1,
usedDevices)))
if dupDevices:
error(_("Device '%s' is used twice")%dupDevices[0],
field="disk")
# detect duplicate mount points
dupMP = list(set(filter(lambda x:usedMP.count(x)>1 and x != "none",
usedMP)))
if dupMP:
error(_("Mount point '%s' is used twice")%dupMP[0],
field="disk")
# set root device
rootdevs = map(lambda x:x[DEVICE],
filter(lambda x:x[MP] == '/',
lDisks))
if rootdevs:
self.clVars.Set('os_install_root_dev',rootdevs[0],True)
else:
error(_("The root partition must be specified"),
field="disk")
# update install root dev
osInstallRootType = self.clVars.Get('os_install_root_type')
mapCurrent = dict(map(lambda x:(x[DEVICE],(x[MP],x[FS])),
self.clVars.zipVars('os_disk_dev',
@ -933,12 +797,6 @@ class Install(color_print, SignalInterrupt):
lDisks = lDisks + lSwaps
for diskData in lDisks:
# if fs not specified
curMP = mapCurrent[diskData[DEVICE]][0]
if curMP == '/':
error(
_("The current root partition %s can not be "
"used for installation")%
diskData[DEVICE], field="disk")
curFS = mapCurrent[diskData[DEVICE]][1]
print diskData
if diskData[FS] == '':
@ -996,17 +854,6 @@ class Install(color_print, SignalInterrupt):
error(_("Disk {device} should be formatted").format(
device=diskData[DEVICE]),field="disk")
# update bind variables by new hash
if osInstallRootType == "flash":
if filter(lambda x: x != '/', usedMP):
error(_("Installation to flash disk is not supported for "
"multipartition install"),field="disk")
if lSwaps:
error(_("Installation to flash disk is not "
"supported for swap disks"),field="disk")
if builderMode:
error(_("Installation to flash disk is not supported"
" in builder mode"),field="disk")
diskDev = self.clVars.Get('os_disk_dev')
mapInstallData = dict(map(lambda x:(x[DEVICE],(x[MP],x[FS],x[FORMAT])),
lDisks))

@ -17,8 +17,15 @@
import os
import sys
from os import path
from calculate.lib.cl_datavars import Variables
from calculate.lib.cl_datavars import Variables,VariableError
from calculate.lib.variables import X11
from calculate.lib.utils.portage import isPkgInstalled
from calculate.lib.utils.files import process,STDOUT,getProgPath
from calculate.lib.utils.common import (getVideoFromXorgLog,
getVideoFromXorgConf, getVideoFromCmdLine,
getAvailableVideo, getValueFromCmdLine,
getCompositeFromXorgconf, getVideoFromModules,
getVideoFromVendor,getInstalledVideo)
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_install',sys.modules[__name__])
@ -27,16 +34,122 @@ 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 = {}
os_install_x11_resolution = {'mode':'w',
'type':'choiceedit'}
# Video driver used by xorg
os_install_x11_video_drv = {'mode':'w'}
os_install_x11_video_drv = {'mode':'w',
'type':'choice'}
# on/off composite
os_install_x11_composite = {'mode':'w'}
os_install_x11_composite = {'mode':'w',
'type':'bool'}
# fb resolution
os_install_fb_resolution = {'mode':'w'}
os_install_fb_resolution = {'mode':'w',
'type':'choiceedit'}
# busid of video card
hr_video_id = {'value':""}
def choice_os_install_x11_video_drv(self):
"""Get available (already installed or installable drivers"""
image = self.Get('cl_image')
if image:
distrPath = image.getDirectory()
if isPkgInstalled('xorg-server',prefix=distrPath):
return getAvailableVideo(prefix=distrPath)+['other']
return []
def get_os_install_x11_video_drv(self):
"""Get install video drv"""
# get available videodriver list from install or configure distributive
list_video = self.Choice('os_install_x11_video_drv')#getAvailableVideo(distrPath)
if not list_video:
return "other"
# if type system is usb-hdd then get detect video driver
if self.Get('os_install_root_type') == 'usb-hdd':
methods = ((getVideoFromModules,()),
(getVideoFromCmdLine,()),
(getVideoFromVendor,(self.Get('hr_video'),list_video)))
else:
# test current video driver for install system
methods = ((getVideoFromXorgLog,('/',list_video)),
(getVideoFromXorgConf,('/',)),
(getVideoFromModules,()),
(getVideoFromCmdLine,()),
(getVideoFromVendor,(self.Get('hr_video'),list_video)))
for func,args in methods:
drv = func(*args)
if drv in list_video:
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):
"""On/off composite"""
defaultCompositeOn = ("nvidia","intel","fglrx","nouveau","radeon")
composite = getValueFromCmdLine("calculate",5)
videodrv = getValueFromCmdLine("calculate",4)
if videodrv != "auto":
composite = {'nocomposite':'off',
'off':'off',
'on':'on',
'composite':'on'}.get(composite)
else:
composite = None
if self.Get('os_install_x11_video_drv') in defaultCompositeOn:
defaultComposite = "on"
else:
defaultComposite = "off"
if self.Get('os_install_x11_video_drv') == self.Get('os_x11_video_drv'):
state = getCompositeFromXorgconf()
else:
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):
"""Get current framebuffer resolution"""
resolution = ""
fbres = getProgPath('/sbin/fbres')
if fbres:
processFbres = process(fbres,stderr=STDOUT)
textLines = processFbres.readlines()
if textLines:
cxx11,cyx11 = \
self.Get('os_install_x11_resolution').partition('x')[0::2]
cxfb, cyfb = textLines[0].partition('x')[0::2]
if not filter(lambda x:not x.isdigit(),
[cxfb,cyfb,cxx11,cyx11])and \
int(cxx11) >= int(cxfb) and int(cyx11) >= int(cyfb):
resolution = "%s-32"%textLines[0]
return resolution or "1024x768-32@60"

File diff suppressed because it is too large Load Diff

@ -134,7 +134,7 @@ class Distro(Variables):
def get_cl_image(self):
"""Get image file from distributive repository"""
if self.Get('cl_action') != 'system':
return ""
return Distributive.fromFile('/')
filename = self.getImage(self.Get('os_install_scratch'),
self.Get('os_install_root_type'),
self.Get('cl_image_path'),

@ -16,10 +16,12 @@
import os
import sys
import re
from os import path
from calculate.lib.cl_datavars import Variables
from calculate.lib.cl_datavars import Variables,VariableError
from calculate.lib.variables import System
from calculate.install.cl_install import FileSystemManager
from calculate.lib.utils.files import readFile,getProgPath,process
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_install',sys.modules[__name__])
@ -27,8 +29,8 @@ 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_root_type",
"os_install_root_dev","os_install_dev_from","os_install_lvm_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",
@ -49,7 +51,6 @@ class InstallSystem(System):
# 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",
@ -119,7 +120,21 @@ class InstallSystem(System):
def get_os_install_scratch(self):
"""Install system in scratch mode"""
return self.Get('os_scratch')
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"""
if value == "on":
if self.Get('os_install_root_type') == "flash":
raise VariableError(
_("Installation to flash disk is not supported"
" in builder mode"))
if filter(lambda x: x != '/', self.Get('os_install_disk_mount')):
raise VariableError(
_("Builder mode does not support multipartition install"))
def get_os_format_type(self):
"""Filesystem format support by calcualte-install"""
@ -135,3 +150,77 @@ class InstallSystem(System):
return "/var/calculate/remote/packages/%s/%s" % (
self.Get('os_install_linux_shortname'),
self.Get('os_install_arch_machine'))
def get_cl_install_autoupdate_set(self):
"""Get autoupdate default value"""
if self.Get('ac_install_system') == "up":
if self.Get('os_install_linux_system') == 'desktop':
return "on"
else:
return "off"
else:
return self.Get('cl_autoupdate_set')
def get_os_nvidia_mask(self):
"""Get nvidia card mask versions"""
image = self.Get('cl_image')
if image:
chrootPath = image.getDirectory()
else:
chrootPath = self.Get("cl_chroot_path")
nvidiaeclass = path.join(chrootPath,
'usr/portage/eclass/nvidia-driver.eclass')
if not os.access(nvidiaeclass,os.R_OK):
return ""
category = "0300"
vendor = "10de:"
lsPciProg = getProgPath("/usr/sbin/lspci")
nvidiacards = filter(lambda x:" %s: "%category in x,
process(lsPciProg,"-d",vendor,"-n"))
if not nvidiacards:
return ""
cardsid = map(lambda x:x.groups()[0],
filter(lambda x:x,
map(lambda x:re.search("[0-9a-fA-F]{4}:([0-9a-fA-F]{4})",x),
nvidiacards)))
if not cardsid:
return ""
eclassdata = readFile(nvidiaeclass)
drv_categories = re.findall('^drv_([^=]+)="', eclassdata, re.M)
drvs = map(lambda x:(x[0],x[1].replace('\\\n','').split()),
re.findall('\ndrv_(%s)="(.*?)"'%"|".join(drv_categories),
eclassdata,re.S))
mask_categories = re.findall('^mask_([^=]+)="', eclassdata, re.M)
masks = dict(map(lambda x:(x[0],x[1].replace('\\\n','')),
re.findall('\nmask_(%s)="(.*?)"'%"|".join(drv_categories),
eclassdata,re.S)))
drvsForCardsid = filter(lambda x:set(x[1])&set(cardsid),drvs)
if drvsForCardsid and drvsForCardsid[0][0] in masks:
return masks[drvsForCardsid[0][0]]
return ""
def get_os_install_lvm_set(self):
"""Using lvm"""
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"""
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.
"""
if self.Get('os_install_scratch') == "on":
return path.join(self.Get('cl_chroot_path'),"mnt/scratch")
else:
return self.Get('cl_chroot_path')

@ -31,11 +31,11 @@ data_files = []
var_data_files = []
data_files += [('/etc/init.d', ['data/calculate']),
('/usr/bin',['data/xautologin']),
('/usr/share/calculate/doc', ['data/handbook-en.html',
'data/handbook-ru.html']),
('/bin',['data/bashlogin'])]
#data_files += [('/etc/init.d', ['data/calculate']),
# ('/usr/bin',['data/xautologin']),
# ('/usr/share/calculate/doc', ['data/handbook-en.html',
# 'data/handbook-ru.html']),
# ('/bin',['data/bashlogin'])]
BUILD_MAN_PATH = "build/man"

Loading…
Cancel
Save