Исправлен выбор видеодрайвера для серверов

master3.3
Mike khiretskiy 11 years ago
parent 33932a41e4
commit 4c58b071f6

@ -18,14 +18,14 @@ import os
import sys import sys
import re import re
from os import path from os import path
from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable from calculate.lib.datavars import Variable, VariableError, ReadonlyVariable
from calculate.lib.utils.portage import isPkgInstalled from calculate.lib.utils.portage import isPkgInstalled
from calculate.lib.utils.files import process,STDOUT,getProgPath from calculate.lib.utils.files import process, STDOUT, getProgPath, readFile
from calculate.lib.utils.common import (getVideoFromXorgLog, from calculate.lib.utils.common import (getVideoFromXorgLog,
getVideoFromXorgConf, getVideoFromCmdLine, getVideoFromXorgConf, getVideoFromCmdLine,
getAvailableVideo, getValueFromCmdLine, getAvailableVideo, getValueFromCmdLine,
getCompositeFromXorgconf, getVideoFromModules, getCompositeFromXorgconf, getVideoFromModules,
getVideoFromVendor,getInstalledVideo) getVideoFromVendor, getInstalledVideo)
from calculate.install.distr import DistributiveError from calculate.install.distr import DistributiveError
from calculate.lib.cl_lang import setLocalTranslate from calculate.lib.cl_lang import setLocalTranslate
@ -44,7 +44,7 @@ class VideoVariable(Variable):
if self.Get('os_install_root_type') == 'flash': if self.Get('os_install_root_type') == 'flash':
return \ return \
_("Video configuration unavailable for Flash install") _("Video configuration unavailable for Flash install")
if self.Get('os_install_x11_server_set') == 'no' and self.xorg_need: if self.Get('os_install_x11_server_set') == 'off' and self.xorg_need:
return \ return \
_("This distribution does not provide a Xorg server") _("This distribution does not provide a Xorg server")
return "" return ""
@ -126,7 +126,7 @@ class VariableOsX11KmsVideoDrv(ReadonlyVariable):
type = "list" type = "list"
value = ["radeon","i915","intel","nouveau","ati"] value = ["radeon","i915","intel","nouveau","ati"]
class VariableOsInstallX11VideoDrv(VideoVariable): class VariableOsInstallX11VideoDrv(Variable):
""" """
Video driver used by xorg Video driver used by xorg
""" """
@ -136,54 +136,81 @@ class VariableOsInstallX11VideoDrv(VideoVariable):
def init(self): def init(self):
self.help = _("set the video driver") self.help = _("set the video driver")
self.label = _("{0} video driver").format("Xorg") self.label = _("Video driver")
def choice(self): def choice(self):
"""Get available (already installed or installable drivers""" """Get available (already installed or installable drivers"""
return self.Get('os_install_x11_video_available') if self.Get('os_install_x11_server_set') == 'on':
return self.Get('os_install_x11_video_available')
else:
return self.Get('os_x11_kms_video_drv') + ["other"]
def get(self): def get(self):
# get available videodriver list from install or configure distributive if self.Get('os_install_x11_server_set') == 'on':
list_video = self.Choice('os_install_x11_video_drv') # get available videodriver list from install or configure distributive
if not list_video: list_video = self.Choice('os_install_x11_video_drv')
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" 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: else:
# test current video driver for install system for drv in self.choice():
methods = ((getVideoFromXorgLog,('/',list_video)), videoSysPath = path.join("/sys/module",drv,"refcnt")
(getVideoFromXorgConf,('/',)), refcnt = readFile(videoSysPath).strip()
(getVideoFromModules,()), if refcnt.isdigit() and int(refcnt) > 0:
(getVideoFromCmdLine,()), return {'i915':'intel'}.get(drv,drv)
(getVideoFromVendor,(self.Get('hr_video'),list_video))) else:
for func,args in methods: return "other"
drv = func(*args)
if drv in list_video:
return drv
return "other"
pkgDrvMap = {'nvidia':('NVidia','x11-drivers/nvidia-drivers'), pkgDrvMap = {'nvidia':('NVidia','x11-drivers/nvidia-drivers'),
'fglrx':('ATI','x11-drivers/ati-drivers'), 'fglrx':('ATI','x11-drivers/ati-drivers'),
'vboxdrv':('VirtualBox','x11-drivers/xf86-video-virtualbox')} 'vboxdrv':('VirtualBox','x11-drivers/xf86-video-virtualbox')}
def check(self,value): def check(self,value):
if self.Get('cl_action') == 'system': if self.Get('os_install_x11_server_set') == 'on':
availDrvs = self.Get('os_install_x11_video_available') if self.Get('cl_action') == 'system':
if not value in availDrvs: availDrvs = self.Get('os_install_x11_video_available')
raise VariableError(_("Only %s drivers are available")% if not value in availDrvs:
",".join(availDrvs)) raise VariableError(_("Only %s drivers are available")%
",".join(availDrvs))
else:
if not value in getInstalledVideo(prefix="/") and \
not value in ("auto","other"):
error =_("video driver %s is unavailable")%value
if value in self.pkgDrvMap:
error += ". " + (_("Install driver %s with:")
%self.pkgDrvMap[value][0])
error += "\n" + ("emerge %s"%self.pkgDrvMap[value][1])
raise VariableError(error)
else: else:
if not value in getInstalledVideo(prefix="/") and \ availDrivers = self.Get('os_x11_kms_video_drv') + ["other"]
not value in ("auto","other"): if not value in availDrivers:
error =_("video driver %s is unavailable")%value raise VariableError("Only %s drivers are available" %
if value in self.pkgDrvMap: ",".join(availDrivers))
error += ". " + (_("Install driver %s with:")
%self.pkgDrvMap[value][0]) def uncompatible(self):
error += "\n" + ("emerge %s"%self.pkgDrvMap[value][1]) """
raise VariableError(error) Video setting up unavailable for flash installation
"""
if self.Get('os_install_root_type') == 'flash':
return \
_("Video configuration unavailable for Flash install")
return ""
class VariableHrVideoId(ReadonlyVariable): class VariableHrVideoId(ReadonlyVariable):
""" """
@ -272,7 +299,7 @@ class VariableOsInstallX11ServerSet(ReadonlyVariable):
with image as distr: with image as distr:
distrPath = image.getDirectory() distrPath = image.getDirectory()
if isPkgInstalled('xorg-server',prefix=distrPath): if isPkgInstalled('xorg-server',prefix=distrPath):
return "yes" return "on"
except: except:
pass pass
return "no" return "off"

