def parse_dmidecode(data): """Parse data returned by the dmidecode command into a dict.""" p = parse.multi_pairs(data) def exclude(value, exceptions): if value not in exceptions: return value def num(value): if value is None: return None try: num, unit = value.split(None, 1) except ValueError: num = value return int(num) if 'System Information' not in p: raise DMIDecodeError('System information not found') result = { 'model': p['System Information']['Product Name'], 'sn': p['System Information']['Serial Number'], 'uuid': p['System Information']['UUID'], 'cpu': [{ 'label': cpu['Socket Designation'], 'model': cpu['Version'], 'speed': num(cpu['Current Speed']), 'threads': num(cpu.get('Thread Count')), 'cores': num(cpu.get('Core Count')), 'family': cpu['Family'], '64bit': any('64-bit capable' in char for char in cpu.getlist('Characteristics') if char), 'flags': [f.keys() for f in cpu.getlist('Flags') if f][0] if 'Flags' in cpu else [], } for cpu in p.getlist('Processor Information') if cpu], 'mem': [{ 'label': mem['Locator'], 'type': mem['Type'], 'size': num(mem['Size']), 'speed': num(exclude(mem.get('Speed'), {'Unknown'})), } for mem in p.getlist('Memory Device') if mem and mem.get('Size') != 'No Module Installed'], } return result
def parse_dmidecode(data): """Parse data returned by the dmidecode command into a dict.""" p = parse.multi_pairs(data) def exclude(value, exceptions): if value not in exceptions: return value def num(value): if value is None or value.lower() == "unknown": return None try: num, unit = value.split(None, 1) except ValueError: num = value return int(num) if "System Information" not in p: raise DMIDecodeError("System information not found") result = { "model": p["System Information"]["Product Name"], "sn": p["System Information"]["Serial Number"], "uuid": p["System Information"]["UUID"], "cpu": [ { "label": cpu["Socket Designation"], "model": cpu["Version"], "speed": num(cpu["Current Speed"]), "threads": num(cpu.get("Thread Count")), "cores": num(cpu.get("Core Count")), "family": cpu["Family"], "64bit": any("64-bit capable" in char for char in cpu.getlist("Characteristics") if char), "flags": [f.keys() for f in cpu.getlist("Flags") if f][0] if "Flags" in cpu else [], } for cpu in p.getlist("Processor Information") if cpu ], "mem": [ { "label": mem["Locator"], "type": mem["Type"], "size": num(mem["Size"]), "speed": num(exclude(mem.get("Speed"), {"Unknown"})), } for mem in p.getlist("Memory Device") if mem and mem.get("Size") != "No Module Installed" ], } return result
def parse_dmidecode(data): """Parse data returned by the dmidecode command into a dict.""" p = parse.multi_pairs(data) def exclude(value, exceptions): if value not in exceptions: return value def num(value): if value is None or value.lower() == 'unknown': return None try: num, unit = value.split(None, 1) except ValueError: num = value return int(num) if 'System Information' not in p: raise DMIDecodeError('System information not found') result = { 'model': p['System Information']['Product Name'], 'sn': p['System Information']['Serial Number'], 'uuid': p['System Information']['UUID'], 'cpu': [{ 'label': cpu['Socket Designation'], 'model': cpu['Version'], 'speed': num(cpu['Current Speed']), 'threads': num(cpu.get('Thread Count')), 'cores': num(cpu.get('Core Count')), 'family': cpu['Family'], '64bit': any('64-bit capable' in char for char in cpu.getlist('Characteristics') if char), 'flags': [f.keys() for f in cpu.getlist('Flags') if f][0] if 'Flags' in cpu else [], } for cpu in p.getlist('Processor Information') if cpu], 'mem': [{ 'label': mem['Locator'], 'type': mem['Type'], 'size': num(mem['Size']), 'speed': num(exclude(mem.get('Speed'), {'Unknown'})), } for mem in p.getlist('Memory Device') if mem and mem.get('Size') != 'No Module Installed'], } return result
def _parse_dmidecode(data): """Parse data returned by the dmidecode command into a dict.""" parsed_data = parse.multi_pairs(data) if 'System Information' not in parsed_data: return {} result = { 'model_name': parsed_data['System Information']['Product Name'], } serial_number = parsed_data['System Information']['Serial Number'] if 'not specified' not in serial_number.lower(): if serial_number not in SERIAL_BLACKLIST: result['serial_number'] = serial_number def exclude(value, exceptions): if value not in exceptions: return value def num(value): if value is None or value.lower() == 'unknown': return None try: num, unit = value.split(None, 1) except ValueError: num = value return int(num) processors = [] for cpu in parsed_data.getlist('Processor Information'): if not cpu: continue processor = { 'label': cpu['Socket Designation'], 'family': cpu['Family'], } speed = num(cpu['Current Speed']) if speed: processor['speed'] = speed cores = num(cpu.get('Core Count')) if cores: processor['cores'] = cores if 'not specified' not in cpu['Version'].lower(): processor['model_name'] = cpu['Version'] processors.append(processor) if processors: result['processors'] = processors memory = [] for mem in parsed_data.getlist('Memory Device'): if any(( not mem, mem and mem.get('Size') == 'No Module Installed', )): continue memory_chip = { 'label': mem['Locator'], } size = num(mem['Size']) if size: memory_chip['size'] = size speed = num(exclude(mem.get('Speed'), {'Unknown'})) if speed: memory_chip['speed'] = speed memory.append(memory_chip) if memory: result['memory'] = memory return result