def extract_data(directory: str, has_dedicated_gpu: bool, gpu_in_cpu: bool, cleanup: bool, verbose: bool, unpack: bool = True): mobo = get_baseboard(directory + "/baseboard.txt") cpu = read_lscpu(directory + "/lscpu.txt") gpu = read_lspci_and_glxinfo(has_dedicated_gpu, directory + "/lspci.txt", directory + "/glxinfo.txt", verbose) if not has_dedicated_gpu: entries = extract_integrated_gpu_from_standalone(gpu) if gpu_in_cpu: if isinstance(cpu, list): # Multiple processors updated_cpus = [] for one_cpu in cpu: one_cpu = {**one_cpu, **entries} updated_cpus.append(one_cpu) cpu = updated_cpus del updated_cpus else: cpu = {**cpu, **entries} else: mobo = {**mobo, **entries} gpu = [] mobo = get_connectors(directory + "/connector.txt", mobo, verbose) mobo = get_net(directory + "/net.txt", mobo, verbose) chassis = get_chassis(directory + "/chassis.txt") dimms = read_decode_dimms(directory + "/dimms.txt", verbose) if chassis["motherboard-form-factor"] == "proprietary-laptop": psu = {"type": "external-psu"} else: psu = {"type": "psu"} disks = read_smartctl(directory) result = [] empty_dict = {} for component in (chassis, mobo, cpu, dimms, gpu, disks, psu): # return JSON ready for TARALLO if unpack: if isinstance(component, list): if component.__len__() == 0: result.append(empty_dict) continue for item in component: result.append(item) else: result.append(component) # return list of lists of dicts to use in extract_and_collect_data_from_generated_files() for long output else: if component.__len__() == 0: result.append(empty_dict) else: result.append(component) if cleanup: result = do_cleanup(result, verbose) return result
def test_chassis(): expect = { 'type': 'case', 'brand': 'ASUSTeK COMPUTER INC.', 'model': '', 'sn': 'G6M0DF00361708D', 'motherboard-form-factor': 'proprietary-laptop' } output = read_dmidecode.get_chassis(filedir + 'chassis.txt') assert output == expect
def test_chassis(): expect = { "type": "case", "brand": "Chassis Manufacture", "model": "", "sn": "Chassis Serial Number", "motherboard-form-factor": "" } output = read_dmidecode.get_chassis(os.path.join(filedir, 'chassis.txt')) assert output == expect
def test_chassis(): expect = { 'brand': 'Apple Inc.', 'sn': 'CENSORED', 'type': 'case', 'motherboard-form-factor': 'proprietary-laptop', 'model': '', } output = read_dmidecode.get_chassis(os.path.join(filedir, 'chassis.txt')) assert output == expect
def test_chassis(): expect = { "type": "case", "brand": "Microsoft Corporation", "model": "", "sn": "CENSORED", "motherboard-form-factor": "proprietary-laptop" } output = read_dmidecode.get_chassis(os.path.join(filedir, 'chassis.txt')) assert output == expect
def test_chassis(): expect = { "type": "case", "brand": "LENOVO", "model": "", "sn": "A2K3GED", "motherboard-form-factor": "proprietary-laptop" } output = read_dmidecode.get_chassis(os.path.join(filedir, 'chassis.txt')) assert output == expect
def test_chassis(): expect = { "type": "case", "brand": "Hewlett-Packard", "model": "", "sn": "CZC6203MC5", "motherboard-form-factor": "" } output = read_dmidecode.get_chassis(filedir + 'chassis.txt') assert output == expect
def test_77_chassis(): expect = { 'brand': 'Chassis Manufacture', 'model': '', 'sn': 'Chassis Serial Number', 'type': 'case', 'motherboard-form-factor': '', } output = read_dmidecode.get_chassis(os.path.join(filedir, 'chassis.txt')) assert output == expect
def test_chassis(): expect = { "type": "case", "brand": "LENOVO", "model": "", "sn": "Not Available", "motherboard-form-factor": "proprietary-laptop" } output = read_dmidecode.get_chassis(filedir + 'chassis.txt') assert output == expect
def test_chassis(): expect = { "type": "case", "brand": "Chassis Manufacture", "model": "", "sn": "EVAL", "motherboard-form-factor": "" } output = read_dmidecode.get_chassis(filedir + 'chassis.txt') assert output == expect
def test_chassis(): expect = { "type": "case", "brand": "Dell Inc.", "model": "", "sn": "5ASDL3L", "motherboard-form-factor": "" } output = read_dmidecode.get_chassis(os.path.join(filedir, 'chassis.txt')) assert output == expect
def test_chassis(): # This is also wrong, but for pre-assembled computers it should be right expect = { "type": "case", "brand": "To Be Filled By O.E.M.", "model": "", "sn": "To Be Filled By O.E.M.", "motherboard-form-factor": "" } output = read_dmidecode.get_chassis(os.path.join(filedir, 'chassis.txt')) assert output == expect
def test_chassis(): # Generic Chassis is generic expect = { "type": "case", "brand": "Chassis Manufacture", "model": "", "sn": "Chassis Serial Number", "motherboard-form-factor": "" } output = read_dmidecode.get_chassis(filedir + 'chassis.txt') assert output == expect
def test_chassis(): # This is also wrong, but for pre-assembled computers it should be right expect = { 'brand': 'Gigabyte Technology Co., Ltd.', 'model': '', 'sn': 'To Be Filled By O.E.M.', 'type': 'case', 'motherboard-form-factor': '', } output = read_dmidecode.get_chassis(os.path.join(filedir, 'chassis.txt')) assert output == expect
def test_chassis(): expect = { "type": "case", "brand": "Matsonic", "model": "", "sn": "00000000", "motherboard-form-factor": "" } output = read_dmidecode.get_chassis(filedir + 'chassis.txt') assert output == expect
def test_chassis(): # At least it's not assuming stuff it cannot know... expect = { "type": "case", "brand": "", "model": "", "sn": "", "motherboard-form-factor": "" } output = read_dmidecode.get_chassis(os.path.join(filedir, 'chassis.txt')) assert output == expect
def test_chassis(): # This is also wrong, but for pre-assembled computers it should be right expect = { 'brand': 'Chassis Manufacture', 'model': '', 'motherboard-form-factor': '', 'sn': 'Chassis Serial Number', 'type': 'case' } output = read_dmidecode.get_chassis(os.path.join(filedir, 'chassis.txt')) assert output == expect
def extract_data(directory: str, has_dedicated_gpu: bool, gpu_in_cpu: bool, gui: bool, verbose: bool, unpack: bool = True): mobo = get_baseboard(directory + "/baseboard.txt") cpu = read_lscpu(directory + "/lscpu.txt") gpu = read_lspci_and_glxinfo(has_dedicated_gpu, directory + "/lspci.txt", directory + "/glxinfo.txt", verbose) if not has_dedicated_gpu: entries = extract_integrated_gpu_from_standalone(gpu) if gpu_in_cpu: if isinstance(cpu, list): # Multiple processors updated_cpus = [] for one_cpu in cpu: one_cpu = {**one_cpu, **entries} updated_cpus.append(one_cpu) cpu = updated_cpus del updated_cpus else: cpu = {**cpu, **entries} else: mobo = {**mobo, **entries} gpu = [] mobo = get_connectors(directory + "/connector.txt", mobo, verbose) mobo = get_net(directory + "/net.txt", mobo, verbose) chassis = get_chassis(directory + "/chassis.txt") dimms = read_decode_dimms(directory + "/dimms.txt", verbose) if chassis["motherboard-form-factor"] == "proprietary-laptop": psu = {"type": "external-psu"} else: psu = {"type": "psu"} disks = read_smartctl(directory) result = [] empty_dict = {} for component in (chassis, mobo, cpu, dimms, gpu, disks, psu): # return JSON ready for TARALLO if unpack: if isinstance(component, list): if len(component) == 0: result.append(empty_dict) continue for item in component: result.append(item) else: result.append(component) # return list of lists of dicts to use in extract_and_collect_data_from_generated_files() for long output else: if len(component) == 0: result.append(empty_dict) else: result.append(component) result = do_cleanup(result, gui, verbose) # check on case and mobo try: if (chassis['model'], chassis['brand'], chassis['variant']) == (mobo['brand'], mobo['model'], mobo['variant']): chassis.pop('model') except KeyError: pass # maybe there's a nicer way comparator = [] for comp in result: if isinstance(comp, list): comparator = comparator + comp else: comparator.append(comp) # avoid bad associations between items and products for comp1 in comparator: for comp2 in comparator: if is_product(comp1) and is_product( comp2) and comp1['type'] != comp2['type']: if (comp1['brand'], comp2['model']) == (comp2['brand'], comp2['model']): variant1 = comp1.pop('variant', '') variant2 = comp2.pop('variant', '') if variant1 == variant2: comp1['variant'] = variant1.rstrip().join( f"_{comp1['type']}") comp2['variant'] = variant2.rstrip().join( f"_{comp2['type']}") return result