This repository has been archived by the owner on May 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.py
73 lines (51 loc) · 1.99 KB
/
debug.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
----------------------------------------------------------------------------
"THE BEER-WARE LICENSE"
As long as you retain this notice you can do whatever you want with this
stuff. If you meet an employee from Windward some day, and you think this
stuff is worth it, you can buy them a beer in return. Windward Studios
----------------------------------------------------------------------------
"""
from __future__ import print_function
import time
#To turn off these utilities set this to False
DEBUG = True
def startTime():
return time.clock()
def timeElapsed(since):
return time.clock() - since
class Trap(UserWarning):
pass
def trap(message="IT'S A TRAP!", breakOn=True):
'''Break into the debugger if breakOn evaluates to True.
Raise (and catch) an instance of the Trap exception.
With optional error message, pass that message into Trap's constructor.
With optional breakOn, raise the exception only if breakOn evaluates to True.
**Be sure that your IDE is set to break on caught (Trap or UserWarning)
exceptions.**
'''
if DEBUG and breakOn:
try:
raise Trap(message)
except Trap:
pass
def bugprint(*args, **kwargs):
'''Same as built-in print, but only works in DEBUG mode.'''
if DEBUG:
print(*args, **kwargs)
def printrap(message, breakOn=True):
'''Print a message to the console (always), and call trap in DEBUG mode.
If DEBUG is set to True, call trap with message and the optional breakOn
argument.
'''
print(message)
if DEBUG:
trap(message, breakOn)
def bugprintrap(message, breakOn=True):
'''Print a message to the console and call trap (in DEBUG mode only).
If DEBUG is set to True, print message and call trap with that message
and the optional breakOn argument.
'''
if DEBUG:
print(message)
trap(message, breakOn)