]> git.ipfire.org Git - ipfire-3.x.git/blobdiff - src/pomona/exception.py
Daily checkin.
[ipfire-3.x.git] / src / pomona / exception.py
index 3a018a8b8004576d40d3d02e063cd7475aff2d77..36fd2b004e994057332887fc48fb3bd0bba3fc21 100644 (file)
@@ -1,19 +1,17 @@
+#!/usr/bin/python
 
-import bdb
-import os, sys, signal, types
-from cPickle import Pickler
-from string import joinfields
+import os
+import signal
+import string
+import sys
 import traceback
+import types
 
-import gettext
-_ = lambda x: gettext.ldgettext("pomona", x)
-
-import logging
-log = logging.getLogger("pomona")
+from cPickle import Pickler
 
 dumpHash = {}
 
-def dumpClass(instance, fd, level=0, parentkey="", skipList=[]):
+def dumpClass(instance, fd, level=0, parentkey=""):
     # protect from loops
     try:
         if not dumpHash.has_key(instance):
@@ -26,11 +24,11 @@ def dumpClass(instance, fd, level=0, parentkey="", skipList=[]):
         return
 
     if (instance.__class__.__dict__.has_key("__str__") or
-                    instance.__class__.__dict__.has_key("__repr__")):
+            instance.__class__.__dict__.has_key("__repr__")):
         fd.write("%s\n" % (instance,))
         return
-    fd.write("%s instance, containing members:\n" %
-             (instance.__class__.__name__))
+
+    fd.write("%s instance, containing members:\n" % (instance.__class__.__name__))
     pad = ' ' * ((level) * 2)
 
     for key, value in instance.__dict__.items():
@@ -39,12 +37,6 @@ def dumpClass(instance, fd, level=0, parentkey="", skipList=[]):
         else:
             curkey = key
 
-        # Don't dump objects that are in our skip list, though ones that are
-        # None are probably okay.
-        if eval("instance.%s is not None" % key) and \
-                eval("id(instance.%s)" % key) in skipList:
-            continue
-
     if type(value) == types.ListType:
         fd.write("%s%s: [" % (pad, curkey))
         first = 1
@@ -54,10 +46,11 @@ def dumpClass(instance, fd, level=0, parentkey="", skipList=[]):
             else:
                 first = 0
             if type(item) == types.InstanceType:
-                dumpClass(item, fd, level + 1, skipList=skipList)
+                dumpClass(item, fd, level + 1,)
             else:
                 fd.write("%s" % (item,))
             fd.write("]\n")
+
     elif type(value) == types.DictType:
         fd.write("%s%s: {" % (pad, curkey))
         first = 1
@@ -71,28 +64,19 @@ def dumpClass(instance, fd, level=0, parentkey="", skipList=[]):
             else:
                 fd.write("%s: " % (k,))
             if type(v) == types.InstanceType:
-                dumpClass(v, fd, level + 1, parentkey = curkey, skipList=skipList)
+                dumpClass(v, fd, level + 1, parentkey = curkey)
             else:
                 fd.write("%s" % (v,))
             fd.write("}\n")
+
     elif type(value) == types.InstanceType:
         fd.write("%s%s: " % (pad, curkey))
-        dumpClass(value, fd, level + 1, parentkey=curkey, skipList=skipList)
+        dumpClass(value, fd, level + 1, parentkey=curkey)
+
     else:
         fd.write("%s%s: %s\n" % (pad, curkey, value))
 
-def dumpException(out, text, tb, pomona):
-    skipList = []
-    idSkipList = []
-
-    # Catch attributes that do not exist at the time we do the exception dump
-    # and ignore them.
-    for k in skipList:
-        try:
-            eval("idSkipList.append(id(%s))" % k)
-        except:
-            pass
-
+def dumpException(out, text, tb, installer):
     p = Pickler(out)
 
     out.write(text)
@@ -111,7 +95,7 @@ def dumpException(out, text, tb, pomona):
 
     try:
         out.write("\n\n")
-        dumpClass(pomona, out, skipList=idSkipList)
+        dumpClass(installer, out)
     except:
         out.write("\nException occurred during state dump:\n")
         traceback.print_exc(None, out)
@@ -139,31 +123,29 @@ def formatException(type, value, tb):
     lst.extend(traceback.format_exception_only(type, value))
     return lst
 
-def handleException(pomona, (type, value, tb)):
-    if isinstance(value, bdb.BdbQuit):
-        sys.exit(1)
-
+def handleException(installer, (type, value, tb)):
     # restore original exception handler
     sys.excepthook = sys.__excepthook__
 
+    installer.log.error("Exception occured. Read more in /tmp/instdump.txt.")
+
     # get traceback information
     list = formatException(type, value, tb)
-    text = joinfields(list, "")
+    text = string.joinfields(list, "")
 
-    # save to local storage first
+    # save to local storage
     out = open("/tmp/instdump.txt", "w")
-    dumpException(out, text, tb, pomona)
+    dumpException(out, text, tb, installer)
     out.close()
 
-    win = pomona.intf.exceptionWindow(text, "/tmp/instdump.txt")
+    win = installer.intf.exceptionWindow(text, "/tmp/instdump.txt")
     if not win:
-        pomona.intf.__del__()
+        installer.intf.__del__()
         os.kill(os.getpid(), signal.SIGKILL)
 
     while 1:
         win.run()
-        rc = win.getrc()
 
-        if rc == 0:
-            pomona.intf.__del__()
+        if win.getrc() == 0:
+            installer.intf.__del__()
             os.kill(os.getpid(), signal.SIGKILL)