home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / DistUpgrade / xorg_fix_proprietary.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-10-12  |  4.4 KB  |  120 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import apt
  5. import sys
  6. import os
  7. import os.path as os
  8. import logging
  9. import time
  10. import shutil
  11. import subprocess
  12. import apt_pkg
  13. XORG_CONF = '/etc/X11/xorg.conf'
  14.  
  15. def remove_input_devices(xorg_source = XORG_CONF, xorg_destination = XORG_CONF):
  16.     logging.debug('remove_input_devices')
  17.     content = []
  18.     in_input_devices = False
  19.     for raw in open(xorg_source):
  20.         line = raw.strip()
  21.         if line.lower().startswith('section') and line.lower().split('#')[0].strip().endswith('"inputdevice"'):
  22.             logging.debug("found 'InputDevice' section")
  23.             content.append('# commented out by update-manager, HAL is now used\n')
  24.             content.append('#' + raw)
  25.             in_input_devices = True
  26.             continue
  27.         if line.lower().startswith('endsection') and in_input_devices:
  28.             content.append('#' + raw)
  29.             in_input_devices = False
  30.             continue
  31.         if line.lower().startswith('inputdevice'):
  32.             logging.debug("commenting out '%s' " % line)
  33.             content.append('# commented out by update-manager, HAL is now used\n')
  34.             content.append('#' + raw)
  35.             continue
  36.         if in_input_devices:
  37.             logging.debug("commenting out '%s' " % line)
  38.             content.append('#' + raw)
  39.             continue
  40.         content.append(raw)
  41.     
  42.     open(xorg_destination + '.new', 'w').write(''.join(content))
  43.     os.rename(xorg_destination + '.new', xorg_destination)
  44.     return True
  45.  
  46.  
  47. def replace_driver_from_xorg(old_driver, new_driver, xorg = XORG_CONF):
  48.     '''
  49.     this removes the fglrx driver from the xorg.conf and subsitutes
  50.     it with the ati one
  51.     '''
  52.     if not os.path.exists(xorg):
  53.         logging.warning('file %s not found' % xorg)
  54.         return None
  55.     content = []
  56.     for line in open(xorg):
  57.         s = line.split('#')[0].strip()
  58.         if s.lower().startswith('driver') and s.endswith('"%s"' % old_driver):
  59.             logging.debug("line '%s' found" % line)
  60.             line = '\tDriver\t"%s"\n' % new_driver
  61.             logging.debug("replacing with '%s'" % line)
  62.         
  63.         content.append(line)
  64.     
  65.     if open(xorg).readlines() != content:
  66.         logging.info('saveing new %s (%s -> %s)' % (xorg, old_driver, new_driver))
  67.         open(xorg + '.xorg_fix', 'w').write(''.join(content))
  68.         os.rename(xorg + '.xorg_fix', xorg)
  69.     
  70.  
  71.  
  72. def is_multiseat(xorg_source = XORG_CONF):
  73.     ''' check if we have a multiseat xorg config '''
  74.     
  75.     def is_serverlayout_line(line):
  76.         if not line.strip().startswith('#'):
  77.             pass
  78.         return line.strip().lower().endswith('"serverlayout"')
  79.  
  80.     msl = len(filter(is_serverlayout_line, open(xorg_source)))
  81.     logging.debug('is_multiseat: lines %i', msl)
  82.     return msl > 1
  83.  
  84. if __name__ == '__main__':
  85.     if not os.getuid() == 0:
  86.         print 'Need to run as root'
  87.         sys.exit(1)
  88.     
  89.     sys.argv[0] = '/usr/bin/update-manager'
  90.     logging.basicConfig(level = logging.DEBUG, filename = '/var/log/dist-upgrade/xorg_fix_intrepid.log', filemode = 'w')
  91.     logging.info('%s running' % sys.argv[0])
  92.     if not os.path.exists(XORG_CONF):
  93.         logging.info('No xorg.conf, exiting')
  94.         sys.exit(0)
  95.     
  96.     backup = XORG_CONF + '.dist-upgrade-' + time.strftime('%Y%m%d%H%M')
  97.     logging.debug("creating backup '%s'" % backup)
  98.     shutil.copy(XORG_CONF, backup)
  99.     if not os.path.exists('/usr/lib/xorg/modules/drivers/fglrx_drv.so') and 'fglrx' in open(XORG_CONF).read():
  100.         logging.info('Removing fglrx from %s' % XORG_CONF)
  101.         replace_driver_from_xorg('fglrx', 'ati')
  102.     
  103.     if not os.path.exists('/usr/lib/xorg/modules/drivers/nvidia_drv.so') and 'nvidia' in open(XORG_CONF).read():
  104.         logging.info('Removing nvidia from %s' % XORG_CONF)
  105.         replace_driver_from_xorg('nvidia', 'nv')
  106.     
  107.     ver = subprocess.Popen([
  108.         'dpkg-query',
  109.         '-W',
  110.         '-f=${Version}',
  111.         'xserver-xorg-core'], stdout = subprocess.PIPE).communicate()[0]
  112.     logging.info("xserver-xorg-core version is '%s'" % ver)
  113.     if ver and apt_pkg.VersionCompare(ver, '2:1.5.0') > 0:
  114.         if not is_multiseat():
  115.             remove_input_devices()
  116.         else:
  117.             logging.info('multiseat setup, ignoring')
  118.     
  119.  
  120.