diff options
| author | Jeff Lane <jeffrey.lane@canonical.com> | 2017-03-14 13:10:07 -0400 |
|---|---|---|
| committer | Jeff Lane <jeffrey.lane@canonical.com> | 2017-03-14 13:10:07 -0400 |
| commit | 15a136e32ae8efea3a6883babfdd87ad36ba0955 (patch) | |
| tree | 6729b0d6b0af400e7858059d415c11776fb01376 /bin | |
| parent | b8e5fb6158ef5ee9b819228aee58266a3b23506b (diff) | |
bin/get_make_and_model: Now also reveals make/model info for the mainboard to assist in identifying whitebox systems like those from SuperMicro LP: #1672726
Diffstat (limited to 'bin')
| -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()) |
