def dmidecode(): import os ''' loads the output from the dmidecode utility into the following structure: {dmi_type(int): [handle(int), title(str), {key(str), [value(str), ...]}]} Thus, the UUID field of the DMI type 1 can be had via: dmidecode()[1][2]["UUID"] The title of DMI type 3 can be had via: dmidecode()[3][1] ''' dmi = {} cmd = "/usr/sbin/dmidecode" try: handle = None field = None # XXX log fd = os.popen2(cmd)[1] for line in fd: if not line: continue elif line.startswith('Handle '): # new handle section handle_val = _hex_int(line[7:].strip()) handle = [handle_val, None, {}] field = None elif line.startswith('\tDMI type '): # assign to current handle dt = line[10:].split(',',1)[0] dt = int(dt) dmi[dt] = handle elif line.startswith('\t\t\t'): # append to list of values in current field if not field: continue fval = handle[2][field] fval.append(line.strip()) elif line.startswith('\t\t'): # new field in current handle field, val = line.split(':', 1) field, val = field.strip(), val.strip() if val: val = [val] else: val = [] handle[2][field] = val elif line.startswith('\t'): # handle title handle[1] = line.strip() except: # XXX log pass return dmi