1#!/usr/bin/env python3

2 import sys

3 from checkbox_support.parsers.modinfo import ModinfoParser

4 from subprocess import Popen, PIPE, check_output, CalledProcessError

5

6

7 def main():

8 process = Popen("lsmod", stdout=PIPE, stderr=PIPE, universal_newlines=True)

9 data = process.stdout.readlines()

10 # Delete the first item because it's headers from lsmod output

11 data.pop(0)

12 module_list = [module.split()[0].strip() for module in data]

13

14 cmd = "/sbin/modinfo"

15 for module in sorted(module_list):

16 version = ""

17 stream = b""

18 try:

19 stream = check_output(

20 [cmd, module], stderr=PIPE, universal_newlines=False

21 )

22 except CalledProcessError as e:

23 if e.returncode != 1:

24 raise e

25 else:

26 version = "Unavailable"

27

28 stream = stream.decode("utf-8")

29

30 parser = ModinfoParser(stream)

31

32 if not version:

33 version = parser.get_field("version")

34 if not version:

35 version = parser.get_field("vermagic").split()[0]

36 print("%s: %s" % (module, version))

37 return 0

38

39

40 if __name__ == "__main__":

41 sys.exit(main())