Changeset 227


Ignore:
Timestamp:
04/09/11 12:31:22 (13 years ago)
Author:
tim
Message:

added a SetLogMask? function to pyregfi as an interface to regfi_log_set_mask
made pyregfi-smoketest.py easier to use

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • test/pyregfi-smoketest.py

    r225 r227  
    88
    99
    10 def usage():
    11     sys.stderr.write("USAGE: pyregfi-smoketest.py hive1 [hive2 ...]\n")
    12 
    13 
    14 
     10
     11pyregfi.SetLogMask((pyregfi.LOG_TYPES.INFO, pyregfi.LOG_TYPES.WARN, pyregfi.LOG_TYPES.ERROR))
    1512
    1613# Uses the HiveIterator to walk all keys
     
    192189        pass
    193190
    194    
    195 if len(sys.argv) < 2:
     191tests = {
     192    "iterTallyNames":iterTallyNames,
     193    "iterParentWalk":iterParentWalk,
     194    "iterTallyData":iterTallyData,
     195    "recurseKeyTally":recurseKeyTally,
     196    "iterFetchRelated":iterFetchRelated,
     197    "iterIterWalk":iterIterWalk,
     198    "iterCallbackIO":iterCallbackIO,
     199    }
     200
     201def usage():
     202    sys.stderr.write("USAGE: pyregfi-smoketest.py test1[,test2[,...]] hive1 [hive2 ...]\n")
     203    sys.stderr.write("\tAvailable tests:\n")
     204    for t in tests.keys():
     205        sys.stderr.write("\t\t%s\n" % t)
     206
     207
     208if len(sys.argv) < 3:
    196209    usage()
    197210    sys.exit(1)
    198211
    199 
    200 tests = [("iterTallyNames",iterTallyNames),
    201          ("iterParentWalk",iterParentWalk),
    202          ("iterTallyData",iterTallyData),
    203          ("recurseKeyTally",recurseKeyTally),
    204          ("iterFetchRelated",iterFetchRelated),
    205          ("iterIterWalk",iterIterWalk),]
    206 
    207 tests = [("iterCallbackIO",iterCallbackIO),]
    208 
     212selected_tests = sys.argv[1].split(',')
     213for st in selected_tests:
     214    if st not in tests:
     215        usage()
     216        sys.stderr.write("ERROR: %s not a valid test type" % st)
     217        sys.exit(1)
    209218
    210219files = []
    211 for f in sys.argv[1:]:
     220for f in sys.argv[2:]:
    212221    files.append((f, open(f,"rb")))
    213222
     
    216225for hname,fh in files:
    217226    hive = pyregfi.Hive(fh)
    218     for tname,t in tests:
     227    for tname in selected_tests:
     228        t = tests[tname]
    219229        teststart = time.time()
    220230        tstr = "'%s' on '%s'" % (tname,hname)
  • trunk/python/pyregfi/__init__.py

    r226 r227  
    133133
    134134
     135## An enumeration of log message types
     136#
     137# @note This is a static class, there is no need to instantiate it.
     138#       Just access its attributes directly as LOG_TYPES.INFO, etc
     139class LOG_TYPES(object):
     140    ## Informational messages, useful in debugging
     141    INFO  =  0x01
     142    ## Non-critical problems in structure parsing or intepretation
     143    WARN  =  0x04
     144    ## Major failures
     145    ERROR =  0x10
     146
     147
    135148def _buffer2bytearray(char_pointer, length):
    136149    if length == 0 or char_pointer == None:
     
    180193        return ''
    181194    return msgs.decode('utf-8')
     195
     196
     197## Sets the types of log messages to record
     198#
     199# @param log_types A sequence of message types that regfi should generate.
     200#                  Message types can be found in the LOG_TYPES enumeration.
     201#
     202# @return True on success, False on failure.  Failures are rare, but could
     203#         indicate that global logging is not operating as expected.
     204#
     205# Example:
     206# @code
     207# SetLogMask((LOG_TYPES.ERROR, LOG_TYPES.WARN, LOG_TYPES.INFO))
     208# @endcode
     209#
     210# The message mask is a global (all hives, iterators), thread-specific value.
     211# For more information, see @ref regfi_log_set_mask.
     212#
     213def SetLogMask(log_types):
     214    mask = 0
     215    for m in log_types:
     216        mask |= m
     217    return regfi.regfi_log_set_mask(mask)
     218
    182219
    183220
  • trunk/python/pyregfi/structures.py

    r226 r227  
    1717# XXX: can we always be sure enums are this size?
    1818REGFI_ENCODING = c_uint32
    19 REGFI_ENCODING_UTF8 = 1
     19REGFI_ENCODING_UTF8 = REGFI_ENCODING(1)
    2020
    2121REGFI_DATA_TYPE = c_uint32
    22 REGFI_REGF_SIZE = 0x1000
    2322
    2423
Note: See TracChangeset for help on using the changeset viewer.