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