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

@ -805,6 +805,27 @@ def listDirectory(directory,fullPath=False):
pass
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):
"""Read file by line"""
try:
@ -965,13 +986,6 @@ def getSquashList():
return map(lambda x:{"lzma":"xz"}.get(x,x),
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):
"""Get hash of lspci, filtred by filtername. If shortInfo, then
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,
map(lambda x:x.split()[:3:2],
open('/proc/modules','r'))))
if "nvidia" in drivers_list:
defaultNvidia = "nvidia"
elif "nouveau" in workedModules:
if "nouveau" in workedModules:
defaultNvidia = "nouveau"
elif "nvidia" in drivers_list:
defaultNvidia = "nvidia"
else:
defaultNvidia = "nv"
if "radeon" in workedModules:
defaultAti = "radeon"
elif "fglrx" in drivers_list:
defaultAti = "fglrx"
else:
defaultAti = "radeon"
defaultDriver = {
'vesa':'vesa',
'nvidia':defaultNvidia,
'ati':'fglrx' if "fglrx" in drivers_list else "radeon",
'ati':defaultAti,
'intel':'intel',
'via':'via',
'vmware':'vmware'}

Loading…
Cancel
Save