home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / XKit / xutils.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  5.5 KB  |  182 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from xorgparser import *
  5. import sys
  6.  
  7. class XUtils(Parser):
  8.     '''
  9.     Subclass with higher-level methods
  10.     
  11.     See xorgparser.Parser for the low-level methods
  12.     '''
  13.     
  14.     def __init__(self, source = None):
  15.         Parser.__init__(self, source)
  16.  
  17.     
  18.     def checkNFixSection(self):
  19.         '''
  20.         Gathers information on one or more sections and try to fix 
  21.         broken references to other sections.
  22.         '''
  23.         brokenReferences = self.getBrokenReferences()
  24.         for section in brokenReferences:
  25.             for reference in brokenReferences[section]:
  26.                 self.makeSection(section, identifier = reference)
  27.             
  28.         
  29.  
  30.     
  31.     def getDriver(self, section, position):
  32.         '''
  33.         Get the driver in use in a section. If none is found it will return
  34.         false.
  35.         
  36.         For further information see getValue
  37.         '''
  38.         option = 'Driver'
  39.         return self.getValue(section, option, position)
  40.  
  41.     
  42.     def setDriver(self, section, driver, position):
  43.         '''
  44.         Set the driver in use in a section.
  45.         '''
  46.         option = 'Driver'
  47.         self.addOption(section, option, driver, position = position)
  48.  
  49.     
  50.     def isDriverInSection(self, driver, sectionsList = None):
  51.         '''
  52.         Look for the driver in the Device sections.
  53.         Return True if the driver is found, otherwise return False. 
  54.         
  55.         if sectionsList == None check all the Device sections
  56.         '''
  57.         if sectionsList == None:
  58.             sectionsList = self.globaldict['Device'].keys()
  59.         
  60.         for section in sectionsList:
  61.             
  62.             try:
  63.                 if self.getDriver('Device', section) == driver:
  64.                     return True
  65.             continue
  66.             except OptionException:
  67.                 continue
  68.             
  69.  
  70.         
  71.         return False
  72.  
  73.     
  74.     def getDevicesFromServerLayout(self, position):
  75.         '''
  76.         Look for references to Device sections in the Screen sections referred
  77.         to in the ServerLayout[position] section.
  78.         
  79.         Return a list of references to the relevant Device sections
  80.         '''
  81.         devicesToCheck = []
  82.         references = self.getReferences('ServerLayout', position, [
  83.             'Screen'])
  84.         if len(references['Screen']) > 0:
  85.             for reference in references['Screen']:
  86.                 
  87.                 try:
  88.                     screenPosition = self.getPosition('Screen', reference)
  89.                 except IdentifierException:
  90.                     continue
  91.  
  92.                 
  93.                 try:
  94.                     deviceReferences = self.getReferences('Screen', screenPosition, [
  95.                         'Device'])
  96.                     for device in deviceReferences['Device']:
  97.                         devicePosition = self.getPosition('Device', device)
  98.                         devicesToCheck.append(devicePosition)
  99.                 continue
  100.                 except OptionException:
  101.                     continue
  102.                 
  103.  
  104.             
  105.         
  106.         return devicesToCheck
  107.  
  108.     
  109.     def getDevicesInUse(self):
  110.         '''
  111.         If possible, return only the Device sections in use, otherwise return
  112.         all the Device sections.
  113.         
  114.         This method supports old Xinerama setups and therefore looks for
  115.         references to Device sections in the ServerLayout section(s) and checks
  116.         only the default ServerLayout section provided than one is set in the
  117.         ServerFlags section.
  118.         '''
  119.         devicesToCheck = []
  120.         driverEnabled = False
  121.         serverLayout = self.globaldict['ServerLayout']
  122.         serverFlags = self.globaldict['ServerFlags']
  123.         serverLayoutLength = len(serverLayout)
  124.         serverFlagsLength = len(serverFlags)
  125.         if serverLayoutLength > 0:
  126.             if serverLayoutLength > 1:
  127.                 if serverFlagsLength > 0:
  128.                     default = self.getDefaultServerLayout()
  129.                     if len(default) == 1:
  130.                         devicesToCheck = self.getDevicesFromServerLayout(default[0])
  131.                     else:
  132.                         for layout in serverLayout:
  133.                             devicesToCheck += self.getDevicesFromServerLayout(layout)
  134.                         
  135.                 else:
  136.                     for layout in serverLayout:
  137.                         devicesToCheck += self.getDevicesFromServerLayout(layout)
  138.                     
  139.             else:
  140.                 devicesToCheck = self.getDevicesFromServerLayout(0)
  141.         
  142.         if len(devicesToCheck) == 0:
  143.             devicesToCheck = self.globaldict['Device'].keys()
  144.         
  145.         return devicesToCheck
  146.  
  147.     
  148.     def isDriverEnabled(self, driver):
  149.         '''
  150.         If possible, check only the Device sections in use, otherwise check
  151.         all the Device sections and see if a driver is enabled.
  152.         
  153.         This method supports old Xinerama setups and therefore looks for
  154.         references to Device sections in the ServerLayout section(s) and checks
  155.         only the default ServerLayout section provided than one is set in the
  156.         ServerFlags section.
  157.         '''
  158.         devicesToCheck = self.getDevicesInUse()
  159.         driverEnabled = self.isDriverInSection(driver, sectionsList = devicesToCheck)
  160.         return driverEnabled
  161.  
  162.     
  163.     def getScreenDeviceRelationships(self):
  164.         '''
  165.         See which Screen sections are related to which Device sections
  166.         '''
  167.         relationships = { }
  168.         it = 0
  169.         for screen in self.globaldict['Screen']:
  170.             references = self.getReferences('Screen', it, reflist = [
  171.                 'Device'])
  172.             device = references['Device'][0]
  173.             device = self.getPosition('Device', device)
  174.             relationships.setdefault(device)
  175.             relationships[device] = { }
  176.             relationships[device]['Screen'] = it
  177.             it += 1
  178.         
  179.         return relationships
  180.  
  181.  
  182.