2 import traceback, sys, string, time, socket, os
9 if os.environ.has_key(
'PYCLEARSILVER_BUGS_PATH'):
10 DUMP_DIR = os.environ[
'PYCLEARSILVER_BUGS_PATH']
12 Warning =
"handle_error.Warning" 15 LV_MESSAGE =
"LV_MESSAGE" 16 LV_WARNING =
"LV_WARNING" 25 return "%s.%s" % (str(sys.exc_type), str(sys.exc_value))
29 sfp = cStringIO.StringIO()
32 exception = sfp.getvalue()
43 gErrorCount = gErrorCount + 1
45 tb_list = traceback.format_exception(sys.exc_type,sys.exc_value,sys.exc_traceback)
47 sys.stderr.write (
"%s\n" % msg)
49 msg =
"Unhandled Exception" 51 sys.stderr.write (string.join(tb_list,
""))
54 if dump:
dump_bug(lvl,
"handleException", msg, string.join(tb_list,
""))
59 header =
"*** handleWarning: %s\n" % msg
60 sys.stderr.write(header)
61 tb = who_calls.pretty_who_calls(strip=1) +
"\n" 65 dump_bug(LV_WARNING,
"handleException", msg, tb)
71 os.path.join (DUMP_DIR,
"tmp"),
72 os.path.join (DUMP_DIR,
"new"))
74 if not os.path.isdir(path):
78 def dump_bug (level, etype, msg, location=None, nhdf=None):
80 if DISABLE_DUMP:
return 82 now = int(time.time())
85 import neo_cgi, neo_util
87 hdf.setValue(
"Required.Level", level)
88 hdf.setValue(
"Required.When", str(int(time.time())))
89 hdf.setValue(
"Required.Type", etype)
90 hdf.setValue(
"Required.Title", msg)
91 hdf.setValue(
"Optional.Hostname", socket.gethostname())
93 hdf.setValue(
"Optional.Location", location)
95 for (key, value)
in os.environ.items():
96 hdf.setValue (
"Environ.%s" % key, value)
100 fname =
"%d.%d_%d.%s" % (now, pid, Count, socket.gethostname())
103 tpath = os.path.join (DUMP_DIR,
"tmp", fname)
104 npath = os.path.join (DUMP_DIR,
"new", fname)
107 os.rename(tpath, npath)
108 except os.error, reason:
109 warn(
"unable to write bug file", tpath)
110 warn(
"reason:", reason)
def handleWarning(msg="")
def dump_bug(level, etype, msg, location=None, nhdf=None)
def handleException(msg=None, lvl=LV_ERROR, dump=1)