def test_lscpu(): expect = [{ "type": "cpu", "working": "yes", "isa": "x86-64", "model": "Xeon 5160", "brand": "Intel", "core-n": 2, "thread-n": 2, "frequency-hertz": 3000000000, "human_readable_frequency": "N/A" }, { "type": "cpu", "working": "yes", "isa": "x86-64", "model": "Xeon 5160", "brand": "Intel", "core-n": 2, "thread-n": 2, "frequency-hertz": 3000000000, "human_readable_frequency": "N/A" }] output = read_lscpu.read_lscpu(os.path.join(filedir, 'lscpu.txt')) assert isinstance(expect, list) assert len(expect) == 2 assert output == expect
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_lscpu(): expect = { 'type': 'cpu', "working": "yes", 'isa': 'x86-32', 'model': 'Celeron 2.80GHz', 'brand': 'Intel', 'core-n': 1, 'thread-n': 1, 'frequency-hertz': -1, 'human_readable_frequency': 'N/A' } output = read_lscpu.read_lscpu(os.path.join(filedir, 'lscpu.txt'))
def test_lscpu(): expect = { "type": "cpu", "working": "yes", "isa": "x86-64", "model": "Core 2 Quad Q6600", "brand": "Intel", "core-n": 4, "thread-n": 4, "frequency-hertz": 2400000000, } output = read_lscpu.read_lscpu(os.path.join(filedir, 'lscpu.txt')) assert output == expect
def test_lscpu(): expect = { "type": "cpu", "working": "yes", "isa": "x86-64", "model": "Pentium 4 2.80GHz", "brand": "Intel", "core-n": 1, "thread-n": 2, "frequency-hertz": 2800000000, } output = read_lscpu.read_lscpu(os.path.join(filedir, 'lscpu.txt')) assert output == expect
def test_lscpu(): expect = { "type": "cpu", "working": "yes", "isa": "x86-64", "model": "FX-8370E", "brand": "AMD", "core-n": 4, "thread-n": 8, "frequency-hertz": 3300000000, } output = read_lscpu.read_lscpu(os.path.join(filedir, 'lscpu.txt')) assert output == expect
def test_lscpu(): expect = { 'brand': 'Intel', 'core-n': 4, 'frequency-hertz': 3400000000, 'isa': 'x86-64', 'model': 'Core i7-2600', 'thread-n': 8, 'type': 'cpu', 'working': 'yes', } output = read_lscpu.read_lscpu(os.path.join(filedir, 'lscpu.txt')) assert output == expect
def test_lscpu(): expect = { "type": "cpu", "working": "yes", "isa": "x86-64", "model": "Core m3-6Y30", "brand": "Intel", "core-n": 2, "thread-n": 4, "frequency-hertz": 900000000, "human_readable_frequency": "N/A" } output = read_lscpu.read_lscpu(filedir + 'lscpu.txt') assert output == expect
def test_lscpu(): expect = { "type": "cpu", "working": "yes", "isa": "x86-64", "model": "Pentium D 2.66GHz", "brand": "Intel", "core-n": 2, "thread-n": 2, "frequency-hertz": 2660000000, "human_readable_frequency": "N/A" } output = read_lscpu.read_lscpu(os.path.join(filedir, 'lscpu.txt')) assert output == expect
def test_lscpu(): expect = { "type": "cpu", "working": "yes", "isa": "x86-32", "model": "Athlon 4", "brand": "AMD", "core-n": 1, "thread-n": 1, "frequency-hertz": -1, } output = read_lscpu.read_lscpu(os.path.join(filedir, 'lscpu.txt')) assert output == expect
def test_lscpu(): expect = { "type": "cpu", "working": "yes", "isa": "x86-64", "model": "FX-8370E", "brand": "AMD", "core-n": 4, "thread-n": 8, "frequency-hertz": 3300000000, "human_readable_frequency": "N/A" } output = read_lscpu.read_lscpu(filedir + 'lscpu.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