/
diag.py
100 lines (74 loc) · 2.49 KB
/
diag.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
"""
Use this with diagnostics so that it can be changed as necessary
For example, sometimes want on stdout maybe or in a scroll window....
Let's replace this with python logging stuff.
at least get it to the point where "make quick" in swap/test works.
There is some wierd stuff here because TimBL and I couldn't
figure out how to share the chatty global across modules.
Surely Daniel K and DanC should be able figure that out.
Some environment variables this uses:
CWM_VERBOSITY - Sets the internal verbosity of the system.
CWM_LIST_FILES - ???
"""
__version__ = "$id$"
import sys
import os, traceback
from codecs import utf_8_encode
##lineCount = [0]
def progress(*args):
"""Logs a debug statement?
"""
level = len(traceback.extract_stack())
sys.stderr.write(" " * level)
for a in args:
i = 0
a = unicode(a)
# Indent all the levels of each of the args.
while 1:
## lineCount[0] += 1
i = a.find("\n", i)
if i < 0: break
a = a[:i+1] + (" " * level) + a[i+1:]
i = i + 1
q = utf_8_encode(u"%s " % (a,))[0]
sys.stderr.write(q)
## if lineCount[0] > 20:
## lineCount[0] = 0
## sys.stdin.readline()
sys.stderr.write("\n")
global chatty_flag # verbosity debug flag
#chatty_flag =0
chatty_flag = int(os.environ.get("CWM_VERBOSITY", 0))
global print_all_file_names
print_all_file_names = int(os.environ.get("CWM_LIST_FILES", 0))
global file_list
file_list = []
global tracking
tracking = 0 # Are we keeping reason information for proof generation?
def setTracking(x):
"""Set the level of tracking of the system. (unused?)
"""
global tracking
chatty_flag = x
def setVerbosity(x):
"""Set the level of verbosity of the system.
"""
global chatty_flag
chatty_flag = x
def verbosity():
"""Get the level of verbosity of the system.
"""
global chatty_flag
return chatty_flag
def printState(prefix="#trace# "):
"""Output the (caller's) function name and local variables.
"""
frame = sys._getframe(1) # caller's state
sys.stderr.write(prefix +
str(frame.f_code.co_name) + " " +
str(frame.f_locals['self']) + "\n")
for varname in frame.f_locals.keys():
if varname == "self": continue
sys.stderr.write("%s %-8s: %s\n" %
(prefix, varname, frame.f_locals[varname]))
sys.stderr.write(prefix+"\n")