diff options
author | Jeff Lane <jeffrey.lane@canonical.com> | 2014-08-04 14:27:50 -0400 |
---|---|---|
committer | Jeff Lane <jeffrey.lane@canonical.com> | 2014-08-04 14:27:50 -0400 |
commit | 9490630609ca862892539a53d35844b0daa18556 (patch) | |
tree | 12dcf111444259ef0e2f2a413d78530659fba7b4 | |
parent | 624baaa53d4fb508c82c4ee8c6f28a736fa691c6 (diff) |
re-wrote get_make_and_model script to use lshw rather than individual code for device-tree vs dmi
-rwxr-xr-x | bin/get_make_and_model | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/bin/get_make_and_model b/bin/get_make_and_model index f21e6eb..bb5efd9 100755 --- a/bin/get_make_and_model +++ b/bin/get_make_and_model @@ -1,17 +1,34 @@ #!/usr/bin/env python3 import os.path +import shlex +from subprocess import check_output -def print_file_contents(heading, filename): - with open(filename) as f: - text = f.read().strip() - print("{}: {}".format(heading, text)) - f.close() +def print_data(key, value): + print("{}: {}".format(key, value)) def main(): - print_file_contents('Manufacturer', '/sys/class/dmi/id/sys_vendor') - print_file_contents('Model', '/sys/class/dmi/id/product_name') - print_file_contents('Version', '/sys/class/dmi/id/product_version') + 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]) if __name__ == "__main__": raise SystemExit(main()) |