~lnxtorez/lava-test/add-pm-qa-definition

« back to all changes in this revision

Viewing changes to abrek/hwprofile.py

  • Committer: Paul Larson
  • Date: 2010-09-27 15:34:28 UTC
  • mfrom: (34.1.4 json-compat-fix)
  • Revision ID: paul.larson@canonical.com-20100927153428-zkorzkpodjdpc04s
Fix some json compatibility issues with the launch-control dashboard

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
        for c in range(len(cpudevs)):
96
96
            device = {}
97
97
            device['device_type'] = 'device.cpu'
98
 
            device['attributes'] = 'Processor #{0}'.format(c)
99
 
            device['desc'] = cpudevs[c]
 
98
            device['description'] = 'Processor #{0}'.format(c)
 
99
            device['attributes'] = cpudevs[c]
100
100
            devices.append(device)
101
101
    except IOError:
102
102
        print >> sys.stderr, "WARNING: Could not read cpu information"
108
108
    Return a list of board devices
109
109
    """
110
110
    devices = []
111
 
    desc = {}
 
111
    attributes = {}
112
112
    device = {}
113
113
    machine = os.uname()[-1]
114
114
    if machine in ('i686', 'x86_64'):
115
115
        try:
116
 
            name = read_file('/sys/class/dmi/id/board_name') or None
 
116
            description = read_file('/sys/class/dmi/id/board_name') or None
117
117
            vendor = read_file('/sys/class/dmi/id/board_vendor') or None
118
118
            version = read_file('/sys/class/dmi/id/board_version') or None
119
 
            if name:
120
 
                device['attributes'] = name.strip()
 
119
            if description:
 
120
                device['description'] = description.strip()
121
121
            if vendor:
122
 
                desc['vendor'] = vendor.strip()
 
122
                attributes['vendor'] = vendor.strip()
123
123
            if version:
124
 
                desc['version'] = version.strip()
 
124
                attributes['version'] = version.strip()
125
125
        except IOError:
126
126
            print >> sys.stderr, "WARNING: Could not read board information"
127
127
            return devices
134
134
            match = pattern.search(cpuinfo)
135
135
            if match is None:
136
136
                return devices
137
 
            desc['hardware'] = match.group('hardware')
 
137
            attributes['hardware'] = match.group('hardware')
138
138
        except IOError:
139
139
            print >> sys.stderr, "WARNING: Could not read board information"
140
140
            return devices
141
141
    else:
142
142
        return devices
143
 
    device['desc'] = desc
 
143
    device['attributes'] = attributes
144
144
    device['device_type'] = 'device.board'
145
145
    devices.append(device)
146
146
    return devices
166
166
                kind = 'RAM'
167
167
            else:
168
168
                kind = 'swap'
169
 
            name = "{capacity}MiB of {kind}".format(
 
169
            description = "{capacity}MiB of {kind}".format(
170
170
                capacity=capacity >> 20, kind=kind)
171
171
            device = {}
172
 
            device['attributes'] = name
173
 
            device['desc'] = {'capacity': capacity, 'kind': kind}
 
172
            device['description'] = description
 
173
            device['attributes'] = {'capacity': capacity, 'kind': kind}
174
174
            device['device_type'] = "device.mem"
175
175
            devices.append(device)
176
176
    except IOError:
183
183
    """
184
184
    pattern = re.compile(
185
185
              "^Bus \d{3} Device \d{3}: ID (?P<vendor_id>[0-9a-f]{4}):"
186
 
              "(?P<product_id>[0-9a-f]{4}) (?P<name>.*)$")
 
186
              "(?P<product_id>[0-9a-f]{4}) (?P<description>.*)$")
187
187
    devices = []
188
188
    for line in commands.getoutput('lsusb').splitlines():
189
189
        match = pattern.match(line)
190
190
        if match:
191
 
            vendor_id, product_id, name = match.groups()
192
 
            desc = {}
 
191
            vendor_id, product_id, description = match.groups()
 
192
            attributes = {}
193
193
            device = {}
194
 
            desc['vendor_id'] = int(vendor_id, 16)
195
 
            desc['product_id'] = int(product_id, 16)
196
 
            device['desc'] = desc
197
 
            device['attributes'] = name
 
194
            attributes['vendor_id'] = int(vendor_id, 16)
 
195
            attributes['product_id'] = int(product_id, 16)
 
196
            device['attributes'] = attributes
 
197
            device['description'] = description
198
198
            device['device_type'] = 'device.usb'
199
199
            devices.append(device)
200
200
    return devices