home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import os
- import re
- import logging
- from checkbox.lib.cache import cache
- from checkbox.properties import String
- from checkbox.registries.command import CommandRegistry
- from checkbox.registries.data import DataRegistry
- from checkbox.registries.map import MapRegistry
-
- class DeviceRegistry(DataRegistry):
- '''Registry for HW device information.
-
- Each item contained in this registry consists of the properties of
- the corresponding HW device.
- '''
-
- def items(self):
- items = []
- lines = []
- id = None
- status = None
- depth = None
- for line in self.split('\n'):
- if not line:
- continue
-
- match = re.match('(\\s+(\\*-)?)(.+)', line)
- if not match:
- raise Exception, 'Invalid line: %s' % line
- match
- space = len(match.group(1))
- if depth is None:
- depth = space
-
- if space > depth:
- lines.append(line)
- continue
- if match.group(2) is not None:
- if id is not None:
- value = DeviceRegistry('\n'.join(lines))
- lines = []
- items.append((id, value))
- items.append(('status', status))
-
- node = match.group(3)
- match = re.match('([^\\s]+)( [A-Z]+)?', node)
- if not match:
- raise Exception, 'Invalid node: %s' % node
- match
- id = match.group(1)
- status = match.group(2)
- continue
- (key, value) = match.group(3).split(': ', 1)
- key = key.replace(' ', '_')
- values = value.split(' ')
- if key == 'product':
- match = re.search('(.*) \\[[0-9A-F]{1,4}:([0-9A-F]{1,4})\\]$', value)
- if match:
- value = match.group(1)
- items.append(('product_id', int(match.group(2), 16)))
-
- elif key == 'vendor':
- match = re.search('(.*) \\[([0-9A-F]{1,4})\\]$', value)
- if match:
- value = match.group(1)
- items.append(('vendor_id', int(match.group(2), 16)))
-
- elif key.endswith('s'):
- value = values
- elif _[1]:
- index = 1
- for value in values[1:]:
- if '=' not in value:
- values[index - 1] += ' %s' % values.pop(index)
- continue
- []
- index += 1
-
- value = dict((lambda .0: for v in .0:
- v.split('=', 1))(values))
- value = MapRegistry(value)
-
- items.append((key, value))
-
- if lines:
- value = DeviceRegistry('\n'.join(lines))
- items.append((id, value))
-
- return items
-
- items = cache(items)
-
-
- class HwRegistry(CommandRegistry):
- '''Registry for HW information.
-
- Each item contained in this registry consists of the hardware id as
- key and the corresponding device registry as value.
- '''
- command = String(default = 'lshw -numeric 2>/dev/null')
- version = String(default = 'lshw -version 2>/dev/null')
-
- def __str__(self):
- logging.info('Running command: %s', self.version)
- version = os.popen(self.version).read().strip()
- numbers = version.split('.')
- if len(numbers) == 3 and numbers[0] == 'B' and int(numbers[1]) == 2 and int(numbers[2]) < 13:
- self.command = self.command.replace(' -numeric', '')
-
- return super(HwRegistry, self).__str__()
-
- __str__ = cache(__str__)
-
- def items(self):
- lines = self.split('\n')
- key = lines.pop(0)
- value = DeviceRegistry('\n'.join(lines))
- return [
- (key, value)]
-
- items = cache(items)
-
- factory = HwRegistry
-