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

« back to all changes in this revision

Viewing changes to providers/plainbox-provider-resource-generic/bin/module_resource

  • 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
 
#
3
 
# This file is part of Checkbox.
4
 
#
5
 
# Copyright 2009 Canonical Ltd.
6
 
#
7
 
# Checkbox is free software: you can redistribute it and/or modify
8
 
# it under the terms of the GNU General Public License version 3,
9
 
# as published by the Free Software Foundation.
10
 
 
11
 
#
12
 
# Checkbox is distributed in the hope that it will be useful,
13
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
# GNU General Public License for more details.
16
 
#
17
 
# You should have received a copy of the GNU General Public License
18
 
# along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
19
 
#
20
 
import sys
21
 
 
22
 
 
23
 
# Filename where cpuinfo is stored.
24
 
MODULES_FILENAME = "/proc/modules"
25
 
 
26
 
 
27
 
def get_module(line):
28
 
    """
29
 
    Each line consists of the following information for each module:
30
 
 
31
 
    name:         Name of the module.
32
 
    size:         Memory size of the module, in bytes.
33
 
    instances:    How many instances of the module are currently loaded.
34
 
    dependencies: If the module depends upon another module to be present
35
 
                  in order to function, and lists those modules.
36
 
    state:        The load state of the module: Live, Loading or Unloading.
37
 
    offset:       Current kernel memory offset for the loaded module.
38
 
    """
39
 
    (name, size, instances, dependencies, state, offset) = line.split(" ")[:6]
40
 
    if dependencies == "-":
41
 
        dependencies = ""
42
 
 
43
 
    return {
44
 
        "name": name,
45
 
        "size": int(size),
46
 
        "instances": int(instances),
47
 
        "dependencies": dependencies.replace(",", " ").strip(),
48
 
        "state": state,
49
 
        "offset": int(offset, 16)}
50
 
 
51
 
 
52
 
def get_modules(filename):
53
 
    file = open(filename, "r")
54
 
    for line in file.readlines():
55
 
        line = line.strip()
56
 
        if line:
57
 
            yield get_module(line)
58
 
 
59
 
 
60
 
def main():
61
 
    modules = get_modules(MODULES_FILENAME)
62
 
    for module in modules:
63
 
        for key, value in module.items():
64
 
            if value != "":
65
 
                print("%s: %s" % (key, value))
66
 
 
67
 
        # Empty line
68
 
        print()
69
 
 
70
 
    return 0
71
 
 
72
 
if __name__ == "__main__":
73
 
    sys.exit(main())