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

« back to all changes in this revision

Viewing changes to checkbox-old/scripts/memory_info

  • Committer: Zygmunt Krynicki
  • Date: 2013-05-29 07:50:30 UTC
  • mto: This revision was merged to the branch mainline in revision 2153.
  • Revision ID: zygmunt.krynicki@canonical.com-20130529075030-ngwz245hs2u3y6us
checkbox: move current checkbox code into checkbox-old

This patch cleans up the top-level directory of the project into dedicated
sub-project directories. One for checkbox-old (the current checkbox and all the
associated stuff), one for plainbox and another for checkbox-ng.

There are some associated changes, such as updating the 'source' mode of
checkbox provider in plainbox, and fixing paths in various test scripts that we
have.

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python3
 
2
 
 
3
import re
 
4
import sys
 
5
 
 
6
 
 
7
def get_meminfo():
 
8
    meminfo = {}
 
9
    for line in open("/proc/meminfo").readlines():
 
10
        match = re.match(r"(.*):\s+(.*)", line)
 
11
        if match:
 
12
            key = match.group(1)
 
13
            value = match.group(2)
 
14
            meminfo[key] = value
 
15
 
 
16
    return meminfo
 
17
 
 
18
 
 
19
def main(args):
 
20
    meminfo = get_meminfo()
 
21
    amount, units = meminfo["MemTotal"].split()
 
22
 
 
23
    amount = float(amount)
 
24
    next_units = {'kB': 'MB',
 
25
                  'MB': 'GB'}
 
26
 
 
27
    while amount > 1024:
 
28
        amount = amount / 1024
 
29
        units = next_units[units]
 
30
 
 
31
    print("%.1f %s" % (amount, units))
 
32
    return 0
 
33
 
 
34
if __name__ == "__main__":
 
35
    sys.exit(main(sys.argv[1:]))