]>
git.ipfire.org Git - ipfire-3.x.git/blob - src/pomona/exception.py
3 import os
, sys
, signal
, types
4 from cPickle
import Pickler
5 from string
import joinfields
9 _
= lambda x
: gettext
.ldgettext("pomona", x
)
12 log
= logging
.getLogger("pomona")
16 def dumpClass(instance
, fd
, level
=0, parentkey
="", skipList
=[]):
19 if not dumpHash
.has_key(instance
):
20 dumpHash
[instance
] = None
22 fd
.write("Already dumped\n")
25 fd
.write("Cannot dump object\n")
28 if (instance
.__class
__.__dict
__.has_key("__str__") or
29 instance
.__class
__.__dict
__.has_key("__repr__")):
30 fd
.write("%s\n" % (instance
,))
32 fd
.write("%s instance, containing members:\n" %
33 (instance
.__class
__.__name
__))
34 pad
= ' ' * ((level
) * 2)
36 for key
, value
in instance
.__dict
__.items():
38 curkey
= parentkey
+ "." + key
42 # Don't dump objects that are in our skip list, though ones that are
43 # None are probably okay.
44 if eval("instance.%s is not None" % key
) and \
45 eval("id(instance.%s)" % key
) in skipList
:
48 if type(value
) == types
.ListType
:
49 fd
.write("%s%s: [" % (pad
, curkey
))
56 if type(item
) == types
.InstanceType
:
57 dumpClass(item
, fd
, level
+ 1, skipList
=skipList
)
59 fd
.write("%s" % (item
,))
61 elif type(value
) == types
.DictType
:
62 fd
.write("%s%s: {" % (pad
, curkey
))
64 for k
, v
in value
.items():
69 if type(k
) == types
.StringType
:
70 fd
.write("'%s': " % (k
,))
72 fd
.write("%s: " % (k
,))
73 if type(v
) == types
.InstanceType
:
74 dumpClass(v
, fd
, level
+ 1, parentkey
= curkey
, skipList
=skipList
)
78 elif type(value
) == types
.InstanceType
:
79 fd
.write("%s%s: " % (pad
, curkey
))
80 dumpClass(value
, fd
, level
+ 1, parentkey
=curkey
, skipList
=skipList
)
82 fd
.write("%s%s: %s\n" % (pad
, curkey
, value
))
84 def dumpException(out
, text
, tb
, pomona
):
88 # Catch attributes that do not exist at the time we do the exception dump
92 eval("idSkipList.append(id(%s))" % k
)
101 if trace
is not None:
103 trace
= trace
.tb_next
104 frame
= trace
.tb_frame
105 out
.write("\nLocal variables in innermost frame:\n")
107 for (key
, value
) in frame
.f_locals
.items():
108 out
.write("%s: %s\n" % (key
, value
))
114 dumpClass(pomona
, out
, skipList
=idSkipList
)
116 out
.write("\nException occurred during state dump:\n")
117 traceback
.print_exc(None, out
)
119 for file in ("/root/syslog", "/root/pomona.log", "/root/install.log"):
122 line
= "\n\n%s:\n" % (file,)
130 out
.write("\nException occurred during %s file copy:\n" % (file,))
131 traceback
.print_exc(None, out
)
133 # Reverse the order that tracebacks are printed so people will hopefully quit
134 # giving us the least useful part of the exception in bug reports.
135 def formatException(type, value
, tb
):
136 lst
= traceback
.format_tb(tb
)
138 lst
.insert(0, 'Traceback (most recent call first):\n')
139 lst
.extend(traceback
.format_exception_only(type, value
))
142 def handleException(pomona
, (type, value
, tb
)):
143 if isinstance(value
, bdb
.BdbQuit
):
146 # restore original exception handler
147 sys
.excepthook
= sys
.__excepthook
__
149 # get traceback information
150 list = formatException(type, value
, tb
)
151 text
= joinfields(list, "")
153 # save to local storage first
154 out
= open("/tmp/instdump.txt", "w")
155 dumpException(out
, text
, tb
, pomona
)
158 win
= pomona
.intf
.exceptionWindow(text
, "/tmp/instdump.txt")
160 pomona
.intf
.__del
__()
161 os
.kill(os
.getpid(), signal
.SIGKILL
)
168 pomona
.intf
.__del
__()
169 os
.kill(os
.getpid(), signal
.SIGKILL
)