1#!/usr/bin/env python3

2

3 import shlex

4 from subprocess import check_output

5

6

7 def print_header(value):

8 print("{}:".format(value))

9

10

11 def print_data(key, value):

12 print(" {}: {}".format(key, value))

13

14

15 def run_cmd(option):

16 cmd = "lshw -C " + option

17 out = check_output(shlex.split(cmd), universal_newlines=True)

18 return out.split("\n")

19

20

21 def main():

22 keys = {"Manufacturer": "vendor", "Model": "product", "Version": "version"}

23 lshw_classes = {"system": "System", "bus": "Mainboard"}

24

25 for lshw_class in lshw_classes:

26 output = run_cmd(lshw_class)

27 data = {}

28 for key in keys:

29 for line in output:

30 if keys[key] in line:

31 data[key] = line.split(":")[1].strip()

32 break

33 else:

34 data[key] = "NOT FOUND"

35

36 print_header(lshw_classes[lshw_class])

37 for key in data:

38 print_data(key, data[key])

39

40

41 if __name__ == "__main__":

42 raise SystemExit(main())