@ -54,6 +54,27 @@ class Sizes(object):
else: else:
raise AttributeError raise AttributeError
class SizeHelper:
def set(self,value):
# convert table from value to MB
sizeMap = {'kB':1/1000.0,
'K':1/1024.0,
'M':1.0,
'Mb':1000/1024.0,
'G':1024,
'Gb':1000,
'T':1024*1024,
'Tb':1000*1000}
value = value.strip()
reSizeValue = re.compile('^(\d+)\s*(%s)?'%"|".join(sizeMap.keys()))
res = reSizeValue.search(value)
if not res:
return "0"
intValue = int(res.group(1))
if res.group(2):
intValue = intValue * sizeMap[res.group(2)]
return str(int(intValue))
MINROOTSIZE=7*Sizes.G MINROOTSIZE=7*Sizes.G
class AutopartitionError(Exception): class AutopartitionError(Exception):
@ -365,11 +386,17 @@ class VariableHrMemorySize(ReadonlyVariable):
def humanReadable(self): def humanReadable(self):
return humanreadableSize(self.Get()) return humanreadableSize(self.Get())
class VariableClAutopartitionSwapSize(Variable): class VariableClAutopartitionSwapSize(SizeHelper,AutopartitionHelper,Variable):
""" """
Swap size Swap size
""" """
type = "int" opt = ["--swap-size"]
metavalue = "SIZE"
untrusted = True
def init(self):
self.label = _("Swap partition size")+ " (MB)"
self.help = _("set the swap partition size for autopartition")
def get(self): def get(self):
size = self.Get('hr_memory_size') size = self.Get('hr_memory_size')
@ -377,6 +404,9 @@ class VariableClAutopartitionSwapSize(Variable):
size = Sizes.G size = Sizes.G
return str(size) return str(size)
def humanReadable(self):
return humanreadableSize(self.Get())
class VariableClAutopartitionDevice(AutopartitionHelper,Variable): class VariableClAutopartitionDevice(AutopartitionHelper,Variable):
""" """
Device for autopartition Device for autopartition
@ -538,7 +568,7 @@ class VariableClAutopartitionScheme(AutopartitionHelper,Variable,AutoPartition):
_("The bios_grub partition need the partition table to be GPT")) _("The bios_grub partition need the partition table to be GPT"))
class VariableClAutopartitionRootSize(AutopartitionHelper,Variable): class VariableClAutopartitionRootSize(SizeHelper,AutopartitionHelper,Variable):
""" """
Root partition size for autopartition Root partition size for autopartition
""" """
@ -560,26 +590,6 @@ class VariableClAutopartitionRootSize(AutopartitionHelper,Variable):
size = max(Sizes().to_M(deviceSize),Sizes().to_M(MINROOTSIZE)) size = max(Sizes().to_M(deviceSize),Sizes().to_M(MINROOTSIZE))
return str(size) return str(size)
def set(self,value):
# convert table from value to MB
sizeMap = {'kB':1/1000.0,
'K':1/1024.0,
'M':1.0,
'Mb':1000/1024.0,
'G':1024,
'Gb':1000,
'T':1024*1024,
'Tb':1000*1000}
value = value.strip()
reSizeValue = re.compile('^(\d+)\s*(%s)?'%"|".join(sizeMap.keys()))
res = reSizeValue.search(value)
if not res:
return "0"
intValue = int(res.group(1))
if res.group(2):
intValue = intValue * sizeMap[res.group(2)]
return str(int(intValue))
def check(self,value): def check(self,value):
if self.Get('cl_autopartition_device') and \ if self.Get('cl_autopartition_device') and \
self.Get('cl_autopartition_set') == "on": self.Get('cl_autopartition_set') == "on":
@ -588,6 +598,9 @@ class VariableClAutopartitionRootSize(AutopartitionHelper,Variable):
_("The root partition should be at least {size}").format( _("The root partition should be at least {size}").format(
size="7 Gb")) size="7 Gb"))
def humanReadable(self):
return humanreadableSize(self.Get())
class VariableClAutopartitionTable(AutopartitionHelper,Variable): class VariableClAutopartitionTable(AutopartitionHelper,Variable):
""" """
Partition table for autopartition Partition table for autopartition

