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

« back to all changes in this revision

Viewing changes to scripts/graphic_memory_info

  • Committer: Zygmunt Krynicki
  • Date: 2013-05-17 13:54:25 UTC
  • mto: This revision was merged to the branch mainline in revision 2130.
  • Revision ID: zygmunt.krynicki@canonical.com-20130517135425-cxcenxx5t0qrtbxd
checkbox-ng: add CheckBoxNG sub-project

CheckBoxNG (or lowercase as checkbox-ng, pypi:checkbox-ng) is a clean
implementation of CheckBox on top of PlainBox. It provides a new
executable, 'checkbox' that has some of the same commands that were
previously implemented in the plainbox package.

In particular CheckBoxNG comes with the 'checkbox sru' command
(the same one as in plainbox). Later on this sub-command will be removed
from plainbox.

CheckBoxNG depends on plainbox >= 0.3

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
# -*- coding: utf-8 -*-
 
3
#
 
4
# graphic_memory_info
 
5
#
 
6
# This file is part of Checkbox.
 
7
#
 
8
# Copyright 2012 Canonical Ltd.
 
9
#
 
10
# Authors: Shawn Wang <shawn.wang@canonical.com>
 
11
#
 
12
# Checkbox is free software: you can redistribute it and/or modify
 
13
# it under the terms of the GNU General Public License as published by
 
14
# the Free Software Foundation, either version 3 of the License, or
 
15
# (at your option) any later version.
 
16
#
 
17
# Checkbox is distributed in the hope that it will be useful,
 
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
# GNU General Public License for more details.
 
21
#
 
22
# You should have received a copy of the GNU General Public License
 
23
# along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
 
24
 
 
25
"""
 
26
    The graphic_memory_info got information from lspci
 
27
"""
 
28
 
 
29
import re
 
30
import sys
 
31
import subprocess
 
32
 
 
33
# 00:01.0 VGA compatible controller: \
 
34
# Advanced Micro Devices [AMD] nee ATI Wrestler [Radeon HD 6320] \
 
35
# (prog-if 00 [VGA controller])
 
36
 
 
37
 
 
38
def vgamem_paser(data=None):
 
39
 
 
40
    '''Parsing type vga and find memory information'''
 
41
 
 
42
    device = None
 
43
    vgamems = list()
 
44
    for line in data.split('\n'):
 
45
        for match in re.finditer('(\d\d:\d\d\.\d) VGA(.+): (.+)', line):
 
46
            device = match.group(1)
 
47
            name = match.group(3)
 
48
        if device is None:
 
49
            continue
 
50
#Memory at e0000000 (32-bit, prefetchable) [size=256M]
 
51
        for match in re.finditer('Memory(.+) prefetchable\) \[size=(\d+)M\]',
 
52
                                 line):
 
53
            vgamem_size = match.group(2)
 
54
            vgamem = {'device': device,
 
55
                      'name': name,
 
56
                      'vgamem_size': vgamem_size}
 
57
            vgamems.append(vgamem)
 
58
    return vgamems
 
59
 
 
60
 
 
61
def main():
 
62
 
 
63
    '''main function
 
64
       lspci -v -s 00:01.0 | grep ' prefetchable'
 
65
    '''
 
66
 
 
67
    try:
 
68
        data = subprocess.check_output(['lspci', '-v'],
 
69
                                       universal_newlines=True)
 
70
    except subprocess.CalledProcessError as exc:
 
71
        return exc.returncode
 
72
 
 
73
    vgamems = vgamem_paser(data)
 
74
    for vgamem in vgamems:
 
75
        output_str = "Device({0})\t Name: {1}\tVGA Memory Size: {2}M"
 
76
        print(output_str.format(vgamem['device'],
 
77
                                vgamem['name'],
 
78
                                vgamem['vgamem_size']))
 
79
 
 
80
if __name__ == '__main__':
 
81
    sys.exit(main())