From 04875c5e8523e6f46a032072d25fd761cd78fa5f Mon Sep 17 00:00:00 2001 From: Sylvain Pineau Date: Mon, 13 Jul 2020 10:55:23 +0200 Subject: bin:get_make_and_model -> get_make_and_model.py --- bin/get_make_and_model | 43 ------------------------------------------- bin/get_make_and_model.py | 43 +++++++++++++++++++++++++++++++++++++++++++ units/miscellanea/jobs.pxu | 2 +- 3 files changed, 44 insertions(+), 44 deletions(-) delete mode 100755 bin/get_make_and_model create mode 100755 bin/get_make_and_model.py diff --git a/bin/get_make_and_model b/bin/get_make_and_model deleted file mode 100755 index 496a949..0000000 --- a/bin/get_make_and_model +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env python3 - -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)) - -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'} - 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()) - diff --git a/bin/get_make_and_model.py b/bin/get_make_and_model.py new file mode 100755 index 0000000..496a949 --- /dev/null +++ b/bin/get_make_and_model.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 + +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)) + +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'} + 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()) + diff --git a/units/miscellanea/jobs.pxu b/units/miscellanea/jobs.pxu index 96b8562..8fd16f5 100644 --- a/units/miscellanea/jobs.pxu +++ b/units/miscellanea/jobs.pxu @@ -403,7 +403,7 @@ category_id: com.canonical.plainbox::miscellanea estimated_duration: 30.0 id: miscellanea/get_make_and_model user: root -command: get_make_and_model +command: get_make_and_model.py requires: dmi_present.state == 'supported' _description: Retrieve the computer's make and model for easier access than digging through the dmidecode output. -- cgit v1.2.3