/
debug.py
157 lines (138 loc) · 4.53 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
##############################################################################
# .___________. __ .___ ___. .______ _______ .______ #
# | || | | \/ | | _ \ | ____|| _ \ #
# `---| |----`| | | \ / | | |_) | | |__ | |_) | #
# | | | | | |\/| | | _ < | __| | / #
# | | | | | | | | | |_) | | |____ | |\ \----. #
# |__| |__| |__| |__| |______/ |_______|| _| `._____| #
# #
##############################################################################
#----------------------------------------------------------------------------#
# debug.py #
# Module for debugging. Can be called directly, which compiles everything #
# and then gives a total line count. Also handles internal printing. #
#----------------------------------------------------------------------------#
### Imports ##################################################################
# Python Library Imports
import sys
import os
import string
import traceback
# Local Imports
import config
import me
### Constants ################################################################
DEBUG_FLG = True
THRESHOLD = 2 # scale of 1 to 10
INCLUDE_UID = True
### Variables ################################################################
shortUid = None
### Functions ################################################################
def printError(msg):
"""
Print a message to standard error.
"""
print >>sys.stderr, str(msg)
sys.stderr.flush()
def logError(msg):
"""
Log an error message
"""
printError(msg)
def printMessage(msg):
"""
Print a message to standard out
"""
print >>sys.stdout, str(msg)
sys.stdout.flush()
def logMessage(msg):
"""
Log a message. (non error)
"""
printMessage(msg)
def debug(
msg,
threshold=5,
error=False,
success=False,
info=False,
strange=False,
monitor=False):
"""
Main debug function.
"""
global shortUid
if not shortUid:
try:
shortUid = me.getMe().getShortUid()
except:
shortUid = ""
uidstr = (shortUid + "\t") if INCLUDE_UID else ""
if type(msg) is str:
if DEBUG_FLG and threshold >= THRESHOLD:
if error:
printError("! ERROR: \t" + uidstr + msg)
elif success:
printMessage("* SUCCESS:\t" + uidstr + msg)
elif info:
printMessage("- INFO: \t" + uidstr + msg)
elif strange:
printMessage("? STRANGE:\t" + uidstr + msg)
elif monitor:
printMessage("MONITOR: " + msg)
else:
printMessage(msg)
else:
if error and threshold >= THRESHOLD:
printError("! ERROR: \t" + uidstr + msg)
else:
print "! ERROR: ", msg
traceback.print_exc(file=sys.stderr)
def countLinesOfCode(path=".", extension='py'):
"""
Procedure to count total lines of code in each file
"""
total = 0
listing = os.listdir(path)
for fname in listing:
if fname[-1*len(extension):] == extension:
with open(os.path.join(path, fname)) as f:
for i, l in enumerate(f):
if len(l) > 80:
print "line " + str(i) + " of " \
+ fname + " is too long."
if l.find("TODO") > -1 and fname != 'debug.py':
print "line " + str(i) + " of " \
+ fname + " has a todo: " + l
subtotal = i + 1
print string.rjust(fname, 25) + "\t" + str(subtotal)
total += subtotal
print total
return total
if __name__ == "__main__":
"""
TEST ALL THE THINGS!!!1!
"""
import me
import config
import launch
import nodes
import gossip
import logger
import timber_exceptions
import vectorClock
import message
import message_queue
import membership
import neighbors
import simpledb
import timber
import stats
import connections
import aggregation
import demo
import controller
py = countLinesOfCode('.', 'py')
client = countLinesOfCode('./client/', 'py')
jav = countLinesOfCode('monitor/', 'java')
print 'Total:',str(py+client+jav)