Index: /pykota/trunk/bin/edpykota
===================================================================
--- /pykota/trunk/bin/edpykota (revision 2147)
+++ /pykota/trunk/bin/edpykota (revision 2210)
@@ -506,4 +506,5 @@
         # Initializes the command line tool
         editor = EdPyKota(doc=__doc__)
+        editor.deferredInit()
         
         # parse and checks the command line
Index: /pykota/trunk/bin/pykotme
===================================================================
--- /pykota/trunk/bin/pykotme (revision 2147)
+++ /pykota/trunk/bin/pykotme (revision 2210)
@@ -131,4 +131,5 @@
         # Initializes the command line tool
         sender = PyKotMe(doc=__doc__)
+        sender.deferredInit()
         
         # parse and checks the command line
Index: /pykota/trunk/bin/pkhint
===================================================================
--- /pykota/trunk/bin/pkhint (revision 2147)
+++ /pykota/trunk/bin/pkhint (revision 2210)
@@ -28,7 +28,5 @@
 import os
 
-from pykota.tool import PyKotaTool, PyKotaToolError, crashed, N_
-from pykota.config import PyKotaConfigError
-from pykota.storage import PyKotaStorageError
+from pykota.tool import Tool, PyKotaToolError, crashed, N_
 try :
     import pysnmp
@@ -89,5 +87,5 @@
               ]
               
-class PKHint(PyKotaTool) :
+class PKHint(Tool) :
     """A class to autodetect the best accounting method for printers."""
     def extractPrintersInformation(self) :    
@@ -237,4 +235,5 @@
         # Initializes the command line tool
         manager = PKHint(doc=__doc__)
+        manager.deferredInit()
         
         (options, args) = manager.parseCommandline(sys.argv[1:], short_options, long_options)
@@ -260,9 +259,4 @@
             crashed("pkhint failed")
         retcode = -1
-
-    try :
-        manager.storage.close()
-    except (TypeError, NameError, AttributeError) :    
-        pass
         
     sys.exit(retcode)    
Index: /pykota/trunk/bin/repykota
===================================================================
--- /pykota/trunk/bin/repykota (revision 2147)
+++ /pykota/trunk/bin/repykota (revision 2210)
@@ -138,4 +138,5 @@
         # Initializes the command line tool
         reportTool = RePyKota(doc=__doc__)
+        reportTool.deferredInit()
         
         # parse and checks the command line
Index: /pykota/trunk/bin/warnpykota
===================================================================
--- /pykota/trunk/bin/warnpykota (revision 2147)
+++ /pykota/trunk/bin/warnpykota (revision 2210)
@@ -153,4 +153,5 @@
         # Initializes the command line tool
         sender = WarnPyKota(doc=__doc__)
+        sender.deferredInit()
         
         # parse and checks the command line
Index: /pykota/trunk/bin/pkbanner
===================================================================
--- /pykota/trunk/bin/pkbanner (revision 2193)
+++ /pykota/trunk/bin/pkbanner (revision 2210)
@@ -303,4 +303,5 @@
         # Initializes the command line tool
         banner = PyKotaBanner(doc=__doc__)
+        banner.deferredInit()
         
         # parse and checks the command line
Index: /pykota/trunk/bin/autopykota
===================================================================
--- /pykota/trunk/bin/autopykota (revision 2147)
+++ /pykota/trunk/bin/autopykota (revision 2210)
@@ -108,4 +108,5 @@
         # Initializes the command line tool
         automat = AutoPyKota(doc=__doc__)
+        automat.deferredInit()
         
         # parse and checks the command line
Index: /pykota/trunk/bin/pkprinters
===================================================================
--- /pykota/trunk/bin/pkprinters (revision 2147)
+++ /pykota/trunk/bin/pkprinters (revision 2210)
@@ -206,4 +206,5 @@
         # Initializes the command line tool
         manager = PKPrinters(doc=__doc__)
+        manager.deferredInit()
         
         # parse and checks the command line
Index: /pykota/trunk/bin/cupspykota
===================================================================
--- /pykota/trunk/bin/cupspykota (revision 2177)
+++ /pykota/trunk/bin/cupspykota (revision 2210)
@@ -705,16 +705,12 @@
     else :    
         try :
-            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()    
+            # Initializes the backend
+            kotabackend = PyKotaBackend()    
+            kotabackend.deferredInit()
+            retcode = kotabackend.mainWork()
+            kotabackend.storage.close()
+            kotabackend.closeJobDataStream()    
+        except SystemExit :    
+            retcode = -1
         except :
             try :
Index: /pykota/trunk/bin/pykosd
===================================================================
--- /pykota/trunk/bin/pykosd (revision 2147)
+++ /pykota/trunk/bin/pykosd (revision 2210)
@@ -167,4 +167,5 @@
         
         cmd = PyKOSD(doc=__doc__)
