Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 1 | """ Utility module to help debug Python scripts |
| 2 | |
| 3 | -------------------------------------------------------------------------- |
| 4 | File: utilsDebug.py |
| 5 | |
| 6 | Overview: Python module to supply functions to help debug Python |
| 7 | scripts. |
| 8 | |
Deepak Panickal | 9b35cf5 | 2014-07-01 17:57:19 +0000 | [diff] [blame] | 9 | Gotchas: None. |
| 10 | |
| 11 | Copyright: None. |
| 12 | -------------------------------------------------------------------------- |
| 13 | |
| 14 | """ |
| 15 | |
| 16 | # Python modules: |
| 17 | |
| 18 | # Third party modules: |
| 19 | |
| 20 | # In-house modules: |
| 21 | |
| 22 | # Instantiations: |
| 23 | |
| 24 | #----------------------------------------------------------------------------- |
| 25 | # Details: Class to implement simple stack function trace. Instantiation the |
| 26 | # class as the first function you want to trace. Example: |
| 27 | # obj = utilsDebug.CDebugFnVerbose( "validate_arguments()" ); |
| 28 | # Gotchas: This class will not work in properly in a multi-threaded |
| 29 | # environment. |
| 30 | # Authors: Illya Rudkin 28/11/2013. |
| 31 | # Changes: None. |
| 32 | #-- |
| 33 | class CDebugFnVerbose: |
| 34 | # Public static properties: |
| 35 | bVerboseOn = False; # True = turn on function tracing, False = turn off. |
| 36 | |
| 37 | # Public: |
| 38 | #++------------------------------------------------------------------------ |
| 39 | # Details: CDebugFnVerbose constructor. |
| 40 | # Type: Method. |
| 41 | # Args: vstrFnName - (R) Text description i.e. a function name. |
| 42 | # Return: None. |
| 43 | # Throws: None. |
| 44 | #-- |
| 45 | # CDebugFnVerbose( vstrFnName ) |
| 46 | |
| 47 | #++------------------------------------------------------------------------ |
| 48 | # Details: Print out information on the object specified. |
| 49 | # Type: Method. |
| 50 | # Args: vstrText - (R) Some helper text description. |
| 51 | # vObject - (R) Some Python type object. |
| 52 | # Return: None. |
| 53 | # Throws: None. |
| 54 | #-- |
| 55 | def dump_object( self, vstrText, vObject ): |
| 56 | if CDebugFnVerbose.bVerboseOn == False: |
| 57 | return; |
| 58 | print "%d%s> Dp: %s" % (CDebugFnVerbose.__nLevel, self.__get_dots(), |
| 59 | vstrText),; |
| 60 | print vObject; |
| 61 | |
| 62 | #++------------------------------------------------------------------------ |
| 63 | # Details: Print out some progress text given by the client. |
| 64 | # Type: Method. |
| 65 | # Args: vstrText - (R) Some helper text description. |
| 66 | # Return: None. |
| 67 | # Throws: None. |
| 68 | #-- |
| 69 | def dump_text( self, vstrText ): |
| 70 | if CDebugFnVerbose.bVerboseOn == False: |
| 71 | return; |
| 72 | print "%d%s> Dp: %s" % (CDebugFnVerbose.__nLevel, self.__get_dots(), |
| 73 | vstrText); |
| 74 | |
| 75 | # Private methods: |
| 76 | def __init__( self, vstrFnName ): |
| 77 | self.__indent_out( vstrFnName ); |
| 78 | |
| 79 | # Class destructor |
| 80 | def __del__( self ): |
| 81 | self.__indent_back(); |
| 82 | |
| 83 | #++------------------------------------------------------------------------ |
| 84 | # Details: Build an indentation string of dots based on the __nLevel. |
| 85 | # Type: Method. |
| 86 | # Args: None. |
| 87 | # Return: Str - variable length string. |
| 88 | # Throws: None. |
| 89 | #-- |
| 90 | def __get_dots( self ): |
| 91 | return "".join( "." for i in range( 0, CDebugFnVerbose.__nLevel ) ); |
| 92 | |
| 93 | #++------------------------------------------------------------------------ |
| 94 | # Details: Build and print out debug verbosity text indicating the function |
| 95 | # just exited from. |
| 96 | # Type: Method. |
| 97 | # Args: None. |
| 98 | # Return: None. |
| 99 | # Throws: None. |
| 100 | #-- |
| 101 | def __indent_back( self ): |
| 102 | if CDebugFnVerbose.bVerboseOn: |
| 103 | print "%d%s< fn: %s" % (CDebugFnVerbose.__nLevel, self.__get_dots(), |
| 104 | self.__strFnName); |
| 105 | CDebugFnVerbose.__nLevel -= 1; |
| 106 | |
| 107 | #++------------------------------------------------------------------------ |
| 108 | # Details: Build and print out debug verbosity text indicating the function |
| 109 | # just entered. |
| 110 | # Type: Method. |
| 111 | # Args: vstrFnName - (R) Name of the function entered. |
| 112 | # Return: None. |
| 113 | # Throws: None. |
| 114 | #-- |
| 115 | def __indent_out( self, vstrFnName ): |
| 116 | CDebugFnVerbose.__nLevel += 1; |
| 117 | self.__strFnName = vstrFnName; |
| 118 | if CDebugFnVerbose.bVerboseOn: |
| 119 | print "%d%s> fn: %s" % ( CDebugFnVerbose.__nLevel, self.__get_dots(), |
| 120 | self.__strFnName); |
| 121 | |
| 122 | # Private statics attributes: |
| 123 | __nLevel = 0; # Indentation level counter |
| 124 | |
| 125 | # Private attributes: |
| 126 | __strFnName = ""; |
| 127 | |
| 128 | |
Ed Maste | a6a53d1 | 2015-03-23 17:57:42 +0000 | [diff] [blame] | 129 | |