@ -47,7 +47,7 @@ class UserHelper:
""" """
if self.Get('os_install_root_type') == 'flash': if self.Get('os_install_root_type') == 'flash':
return _("User configuration unavailable for Flash install") return _("User configuration unavailable for Flash install")
if self.Get('os_install_x11_server_set') == 'no' and self.xorg_need: if self.Get('os_install_x11_server_set') == 'off' and self.xorg_need:
return _("Autologin is available for Xorg sessions only") return _("Autologin is available for Xorg sessions only")
return "" return ""

@ -70,7 +70,8 @@ class Wsdl(WsdlBase):
lambda group:group(_("Allocate drive space"), lambda group:group(_("Allocate drive space"),
normal=('cl_autopartition_set',), normal=('cl_autopartition_set',),
expert=('cl_autopartition_scheme','cl_autopartition_device', expert=('cl_autopartition_scheme','cl_autopartition_device',
'cl_autopartition_table','cl_autopartition_root_size'), 'cl_autopartition_table','cl_autopartition_root_size',
'cl_autopartition_swap_size'),
expert_label=_("Click to set up autopartition options")), expert_label=_("Click to set up autopartition options")),
lambda group:group(_("Mount points"), lambda group:group(_("Mount points"),
normal=('os_location_data',), normal=('os_location_data',),

Loading…
Cancel
Save