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

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

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

@ -54,6 +54,27 @@ class Sizes(object):
else:
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
class AutopartitionError(Exception):
@ -365,11 +386,17 @@ class VariableHrMemorySize(ReadonlyVariable):
def humanReadable(self):
return humanreadableSize(self.Get())
class VariableClAutopartitionSwapSize(Variable):
class VariableClAutopartitionSwapSize(SizeHelper,AutopartitionHelper,Variable):
"""
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):
size = self.Get('hr_memory_size')
@ -377,6 +404,9 @@ class VariableClAutopartitionSwapSize(Variable):
size = Sizes.G
return str(size)
def humanReadable(self):
return humanreadableSize(self.Get())
class VariableClAutopartitionDevice(AutopartitionHelper,Variable):
"""
Device for autopartition
@ -538,7 +568,7 @@ class VariableClAutopartitionScheme(AutopartitionHelper,Variable,AutoPartition):
_("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
"""
@ -560,26 +590,6 @@ class VariableClAutopartitionRootSize(AutopartitionHelper,Variable):
size = max(Sizes().to_M(deviceSize),Sizes().to_M(MINROOTSIZE))
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):
if self.Get('cl_autopartition_device') and \
self.Get('cl_autopartition_set') == "on":
@ -588,6 +598,9 @@ class VariableClAutopartitionRootSize(AutopartitionHelper,Variable):
_("The root partition should be at least {size}").format(
size="7 Gb"))
def humanReadable(self):
return humanreadableSize(self.Get())
class VariableClAutopartitionTable(AutopartitionHelper,Variable):
"""
Partition table for autopartition

@ -47,7 +47,7 @@ class UserHelper:
"""
if self.Get('os_install_root_type') == 'flash':
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 ""

@ -70,7 +70,8 @@ class Wsdl(WsdlBase):
lambda group:group(_("Allocate drive space"),
normal=('cl_autopartition_set',),
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")),
lambda group:group(_("Mount points"),
normal=('os_location_data',),

Loading…
Cancel
Save