Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
debug.py
Go to the documentation of this file.
1 import traceback
2 import sys
3 
4 debugnum=0
5 
6 class VSException(Exception):
7  pass
8 
9 
10 def _devnull(msg, *fmtargs): # == /dev/null
11  pass
12 
13 def prettyfile(fil):
14  lasttwo=str(fil).split('/')[-2:]
15  if len(lasttwo)<2: return fil
16  return '%s/%s' % (lasttwo[0][0],lasttwo[1])
17 
18 def _withlineno(msg, *fmtargs): # Simple line number
19  laststack = traceback.extract_stack()[-2]
20  print ' +++ %s:%s %s' % (prettyfile(laststack[0]),laststack[1],str(msg) % fmtargs)
21 
22 
23 def _warn(msg, *fmtargs): # Traceback without killing the script
24  global debugnum
25  debugnum+=1
26  print " *** Python Warning %s!" % (debugnum,)
27  sys.stderr.write('Warning Traceback %s:\n' % (debugnum,))
28  for frame in traceback.extract_stack()[:-1]:
29  sys.stderr.write(' File "%s", line %s' % (prettyfile(frame[0]), frame[1]))
30  sys.stderr.write(', in %s\n %s\n' % (frame[2],frame[3]))
31  sys.stderr.write('Message: %s\n\n' % (msg % fmtargs,))
32 
33 def _fatal(msg, *fmtargs): # Kill the script!
34  global debugnum
35  debugnum+=1
36  print "Python VSException %s!" % (debugnum,)
37  raise VSException(msg)
38 
39 fatal = _fatal # Really bad error... Kill the script. Same as a call to raise()
40 
41 warn = _warn # Anything that shouldn't happen, but shouldn't cause a crash either.
42 error = _warn # Different name for the same thing.
43 
44 # Less important messages that happen a lot.
45 debug = _withlineno # Useful messages for hunting down bugs, or loading status.
46 info = _warn
47 
48 # For release, we can disable unimportant messages:
49 info = _devnull
50 debug = _devnull
51 
52