Back to index

apport  2.4
dump_acpi_tables.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 import os, sys, stat
00004 
00005 
00006 def dump_acpi_table(filename, tablename, out):
00007     '''Dump a single ACPI table'''
00008 
00009     out.write('%s @ 0x00000000\n' % tablename)
00010     n = 0
00011     f = open(filename, 'rb')
00012     hex_str = ''
00013     try:
00014         byte = f.read(1)
00015         while byte != b'':
00016             val = ord(byte)
00017             if (n & 15) == 0:
00018                 hex_str = '  %4.4x: ' % n
00019                 ascii_str = ''
00020 
00021             hex_str = hex_str + '%2.2x ' % val
00022 
00023             if (val < 32) or (val > 126):
00024                 ascii_str = ascii_str + '.'
00025             else:
00026                 ascii_str = ascii_str + chr(val)
00027             n = n + 1
00028             if (n & 15) == 0:
00029                 out.write('%s %s\n' % (hex_str, ascii_str))
00030             byte = f.read(1)
00031     finally:
00032         for i in range(n & 15, 16):
00033             hex_str = hex_str + '   '
00034 
00035         if (n & 15) != 15:
00036             out.write('%s %s\n' % (hex_str, ascii_str))
00037         f.close()
00038     out.write('\n')
00039 
00040 
00041 def dump_acpi_tables(path, out):
00042     '''Dump ACPI tables'''
00043 
00044     tables = os.listdir(path)
00045     for tablename in tables:
00046         pathname = os.path.join(path, tablename)
00047         mode = os.stat(pathname).st_mode
00048         if stat.S_ISDIR(mode):
00049             dump_acpi_tables(pathname, out)
00050         else:
00051             dump_acpi_table(pathname, tablename, out)
00052 
00053 if os.path.isdir('/sys/firmware/acpi/tables'):
00054     dump_acpi_tables('/sys/firmware/acpi/tables', sys.stdout)