Add system configuration methods

master3.3
Mike Hiretsky 12 years ago
parent a43f6e4a28
commit 8a95970c3d

@ -483,21 +483,10 @@ class Install(color_print):
if maskNvidia == curNvidiaMask:
return True
self.printByResult(True)
self.printMessageForTest(_("Driver installation for %s")%
self.startTask(_("Driver installation for %s")%
self.clVars.Get('hr_video'))
open(nvidiaMaskFile,'w').write(maskNvidia)
try:
envDict = {'PKGDIR':binPackages}
envDict.update(os.environ)
processEmerge = process('/usr/bin/emerge','-k','nvidia-drivers',
envdict=envDict,stdout=PIPE,stderr=PIPE)
res = processEmerge.success()
except KeyboardInterrupt:
os.unlink(nvidiaMaskFile)
return False
if not res:
os.unlink(nvidiaMaskFile)
return res
return True
def configureSystem(self,autologin):
"""configuring the current system"""
@ -666,6 +655,165 @@ class Install(color_print):
raise InstallError(_("Failed to migrate users to the new system"))
self.endTask()
def setupVideo(self):
"""Setup video"""
pathGlModules = path.join(self.clVars.Get('cl_chroot_path'),
'usr/lib/opengl')
self.startTask(_("Check the video driver"))
self.checkVideoDriver()
self.endTask()
if path.exists(pathGlModules):
self.startTask(_("Configure OpenGL"))
self.setupOpenGL()
self.endTask()
oldXdrv = self.clVars.Get('os_x11_video_drv')
newXdrv = self.clVars.Get('os_install_x11_video_drv')
if oldXdrv != newXdrv:
kmsDrv = ("radeon","i915","intel","nouveau","ati")
self.defaultPrint("\n")
if oldXdrv in kmsDrv or newXdrv in kmsDrv:
self.printWARNING(
_("To apply the changes, reboot the system")
+".\n")
else:
self.printWARNING(
_("To apply the changes, restart the X server")
+".\n")
def hideStdout(self):
if not self.stdoutHide:
self.stdoutHide = sys.stdout
self.stderrHide = sys.stderr
sys.stdout = StringIO()
sys.stderr = StringIO()
sys.stdout.fileno = self.stdoutHide.fileno
sys.stderr.fileno = self.stderrHide.fileno
def showStdout(self):
if self.stdoutHide:
sys.stdout = self.stdoutHide
sys.stderr = self.stderrHide
self.stdoutHide = None
self.stderrHide = None
def installDesktopClient(self):
"""
Install desktop and client package
"""
linuxShortname = self.clVars.Get('os_install_linux_shortname')
# install desktop package
if linuxShortname in ("CLD","CLS","CLDG","CLDX"):
generalLib = '/usr/lib/calculate-2.2/calculate-lib/pym'
desktopLib = '/usr/lib/calculate-2.2/calculate-desktop/pym'
if path.exists(generalLib) and path.exists(desktopLib):
sys.path.insert(0, path.abspath(generalLib))
sys.path.insert(0, path.abspath(desktopLib))
from cl_desktop import desktop
self.startTask(_("Enable calculate-desktop "
"for package configuration"))
self.hideStdout()
objDesktop = desktop()
objDesktop.createClVars()
if objDesktop.installProg():
self.endTask()
else:
self.printERROR()
self.showStdout()
sys.path.pop(0)
sys.path.pop(0)
# install client package
if linuxShortname in ("CLD","CLDG","CLDX"):
generalLib = '/usr/lib/calculate-2.2/calculate-lib/pym'
clientLib = '/usr/lib/calculate-2.2/calculate-client/pym'
if path.exists(generalLib) and path.exists(clientLib):
sys.path.insert(0, path.abspath(generalLib))
sys.path.insert(0, path.abspath(clientLib))
from cl_client import client
self.startTask(
_("Enable calculate-client for package configuration"))
objClient = client()
objClient.createClVars()
self.hideStdout()
if hasattr(objClient,"updateEnvFiles") and \
objClient.updateEnvFiles():
objClient.clVars.flIniFile()
if objClient.installProg():
self.endTask()
else:
self.printERROR()
self.showStdout()
sys.path.pop(0)
sys.path.pop(0)
def setupSystem(self,variables):
error = None
if variables:
self.clVars = variables
else:
self.initVars()
try:
target = None
setupType = self.clVars.Get('cl_setup',humanreadable=True)
if setupType:
self.startTask((_("%s are configured")%
setupType).capitalize(),progress=True)
else:
self.startTask(_("System configuration"),progress=True)
res = self.applyTemplatesStartup()
self.endTask()
if setupType and self.clVars.Get('cl_setup') == 'network':
pass
if setupType and self.clVars.Get('cl_setup') == 'video':
self.setupVideo()
if setupType and self.clVars.Get('cl_setup') == 'users':
pass
if not setupType or self.clVars.Get('cl_setup') == 'boot' and \
self.clVars.Get('os_root_type') != 'livecd':
target = self.clVars.Get('cl_image')
self.startTask(_("Installing bootloader"))
self.prepareBoot(target)
self.endTask()
root_dev = self.clVars.Select('os_disk_parent',
where='os_disk_mount',
eq='/',limit=1)
if root_dev:
self.startTask(_("Changing I/O scheduler"))
try:
schedpath = ("/sys%s/queue/scheduler"%
(getUdevDeviceInfo(name=root_dev).get('DEVPATH','')))
if path.exists(schedpath):
open(schedpath,'w').write(
self.clVars.Get('os_install_kernel_scheduler'))
self.endTask()
except:
self.printERROR(_("Unable change I/O scheduler"))
pass
if not setupType:
self.installDesktopClient()
except (BaseException),e:
error = ""
for i in apply(traceback.format_exception, sys.exc_info()):
error += i
self.printERROR(error)
return False
finally:
try:
self.clVars.close()
if target:
target.close()
except (BaseException),e:
error = ""
for i in apply(traceback.format_exception, sys.exc_info()):
error += i
self.printERROR(error)
return False
if not error:
self.printSUCCESS(_("System configured")+"!")
self.endTask()
self.endFrame()
return True
def installSystem(self,variables):
"""install System by current variable enviroment"""
error = None

@ -61,6 +61,8 @@ class InstallInfo(ClassSerializer):
os_install_net_data = Array(Array(String))
os_install_net_route_data = Array(Array(String))
os_install_net_conf = String
os_install_net_dns = String
os_install_net_dns_search = String
os_install_ntp = String
os_install_x11_video_drv = String
os_install_x11_resolution = String
@ -73,6 +75,8 @@ class InstallInfo(ClassSerializer):
cl_autopartition_table = String
cl_autopartition_root_size = String
cl_live = Boolean
os_install_pxe = Boolean
os_install_pxe_path = String
@ -149,11 +153,13 @@ class Wsdl:
return []
@rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
@core_method(category=__('System'),title=__('System installing'),
image='drive-harddisk',gui=True,command='cl-install',
@core_method(category=__('Installation'),title=__('System installing'),
image='system-installer,applications-other,drive-harddisk',
gui=True,command='cl-install',
rights=['install'])
def install ( self, sid, info):
return self.installCommon(sid,info,'install',self.install_vars)
return self.installCommon(sid,info,'install',self.install_vars,
humanName=_('System installing'))
def install_vars(self,dv=None):
if not dv:
@ -181,13 +187,16 @@ class Wsdl:
dv.addGroup(_("Network settings"),
normal=('os_install_net_conf','os_install_net_data',
'os_install_net_fqdn','os_install_ntp'),
expert=('os_install_net_route_data',))
expert=('os_install_net_dns','os_install_net_dns_search',
'os_install_net_route_data',))
dv.addGroup(_("Users"),
normal=('cl_migrate_data','cl_autologin'))
normal=('cl_migrate_data','cl_autologin'),
hide=('cl_migrate_data',),
brief=('cl_migrate_user',))
dv.addGroup(_("Video"),
normal=('os_install_x11_video_drv','os_install_x11_composite',
'os_install_x11_resolution','os_install_fb_resolution'))
dv.addBrief(next_label=_("Install"),image="finish")
dv.addBrief(next_label=_("Installation"),image="finish")
return dv
def fixInstallLocalization(self,sid,dv):
@ -238,15 +247,16 @@ class Wsdl:
return dv
@rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
@core_method(category=__('System'),title=__('Flash install'),
image='drive-removable-media-usb-pendrive,media-removable',
@core_method(category=__('Installation'),title=__('Flash install'),
image='drive-removable-media-usb-pendrive,media-flash',
gui=True, rights=['install'])
def install_flash ( self, sid, info):
"""
Install to flash
"""
return self.installCommon(sid,info,'install_flash',
self.install_flash_vars)
self.install_flash_vars,
humanName=_('Flash install'))
@rpc(Integer, ViewParams,_returns = ViewInfo)
@catchExcept
@ -300,3 +310,205 @@ class Wsdl:
self.set_cache(sid, 'install_pxe', "vars",dv,smart=False)
return view
def configure_network_vars(self):
dv = cl_install.DataVarsInstall()
dv.importInstall()
dv.flIniFile()
dv.Set('cl_action','merge',True)
dv.Set('cl_belong_pkg',[None],True)
dv.Set('cl_setup','network',True)
dv.addGroup(None,
normal=('os_install_net_conf','os_install_net_data',
'os_install_net_fqdn','os_install_ntp'),
expert=('os_install_net_dns','os_install_net_dns_search',
'os_install_net_route_data',),
next_label=_("Save"))
return dv
@rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
@core_method(category=__('Configuration'),title=__('Network'),
image='network-idle,preferences-system-network',
command="cl-configure-network",
gui=True, rights=['configure'])
def configure_network ( self, sid, info):
"""
Setup network
"""
print "OINRD",info.os_install_net_route_data
return self.installCommon(sid,info,'configure_network',
self.configure_network_vars,
installFunc="setupSystem",
humanName=_('Network'))
@rpc(Integer, ViewParams,_returns = ViewInfo)
@catchExcept
def configure_network_view (self, sid, params):
dv = self.get_cache(sid,"configure_network","vars")
if not dv:
dv = self.configure_network_vars()
else:
dv.processRefresh()
view = ViewInfo(dv,step=params.step,
expert=params.expert,
brief=params.brief)
self.set_cache(sid, 'configure_network', "vars",dv,smart=False)
return view
def configure_video_vars(self):
dv = cl_install.DataVarsInstall()
dv.importInstall()
dv.flIniFile()
dv.Set('cl_action','merge',True)
dv.Set('cl_belong_pkg',[None],True)
dv.Set('cl_setup','video',True)
dv.addGroup(None,
normal=('os_install_x11_video_drv', 'os_install_x11_resolution',
'os_install_x11_composite', 'os_install_fb_resolution'),
next_label=_("Save"))
return dv
@rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
@core_method(category=__('Configuration'),title=__('Video'),
image='gnome-multimedia,video-display',
command="cl-configure-video",
gui=True, rights=['configure'])
def configure_video ( self, sid, info):
"""
Setup video
"""
return self.installCommon(sid,info,'configure_video',
self.configure_video_vars,
installFunc="setupSystem",
humanName=_('Video'))
@rpc(Integer, ViewParams,_returns = ViewInfo)
@catchExcept
def configure_video_view (self, sid, params):
dv = self.get_cache(sid,"configure_video","vars")
if not dv:
dv = self.configure_video_vars()
else:
dv.processRefresh()
view = ViewInfo(dv,step=params.step,
expert=params.expert,
brief=params.brief)
self.set_cache(sid, 'configure_video', "vars",dv,smart=False)
return view
def configure_locale_vars(self):
dv = cl_install.DataVarsInstall()
dv.importInstall()
dv.flIniFile()
dv.Set('cl_action','merge',True)
dv.Set('cl_belong_pkg',[None],True)
dv.Set('cl_setup','locale',True)
dv.addGroup(None,
normal=('os_install_locale_lang',
'os_install_clock_timezone'),
next_label=_("Save"))
return dv
@rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
@core_method(category=__('Configuration'),title=__('Locale'),
image='locale,preferences-desktop-locale',
command="cl-configure-locale",
gui=True, rights=['configure'])
def configure_locale ( self, sid, info):
"""
Setup locale
"""
return self.installCommon(sid,info,'configure_locale',
self.configure_locale_vars,
installFunc="setupSystem",
humanName=_('Locale'))
@rpc(Integer, ViewParams,_returns = ViewInfo)
@catchExcept
def configure_locale_view (self, sid, params):
dv = self.get_cache(sid,"configure_locale","vars")
if not dv:
dv = self.configure_locale_vars()
else:
dv.processRefresh()
view = ViewInfo(dv,step=params.step,
expert=params.expert,
brief=params.brief)
self.set_cache(sid, 'configure_locale', "vars",dv,smart=False)
return view
def configure_boot_vars(self):
dv = cl_install.DataVarsInstall()
dv.importInstall()
dv.flIniFile()
dv.Set('cl_action','merge',True)
dv.Set('cl_belong_pkg',[None],True)
dv.Set('cl_setup','boot',True)
dv.addGroup(None,
normal=('os_install_mbr',
'os_install_kernel_scheduler'),
next_label=_("Save"))
return dv
@rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
@core_method(category=__('Configuration'),title=__('Boot'),
image='stock_save,drive-harddisk',command="cl-configure-boot",
gui=True, rights=['configure'])
def configure_boot ( self, sid, info):
"""
Setup locale
"""
return self.installCommon(sid,info,'configure_boot',
self.configure_boot_vars,
installFunc="setupSystem",
humanName=_('Boot'))
@rpc(Integer, ViewParams,_returns = ViewInfo)
@catchExcept
def configure_boot_view (self, sid, params):
dv = self.get_cache(sid,"configure_boot","vars")
if not dv:
dv = self.configure_boot_vars()
else:
dv.processRefresh()
view = ViewInfo(dv,step=params.step,
expert=params.expert,
brief=params.brief)
self.set_cache(sid, 'configure_boot', "vars",dv,smart=False)
return view
def configure_system_vars(self):
dv = cl_install.DataVarsInstall()
dv.importInstall()
dv.flIniFile()
dv.Set('cl_action','merge',True)
dv.addGroup(None,
normal=("cl_live",),
next_label=_("Reconfigure"))
return dv
@rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
@core_method(category=__('Configuration'),title=__('System'),
image='system,computer',command="cl-configure",
gui=True, rights=['configure'])
def configure_system ( self, sid, info):
"""
Setup locale
"""
return self.installCommon(sid,info,'configure_system',
self.configure_system_vars,
installFunc="setupSystem",
humanName=_('System'))
@rpc(Integer, ViewParams,_returns = ViewInfo)
@catchExcept
def configure_system_view (self, sid, params):
dv = self.get_cache(sid,"configure_system","vars")
if not dv:
dv = self.configure_system_vars()
else:
dv.processRefresh()
view = ViewInfo(dv,step=params.step,
expert=params.expert,
brief=params.brief)
self.set_cache(sid, 'configure_system', "vars",dv,smart=False)
return view

