Fix video detect.

develop
Mike Hiretsky 13 years ago
parent 82e9f675b9
commit eb3033bce5

@ -23,8 +23,9 @@ import cl_overriding
from cl_vars_share import varsShare, clLocale from cl_vars_share import varsShare, clLocale
from os.path import exists as pathexists from os.path import exists as pathexists
from os import path from os import path
from cl_utils import isMount, genpassword, getAvailableX11Drivers, \ from cl_utils import isMount, genpassword, \
listDirectory,isPkgInstalled,lspci getAvailableVideo, \
listDirectory,isPkgInstalled,lspci, readLinesFile
from utils import ip from utils import ip
from encrypt import getHash from encrypt import getHash
@ -388,23 +389,25 @@ class fillVars(varsShare):
xorg_conf = '/etc/X11/xorg.conf' xorg_conf = '/etc/X11/xorg.conf'
# Try analize Xorg.{DISPLAY}.log # Try analize Xorg.{DISPLAY}.log
display = os.environ.get('DISPLAY') display = os.environ.get('DISPLAY')
list_avialable_drivers = \ list_available_drivers = \
getAvailableX11Drivers(prefix=self.Get('cl_chroot_path')) getAvailableVideo(prefix=self.Get('cl_chroot_path'))
if display and list_avialable_drivers: if display and list_available_drivers:
reDriver = re.compile('|'.join(map(lambda x: "%s_drv.so"%x, reDriver = re.compile('|'.join(map(lambda x: "%s_drv.so"%x,
list_avialable_drivers))) list_available_drivers)))
display_number = re.search(r':(\d+)\..*', display) display_number = re.search(r':(\d+)\..*', display)
reDriverName = re.compile(r'([^/]+)_drv.so')
if display_number: if display_number:
xorg_log_file = '/var/log/Xorg.%s.log' % \ xorg_log_file = '/var/log/Xorg.%s.log' % \
display_number.group(1) display_number.group(1)
if path.exists(xorg_log_file): if path.exists(xorg_log_file):
matchStrs = [i for i in open(xorg_log_file) matchStrs = \
if "drv" in i and reDriver.search(i)] map(lambda x:x.group(1),
filter(lambda x:x,
map(lambda x:reDriverName.search,
filter(lambda x:"drv" in x and reDriver.search(x),
readLinesFile(xorg_log_file)))))
if matchStrs: if matchStrs:
resDriver = re.search(r'([^/]+)_drv.so', return matchStrs[-1]
matchStrs[-1])
if resDriver:
return resDriver.group(1)
# analize /etc/X11/xorg.conf # analize /etc/X11/xorg.conf
if path.exists(xorg_conf): if path.exists(xorg_conf):
@ -413,19 +416,15 @@ class fillVars(varsShare):
if matchSect: if matchSect:
resDriver = re.search(r'^\S*Driver\s*"([^"]+)"', resDriver = re.search(r'^\S*Driver\s*"([^"]+)"',
matchSect.group(0),re.S) matchSect.group(0),re.S)
if resDriver and resDriver.group(1) in list_avialable_drivers: if resDriver and resDriver.group(1) in list_available_drivers:
return resDriver.group(1) return resDriver.group(1)
videoVal = self.getValueFromCmdLine("calculate","video") videoVal = self.getValueFromCmdLine("calculate","video")
videoVal = {'i915':'intel'}.get(videoVal,videoVal) videoVal = {'i915':'intel'}.get(videoVal,videoVal)
if not isPkgInstalled('xorg-server') or \ if not isPkgInstalled('xorg-server') or \
videoVal in list_avialable_drivers: videoVal in list_available_drivers:
return videoVal return videoVal
workedModules = map(lambda x:x[0], return self.getVideoByDefault(list_available_drivers)
filter(lambda x:x[1].isdigit() and int(x[1])>0,
map(lambda x:x.split()[:3:2],
open('/proc/modules','r'))))
return self.getVideoByDefault(list_avialable_drivers)
def get_os_x11_height(self): def get_os_x11_height(self):
"""Get screen height in pixeles""" """Get screen height in pixeles"""

@ -805,6 +805,27 @@ def listDirectory(directory,fullPath=False):
pass pass
return [] return []
def getInstalledVideo(prefix="/"):
"""Get installed video drivers"""
x11Drivers = path.join(prefix,"usr/lib/xorg/modules/drivers")
return map(lambda x:x[:-7],
filter(lambda x:x.endswith('_drv.so'),
listDirectory(x11Drivers)))
def getDistfilesVideo(prefix="/"):
"""Get video drivers from distfiles"""
distFiles = path.join(prefix,"usr/portage/distfiles")
return list(set(
map(lambda x:'fglrx' if x.startswith('ati-driver') else "nvidia",
filter(lambda x:x.startswith('ati-driver-installer') or
x.startswith('NVIDIA-Linux'),
listDirectory(distFiles)))))
def getAvailableVideo(prefix="/"):
"""Get available video drivers (installed and maybe installed)"""
return list(set(getInstalledVideo(prefix=prefix) + \
getDistfilesVideo(prefix=prefix)))
def readLinesFile(filename): def readLinesFile(filename):
"""Read file by line""" """Read file by line"""
try: try:
@ -965,13 +986,6 @@ def getSquashList():
return map(lambda x:{"lzma":"xz"}.get(x,x), return map(lambda x:{"lzma":"xz"}.get(x,x),
list(set(usesSquashFs) & wantMethod)) list(set(usesSquashFs) & wantMethod))
def getAvailableX11Drivers(prefix="/"):
"""Get available x11 drivers"""
xorg_modules_dir = path.join(prefix,'usr/lib/xorg/modules/drivers')
return map(lambda x: x[:-7],
filter(lambda x:x.endswith('_drv.so'),
listDirectory(xorg_modules_dir)))
def lspci(filtername=None,shortInfo=False): def lspci(filtername=None,shortInfo=False):
"""Get hash of lspci, filtred by filtername. If shortInfo, then """Get hash of lspci, filtred by filtername. If shortInfo, then
type,vendor and name get only first word type,vendor and name get only first word

@ -582,16 +582,22 @@ class varsShare:
filter(lambda x:x[1].isdigit() and int(x[1])>0, filter(lambda x:x[1].isdigit() and int(x[1])>0,
map(lambda x:x.split()[:3:2], map(lambda x:x.split()[:3:2],
open('/proc/modules','r')))) open('/proc/modules','r'))))
if "nvidia" in drivers_list: if "nouveau" in workedModules:
defaultNvidia = "nvidia"
elif "nouveau" in workedModules:
defaultNvidia = "nouveau" defaultNvidia = "nouveau"
elif "nvidia" in drivers_list:
defaultNvidia = "nvidia"
else: else:
defaultNvidia = "nv" defaultNvidia = "nv"
if "radeon" in workedModules:
defaultAti = "radeon"
elif "fglrx" in drivers_list:
defaultAti = "fglrx"
else:
defaultAti = "radeon"
defaultDriver = { defaultDriver = {
'vesa':'vesa', 'vesa':'vesa',
'nvidia':defaultNvidia, 'nvidia':defaultNvidia,
'ati':'fglrx' if "fglrx" in drivers_list else "radeon", 'ati':defaultAti,
'intel':'intel', 'intel':'intel',
'via':'via', 'via':'via',
'vmware':'vmware'} 'vmware':'vmware'}

Loading…
Cancel
Save