+        cmd.deferredInit()
         
         # parse and checks the command line
Index: /pykota/trunk/bin/lprngpykota
===================================================================
--- /pykota/trunk/bin/lprngpykota (revision 2147)
+++ /pykota/trunk/bin/lprngpykota (revision 2210)
@@ -268,16 +268,12 @@
     retcode = JSUCC
     try :
-        try :
-            # Initializes the backend
-            kotabackend = PyKotaFilter()    
-        except SystemExit :    
-            retcode = JABORT
-        except :    
-            crashed("lprngpykota filter initialization failed")
-            retcode = JABORT
-        else :    
-            retcode = kotabackend.mainWork()
-            kotabackend.storage.close()
-            kotabackend.closeJobDataStream()    
+        # Initializes the backend
+        kotabackend = PyKotaFilter()    
+        kotabackend.deferredInit()
+        retcode = kotabackend.mainWork()
+        kotabackend.storage.close()
+        kotabackend.closeJobDataStream()    
+    except SystemExit :    
+        retcode = JABORT
     except :
         try :
Index: /pykota/trunk/bin/pkmail
===================================================================
--- /pykota/trunk/bin/pkmail (revision 2147)
+++ /pykota/trunk/bin/pkmail (revision 2210)
@@ -158,4 +158,5 @@
         # Initializes the command line tool
         mailparser = PKMail(doc=__doc__)
+        mailparser.deferredInit()
         
         # parse and checks the command line
Index: /pykota/trunk/bin/dumpykota
===================================================================
--- /pykota/trunk/bin/dumpykota (revision 2147)
+++ /pykota/trunk/bin/dumpykota (revision 2210)
@@ -138,4 +138,5 @@
         # Initializes the command line tool
         dumper = DumPyKota(doc=__doc__)
+        dumper.deferredInit()
         
         # parse and checks the command line
Index: /pykota/trunk/NEWS
===================================================================
--- /pykota/trunk/NEWS (revision 2202)
+++ /pykota/trunk/NEWS (revision 2210)
@@ -22,4 +22,8 @@
 PyKota NEWS :
        
+    - 1.22alpha6 :
+    
+        - Early errors now produce meaningful error messages (finally !)
+        
     - 1.22alpha5 :
        
Index: /pykota/trunk/pykota/storages/pgstorage.py
===================================================================
--- /pykota/trunk/pykota/storages/pgstorage.py (revision 2147)
+++ /pykota/trunk/pykota/storages/pgstorage.py (revision 2210)
@@ -48,11 +48,7 @@
             port = -1         # Use PostgreSQL's default tcp/ip port (5432).
         
-        try :
-            self.database = pg.connect(host=host, port=port, dbname=dbname, user=user, passwd=passwd)
-        except PGError, msg :
-            raise PyKotaStorageError, str(msg)
-        else :    
-            self.closed = 0
-            self.tool.logdebug("Database opened (host=%s, port=%s, dbname=%s, user=%s)" % (host, port, dbname, user))
+        self.database = pg.connect(host=host, port=port, dbname=dbname, user=user, passwd=passwd)
+        self.closed = 0
+        self.tool.logdebug("Database opened (host=%s, port=%s, dbname=%s, user=%s)" % (host, port, dbname, user))
             
     def close(self) :    
Index: /pykota/trunk/pykota/tool.py
===================================================================
--- /pykota/trunk/pykota/tool.py (revision 2195)
+++ /pykota/trunk/pykota/tool.py (revision 2210)
@@ -74,10 +74,10 @@
         
         # locale stuff
-        defaultToCLocale = 0
+        self.defaultToCLocale = 0
         try :
             locale.setlocale(locale.LC_ALL, lang)
         except (locale.Error, IOError) :
             locale.setlocale(locale.LC_ALL, "C")
-            defaultToCLocale = 1
+            self.defaultToCLocale = 1
         try :
             gettext.install("pykota")
@@ -109,4 +109,6 @@
         self.documentation = doc
         
+    def deferredInit(self) :        
+        """Deferred initialization."""
         # try to find the configuration files in user's 'pykota' home directory.
         try :
@@ -120,19 +122,9 @@
             missingUser = 0
             
-        try :
-            self.config = config.PyKotaConfig(confdir)
-        except ConfigParser.ParsingError, msg :    
-            sys.stderr.write("ERROR: Problem encountered while parsing configuration file : %s\n" % msg)
-            sys.stderr.flush()
-            sys.exit(-1)
-            
-        try :
-            self.debug = self.config.getDebug()
-            self.smtpserver = self.config.getSMTPServer()
-            self.maildomain = self.config.getMailDomain()
-            self.logger = logger.openLogger(self.config.getLoggingBackend())
-        except (config.PyKotaConfigError, logger.PyKotaLoggingError, storage.PyKotaStorageError), msg :
-            self.crashed(msg)
-            raise
+        self.config = config.PyKotaConfig(confdir)
+        self.debug = self.config.getDebug()
+        self.smtpserver = self.config.getSMTPServer()
+        self.maildomain = self.config.getMailDomain()
+        self.logger = logger.openLogger(self.config.getLoggingBackend())
             
         # now drop priviledge if possible
