~package-import/ubuntu/natty/apport/defunct

« back to all changes in this revision

Viewing changes to data/dump_acpi_tables.py

  • Committer: Martin Pitt
  • Date: 2010-07-13 05:42:32 UTC
  • mto: This revision was merged to the branch mainline in revision 1679.
  • Revision ID: martin.pitt@canonical.com-20100713054232-mws1mrlockjaw4h0
Add dump_acpi_tables.py script. This can be called by package hooks which need ACPI table information (in particular, kernel bug reports). Thanks to Brad Figg for the script!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import os, sys
 
4
from stat import *
 
5
from tempfile import mkstemp
 
6
 
 
7
def dump_acpi_table(filename, tablename, out):
 
8
    '''Dump a single ACPI table'''
 
9
 
 
10
    out.write('%s @ 0x00000000\n' % tablename)
 
11
    n = 0
 
12
    f = open(filename, 'rb')
 
13
    try:
 
14
        byte = f.read(1)
 
15
        while byte != '':
 
16
            val = ord(byte)
 
17
            if (n & 15) == 0:
 
18
                hex_str = '  %4.4x: ' % n
 
19
                ascii_str=''
 
20
                
 
21
            hex_str = hex_str + '%2.2x ' % val
 
22
 
 
23
            if (val < 32) or (val > 126):
 
24
                ascii_str = ascii_str + '.'
 
25
            else:
 
26
                ascii_str = ascii_str + byte
 
27
            n = n + 1
 
28
            if (n & 15) == 0:
 
29
                out.write('%s %s\n' % (hex_str, ascii_str))
 
30
            byte = f.read(1)
 
31
    finally:
 
32
        for i in range(n & 15,16):
 
33
            hex_str = hex_str + '   '
 
34
 
 
35
        if (n & 15) != 15:
 
36
            out.write('%s %s\n' % (hex_str, ascii_str))
 
37
        f.close()
 
38
    out.write('\n')
 
39
    
 
40
def dump_acpi_tables(path, out):
 
41
    '''Dump ACPI tables'''
 
42
 
 
43
    tables = os.listdir(path)
 
44
    for tablename in tables:
 
45
        pathname = os.path.join(path, tablename)
 
46
        mode = os.stat(pathname)[ST_MODE]   
 
47
        if S_ISDIR(mode):
 
48
            dump_acpi_tables(pathname, out)
 
49
        else:
 
50
            dump_acpi_table(pathname, tablename, out)
 
51
 
 
52
dump_acpi_tables('/sys/firmware/acpi/tables', sys.stdout)