예제 #1
0
    def get_os_x11_video_drv(self):
        """Get video driver used by xorg"""
        xorg_conf = '/etc/X11/xorg.conf'
        # Try analize Xorg.{DISPLAY}.log
        display = os.environ.get('DISPLAY')
        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_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 = \
                        map(lambda x:x.group(1),
                        filter(lambda x:x,
                        map(reDriverName.search,
                        filter(lambda x:"drv" in x and reDriver.search(x),
                        readLinesFile(xorg_log_file)))))
                    if matchStrs:
                        return matchStrs[-1]

        # analize /etc/X11/xorg.conf
        if path.exists(xorg_conf):
            matchSect = re.search(r'Section "Device".*?EndSection',
                                  open('/etc/X11/xorg.conf').read(),re.S)
            if matchSect:
                resDriver = re.search(r'^\s*Driver\s*"([^"]+)"',
                                      matchSect.group(0),re.M)
                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_available_drivers:
            return videoVal
        return self.getVideoByDefault(list_available_drivers)