diff options
author | PMR <pmr@pmr-lander> | 2017-03-20 18:18:59 +0000 |
---|---|---|
committer | PMR <pmr@pmr-lander> | 2017-03-20 18:18:59 +0000 |
commit | 190c7ebd7eb3cf4d46311e42fa58dd8419aebe31 (patch) | |
tree | d704e1fe52d6f84192b5ee5e2db46708a71dd33f | |
parent | d573c20db3aeb93c40f0221c604a7147260b8b47 (diff) | |
parent | 15a136e32ae8efea3a6883babfdd87ad36ba0955 (diff) |
Merge #319847 from ~bladernr/plainbox-provider-checkbox:1672726-improve-get-make-model
-rwxr-xr-x | bin/get_make_and_model | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/bin/get_make_and_model b/bin/get_make_and_model index bb5efd9..496a949 100755 --- a/bin/get_make_and_model +++ b/bin/get_make_and_model @@ -4,31 +4,39 @@ import os.path import shlex from subprocess import check_output +def print_header(value): + print("{}:".format(value)) + def print_data(key, value): - print("{}: {}".format(key, value)) + print(" {}: {}".format(key, value)) + +def run_cmd(option): + cmd = "lshw -C " + option + out = check_output(shlex.split(cmd), + universal_newlines = True) + return out.split('\n') def main(): keys = {'Manufacturer': 'vendor', 'Model': 'product', 'Version': 'version'} - - cmd = "lshw -C system" - - out = check_output(shlex.split(cmd), - universal_newlines = True) - output = out.split('\n') - - data = {} - for key in keys: - for line in output: - if keys[key] in line: - data[key] = line.split(':')[1].strip() - break - else: - data[key] = "NOT FOUND" - - for key in data: - print_data(key, data[key]) + lshw_classes = {'system': 'System', + 'bus': 'Mainboard'} + + for lshw_class in lshw_classes: + output = run_cmd(lshw_class) + data = {} + for key in keys: + for line in output: + if keys[key] in line: + data[key] = line.split(':')[1].strip() + break + else: + data[key] = "NOT FOUND" + + print_header(lshw_classes[lshw_class]) + for key in data: + print_data(key, data[key]) if __name__ == "__main__": raise SystemExit(main()) |