@@ -143,5 +135,5 @@
         self.softwareJobPrice = 0.0
         
-        if defaultToCLocale :
+        if self.defaultToCLocale :
             self.printInfo("Incorrect locale settings. PyKota falls back to the 'C' locale.", "warn")
         if missingUser :     
@@ -201,4 +193,11 @@
         sys.stderr.flush()
         
+    def matchString(self, s, patterns) :
+        """Returns 1 if the string s matches one of the patterns, else 0."""
+        for pattern in patterns :
+            if fnmatch.fnmatchcase(s, pattern) :
+                return 1
+        return 0
+        
     def display_version_and_quit(self) :
         """Displays version number, then exists successfully."""
@@ -302,14 +301,13 @@
         """Initializes the command line tool and opens the database."""
         Tool.__init__(self, lang, charset, doc)
-        try :
-            self.storage = storage.openConnection(self)
-        except storage.PyKotaStorageError, msg :
-            self.crashed(msg)
-            raise
+        
+    def deferredInit(self) :    
+        """Deferred initialization."""
+        Tool.deferredInit(self)
+        self.storage = storage.openConnection(self)
+        if self.config.isAdmin : # TODO : We don't know this before, fix this !
+            self.logdebug("Beware : running as a PyKota administrator !")
         else :    
-            if self.config.isAdmin : # TODO : We don't know this before, fix this !
-                self.logdebug("Beware : running as a PyKota administrator !")
-            else :    
-                self.logdebug("Don't Panic : running as a mere mortal !")
+            self.logdebug("Don't Panic : running as a mere mortal !")
         
     def clean(self) :    
@@ -327,11 +325,4 @@
                 return 0
         return 1        
-        
-    def matchString(self, s, patterns) :
-        """Returns 1 if the string s matches one of the patterns, else 0."""
-        for pattern in patterns :
-            if fnmatch.fnmatchcase(s, pattern) :
-                return 1
-        return 0
         
     def sendMessage(self, adminmail, touser, fullmessage) :
@@ -655,4 +646,8 @@
          self.originalbackend) = self.extractInfoFromCupsOrLprng()
          
+    def deferredInit(self) :
+        """Deferred initialization."""
+        PyKotaTool.deferredInit(self)
+        
         arguments = " ".join(['"%s"' % arg for arg in sys.argv])
         self.logdebug(_("Printing system %s, args=%s") % (str(self.printingsystem), arguments))
Index: /pykota/trunk/pykota/version.py
===================================================================
--- /pykota/trunk/pykota/version.py (revision 2202)
+++ /pykota/trunk/pykota/version.py (revision 2210)
@@ -22,5 +22,5 @@
 #
 
-__version__ = "1.22alpha5_unofficial"
+__version__ = "1.22alpha6_unofficial"
 
 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""
Index: /pykota/trunk/cgi-bin/printquota.cgi
===================================================================
--- /pykota/trunk/cgi-bin/printquota.cgi (revision 2174)
+++ /pykota/trunk/cgi-bin/printquota.cgi (revision 2210)
@@ -231,4 +231,5 @@
     os.environ["LC_ALL"] = getLanguagePreference()
     admin = PyKotaReportGUI(lang=os.environ["LC_ALL"], charset=getCharsetPreference())
+    admin.deferredInit()
     admin.form = cgi.FieldStorage()
     admin.guiAction()
Index: /pykota/trunk/cgi-bin/pykotme.cgi
===================================================================
--- /pykota/trunk/cgi-bin/pykotme.cgi (revision 2174)
+++ /pykota/trunk/cgi-bin/pykotme.cgi (revision 2210)
@@ -137,4 +137,5 @@
     os.environ["LC_ALL"] = getLanguagePreference()
     admin = PyKotMeGUI(lang=os.environ["LC_ALL"], charset=getCharsetPreference())
+    admin.deferredInit()
     admin.form = cgi.FieldStorage()
     admin.guiAction()
Index: /pykota/trunk/cgi-bin/dumpykota.cgi
===================================================================
--- /pykota/trunk/cgi-bin/dumpykota.cgi (revision 2174)
+++ /pykota/trunk/cgi-bin/dumpykota.cgi (revision 2210)
@@ -177,4 +177,5 @@
     os.environ["LC_ALL"] = getLanguagePreference()
     admin = PyKotaDumperGUI(lang=os.environ["LC_ALL"], charset=getCharsetPreference())
+    admin.deferredInit()
     admin.form = cgi.FieldStorage()
     admin.options = { "output" : "-",