@ -120,7 +120,7 @@ class VariableOsInstallX11VideoDrv(VideoVariable):
"""
Video driver used by xorg
"""
type = 'choice'
type = 'choiceedit'
opt = ['--video']
metavalue = "VIDEODRV"
@ -155,6 +155,26 @@ class VariableOsInstallX11VideoDrv(VideoVariable):
return drv
return "other"
pkgDrvMap = {'nvidia':('NVidia','x11-drivers/nvidia-drivers'),
'fglrx':('ATI','x11-drivers/ati-drivers'),
'vboxdrv':('VirtualBox','x11-drivers/xf86-video-virtualbox')}
def check(self,value):
if self.Get('cl_action') == 'system':
availDrvs = self.Get('os_install_x11_video_available')
if not value in availDrvs:
raise VariableError(_("Available only %s drivers")%
",".join(availDrvs))
else:
if not value in getInstalledVideo(prefix="/") and \
not value in ("auto","other"):
error =_("%s videodriver is unavailable")%value
if value in self.pkgDrvMap:
error += ". " + (_("Install %s driver with:")
%self.pkgDrvMap[value][0])
error += "\n" + ("emerge %s"%self.pkgDrvMap[value][1])
raise VariableError(error)
class VariableHrVideoId(ReadonlyVariable):
"""
BusID of video card

@ -33,6 +33,8 @@ class VariableAcInstallMerge(ReadonlyVariable):
if cl_action == 'system' and \
self.Get('os_install_root_type') == 'flash':
return ""
if self.Get('cl_live') == "on":
return ""
return actionsMap.get(cl_action,'')
class VariableAcInstallSystem(ReadonlyVariable):
@ -41,7 +43,8 @@ class VariableAcInstallSystem(ReadonlyVariable):
"""
def get(self):
if self.Get('cl_action') == 'system' and \
self.Get('os_install_root_type') != "flash":
self.Get('os_install_root_type') != "flash" and \
self.Get('os_install_pxe') != "on":
return "up"
else:
return ""
@ -63,8 +66,9 @@ class VariableAcInstallLive(ReadonlyVariable):
"""
def get(self):
if self.Get('ac_install_merge') == "up" and \
self.Get('ac_install_pxe') != "up" and \
self.Get('cl_chroot_status') == "off" or \
self.Get('cl_action') == 'live':
self.Get('cl_live') == 'on':
return "up"
else:
return ""
@ -79,3 +83,13 @@ class VariableAcInstallPxe(ReadonlyVariable):
return "up"
return ""
class VariableAcInstallConfigure(ReadonlyVariable):
"""
Action variable which has value "up" for configuration
"""
def get(self):
clAction = self.Get('cl_action')
clSetup = self.Get('cl_setup')
if clAction == "merge" and clSetup:
return "up"
return ""

@ -238,7 +238,7 @@ class VariableOsInstallNetNetwork(NetHelper,ReadonlyVariable):
self.label = _("Network")
def get(self):
return map(lambda x:getIpNet(x[0],x[1]) if x[0] else "",
return map(lambda x:getIpNet(x[0],x[1]) if x[0] and x[1] else "",
zip(self.Get('os_install_net_ip'),
self.Get('os_install_net_mask')))
@ -594,6 +594,13 @@ class VariableOsInstallNetDnsSearch(NetHelper,Variable):
"""
Dns search
"""
opt = ["--domain-search"]
metavalue = "DOMAINS"
def init(self):
self.label = _("Search domains")
self.help = _("search domains (comma delimeter)")
def isDNSByDHCP(self):
"""
If first interface get ip by DHCP dns must be DHCP
@ -604,19 +611,36 @@ class VariableOsInstallNetDnsSearch(NetHelper,Variable):
return True
return False
def set(self,value):
return " ".join(re.split('[; ,]',value))
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 ",".join(dnsSearch)
return "" if self.isDNSByDHCP() else dnsSearch
def humanReadable(self):
return self.Get() or (_("Received by DHCP")
if self.isDNSByDHCP()
else _("Not used"))
class VariableOsInstallNetDns(VariableOsInstallNetDnsSearch):
"""
Dns servers
"""
opt = ["--dns"]
metavalue = "DNS"
def init(self):
self.label = _("Domain name servers")
self.help = _("domain name servers (comma delimeter)")
def set(self,value):
return " ".join(re.split('[; ,]',value))
def get(self):
dnsIps = filter(ip.checkIp,
map(lambda x:x.strip().partition("nameserver")[2].strip(),
@ -626,9 +650,14 @@ class VariableOsInstallNetDns(VariableOsInstallNetDnsSearch):
def check(self,value):
reIp = re.compile(ip.IP_ADDR)
if filter(reIp.match,value.split(',')):
if any(ifilterfalse(reIp.match,value.split(','))):
raise VariableError(_("Wrong DNS IP addresses"))
def humanReadable(self):
return self.Get() or (_("Received by DHCP")
if self.isDNSByDHCP()
else _("Not used"))
class VariableOsInstallNetSettings(NetHelper,Variable):
"""
Net service configured

@ -237,6 +237,9 @@ class VariableClAutologin(UserHelper,Variable):
if value == "root":
raise VariableError(_("Autologin is imposible for %s user")%value)
def humanReadable(self):
return self.Get() or _("Not used")
class VariableClInstallAutoupdateSet(Variable):
"""
(on or off) autoupdate config from install program for install
@ -419,6 +422,35 @@ class VariableOsGrub2Path(Variable):
return grubInstall
return ""
class VariableClSetup(Variable):
"""
Type of setup
"""
value = "choice"
def choice(self):
return ["network","locale","video","boot","users",""]
def humanReadable(self):
mapType = {'network':_("network parameters"),
'locale':_("localization and time parameters"),
'video':_("video parameters"),
'boot':_("boot parameters"),
'users':_("user parameters") }
return mapType.get(self.Get(),"")
class VariableClLive(Variable):
"""
Apply live templates
"""
value = "off"
type = "bool"
opt = ['--live']
def init(self):
self.label = _("Configure only mutable parameter")
self.help = _("configure only mutable parameters")
class VariableOsInstallPxe(ReadonlyVariable):
"""
Installation for PXE loading

Loading…
Cancel
Save