~jocave/checkbox/hybrid-amd-gpu-mods

« back to all changes in this revision

Viewing changes to checkbox-old/scripts/lsmod_info

  • Committer: Tarmac
  • Author(s): Brendan Donegan
  • Date: 2013-06-03 11:12:58 UTC
  • mfrom: (2154.2.1 bug1185759)
  • Revision ID: tarmac-20130603111258-1b3m5ydvkf1accts
"[r=zkrynicki][bug=1185759][author=brendan-donegan] automatic merge by tarmac"

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python3
 
2
import sys
 
3
from checkbox.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([cmd, module],
 
20
                                  stderr=PIPE,
 
21
                                  universal_newlines=False)
 
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
if __name__ == '__main__':
 
40
    sys.exit(main())