Index: pykota/trunk/pykota/tool.py
===================================================================
--- pykota/trunk/pykota/tool.py (revision 1541)
+++ pykota/trunk/pykota/tool.py (revision 1542)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.102  2004/06/17 13:26:51  jalet
+# Better exception handling code
+#
 # Revision 1.101  2004/06/16 20:56:34  jalet
 # Smarter initialisation code
@@ -424,4 +427,5 @@
             sys.stderr.flush()
             sys.exit(-1)
+            
         try :
             self.debug = self.config.getDebug()
@@ -466,5 +470,5 @@
         for line in traceback.format_exception(*sys.exc_info()) :
             lines.extend([l for l in line.split("\n") if l])
-        msg = "ERROR : ".join(["%s\n" % l for l in ([message] + lines)])
+        msg = "ERROR: ".join(["%s\n" % l for l in ([message] + lines)])
         sys.stderr.write(msg)
         sys.stderr.flush()
Index: pykota/trunk/pykota/version.py
===================================================================
--- pykota/trunk/pykota/version.py (revision 1541)
+++ pykota/trunk/pykota/version.py (revision 1542)
@@ -22,5 +22,5 @@
 #
 
-__version__ = "1.19alpha21_unofficial"
+__version__ = "1.19alpha22_unofficial"
 
 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""
Index: pykota/trunk/bin/cupspykota
===================================================================
--- pykota/trunk/bin/cupspykota (revision 1541)
+++ pykota/trunk/bin/cupspykota (revision 1542)
@@ -24,4 +24,7 @@
 #
 # $Log$
+# Revision 1.63  2004/06/17 13:26:50  jalet
+# Better exception handling code
+#
 # Revision 1.62  2004/06/16 20:56:34  jalet
 # Smarter initialisation code
@@ -642,6 +645,17 @@
         return retcode    
     
+def crashed(message) :    
+    """Minimal crash method."""
+    import traceback
+    lines = []
+    for line in traceback.format_exception(*sys.exc_info()) :
+        lines.extend([l for l in line.split("\n") if l])
+    msg = "ERROR: ".join(["%s\n" % l for l in ([message] + lines)])
+    sys.stderr.write(msg)
+    sys.stderr.flush()
+
 if __name__ == "__main__" :    
     # This is a CUPS backend, we should act and die like a CUPS backend
+    retcode = 0
     if len(sys.argv) == 1 :
         # we will execute each existing backend in device enumeration mode
@@ -680,5 +694,5 @@
                             fullname = fullname[1:-1]
                         print '%s cupspykota:%s "PyKota+%s" "PyKota managed %s"' % (devicetype, device, name, fullname)
-        retcode = 0
+        retcode = 0                
     elif len(sys.argv) not in (6, 7) :    
         sys.stderr.write("ERROR: %s job-id user title copies options [file]\n" % sys.argv[0])
@@ -686,25 +700,22 @@
     else :    
         try :
-            # Initializes the backend
-            kotabackend = PyKotaBackend()    
-            retcode = kotabackend.mainWork()
+            try :
+                # Initializes the backend
+                kotabackend = PyKotaBackend()    
+            except SystemExit :    
+                retcode = -1
+            except :    
+                crashed("cupspykota backend initialization failed")
+                retcode = 1
+            else :    
+                retcode = kotabackend.mainWork()
+                kotabackend.storage.close()
+                kotabackend.closeJobDataStream()    
         except :
             try :
                 kotabackend.crashed("cupspykota backend failed")
             except :    
-                pass
-            retcode = 1
-        
-        try :
-            kotabackend.storage.close()
-        except (TypeError, NameError, AttributeError) :    
-            pass
-            
-        try :
-            kotabackend.closeJobDataStream()    
-        except NameError, msg :    
-            sys.stderr.write("ERROR: PyKota's CUPS backend wrapper didn't initialize correctly : %s\n" % msg)
-            sys.stderr.flush()
-            retcode = 1
+                crashed("cupspykota backend failed")
+            retcode = 1    
         
     sys.exit(retcode)    
Index: pykota/trunk/NEWS
===================================================================
--- pykota/trunk/NEWS (revision 1541)
+++ pykota/trunk/NEWS (revision 1542)
@@ -22,7 +22,11 @@
 PyKota NEWS :
 
+    - 1.19alpha22 :
+    
+        - Even better debugging code.
+        
     - 1.19alpha21 :
     
-        - Additionnal check
+        - Additionnal check.
         
     - 1.19alpha20 :
