GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
debug.py
Go to the documentation of this file.
1 """!
2 @package core.debug
3 
4 @brief wxGUI debugging
5 
6 Classes:
7  - debug::DebugMsg
8 
9 @code
10 from core.debug import Debug
11 Debug.msg (3, 'debug message')
12 @endcode
13 
14 (C) 2007-2009, 2011 by the GRASS Development Team
15 
16 This program is free software under the GNU General Public License
17 (>=v2). Read the file COPYING that comes with GRASS for details.
18 
19 @author Martin Landa <landa.martin gmail.com>
20 """
21 
22 import os
23 import sys
24 
25 import grass.script as grass
26 
27 class DebugMsg:
28  """!wxGUI debugging
29 
30  @code
31  g.gisenv set=WX_DEBUG=[0-5]
32  @endcode
33  """
34  def __init__(self):
35  # default level
36  self.debuglevel = 0
37 
38  self.SetLevel()
39 
40  def SetLevel(self):
41  """!Initialize gui debug level
42  """
43  self.debuglevel = int(grass.gisenv().get('WX_DEBUG', 0))
44 
45  def msg(self, level, message, *args):
46  """!Print debug message
47 
48  @param level debug level (0-5)
49  @param message message to be printed
50  @param *args formatting params
51  """
52  # self.SetLevel()
53  if self.debuglevel > 0 and level > 0 and level <= self.debuglevel:
54  if args:
55  sys.stderr.write("GUI D%d/%d: " % (level, self.debuglevel) + \
56  message % args + os.linesep)
57  else:
58  sys.stderr.write("GUI D%d/%d: " % (level, self.debuglevel) + \
59  message + os.linesep)
60  sys.stderr.flush() # force flush (required for MS Windows)
61 
62  def GetLevel(self):
63  """!Return current GUI debug level"""
64  return self.debuglevel
65 
66 # Debug instance
67 Debug = DebugMsg()
def msg
Print debug message.
Definition: debug.py:45
def __init__
Definition: debug.py:34
def GetLevel
Return current GUI debug level.
Definition: debug.py:62
wxGUI debugging
Definition: debug.py:27
def SetLevel
Initialize gui debug level.
Definition: debug.py:40