1#!/usr/bin/env python3

2# Copyright 2015-2020 Canonical Ltd.

3# All rights reserved.

4#

5# Written by:

6# Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

7# Jonathan Cave <jonathan.cave@canonical.com>

8

9"""Collect information about all sysfs attributes related to DMI."""

10

11 import os

12

13"""

14 Collect information about all sysfs attributes related to DMI.

15

16 This program reads all the readable files in /sys/class/dmi/id/ and

17 presents them a single RFC822 record.

18

19@EPILOG@

20

21 Unreadable files (typically due to permissions) are silently skipped.

22 Please run this program as root if you wish to access various serial

23 numbers.

24"""

25

26

27 def main():

28 sysfs_root = "/sys/class/dmi/id/"

29 if not os.path.isdir(sysfs_root):

30 return

31 for dmi_attr in sorted(os.listdir(sysfs_root)):

32 dmi_filename = os.path.join(sysfs_root, dmi_attr)

33 if not os.path.isfile(dmi_filename):

34 continue

35 if not os.access(dmi_filename, os.R_OK):

36 continue

37 with open(dmi_filename, "rt", encoding="utf-8") as stream:

38 dmi_data = stream.read().strip()

39 print("{}: {}".format(dmi_attr, dmi_data))

40

41

42 if __name__ == "__main__":

43 main()