home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / checkbox / registries / hal.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-10-12  |  2.9 KB  |  83 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import re
  5. from checkbox.lib.cache import cache
  6. from checkbox.lib.update import recursive_update
  7. from checkbox.properties import String
  8. from checkbox.registries.command import CommandRegistry
  9. from checkbox.registries.data import DataRegistry
  10. from checkbox.registries.map import MapRegistry
  11.  
  12. class DeviceRegistry(DataRegistry):
  13.     '''Registry for HAL device information.
  14.  
  15.     Each item contained in this registry consists of the properties of
  16.     the corresponding HAL device.
  17.     '''
  18.     
  19.     def items(self):
  20.         all = { }
  21.         current = None
  22.         for line in self.split('\n'):
  23.             match = re.match('  (.*) = (.*) \\((.*?)\\)', line)
  24.             if match:
  25.                 keys = match.group(1).split('.')
  26.                 value = match.group(2).strip()
  27.                 type_name = match.group(3)
  28.                 if type_name == 'bool':
  29.                     value = bool(value == 'true')
  30.                 elif type_name == 'double':
  31.                     value = float(value.split()[0])
  32.                 elif type_name == 'int' or type_name == 'uint64':
  33.                     value = int(value.split()[0])
  34.                 elif type_name == 'string':
  35.                     value = str(value.strip("'"))
  36.                 elif type_name == 'string list':
  37.                     value = [ v.strip("'") for v in value.strip('{}').split(', ') ]
  38.                 else:
  39.                     raise Exception, 'Unknown type: %s' % type_name
  40.             recursive_update(all, value)
  41.             match
  42.         
  43.         items = []
  44.         for key, value in all.items():
  45.             value = MapRegistry(value)
  46.             items.append((key, value))
  47.         
  48.         return items
  49.  
  50.     items = cache(items)
  51.  
  52.  
  53. class HalRegistry(CommandRegistry):
  54.     '''Registry for HAL information.
  55.  
  56.     Each item contained in this registry consists of the udi as key and
  57.     the corresponding device registry as value.
  58.     '''
  59.     command = String(default = 'lshal')
  60.     
  61.     def items(self):
  62.         items = []
  63.         for block in self.split('\n\n'):
  64.             lines = block.split('\n')
  65.             while lines:
  66.                 line = lines.pop(0)
  67.                 match = re.match("udi = '(.*)'", line)
  68.                 if match:
  69.                     udi = match.group(1)
  70.                     key = udi.split('/')[-1]
  71.                     break
  72.                     continue
  73.             if lines:
  74.                 value = DeviceRegistry('\n'.join(lines))
  75.                 items.append((key, value))
  76.                 continue
  77.         
  78.         return items
  79.  
  80.     items = cache(items)
  81.  
  82. factory = HalRegistry
  83.