Index: pykota/trunk/setup.py
===================================================================
--- pykota/trunk/setup.py (revision 1111)
+++ pykota/trunk/setup.py (revision 1113)
@@ -23,4 +23,7 @@
 #
 # $Log$
+# Revision 1.23  2003/07/29 20:55:17  jalet
+# 1.14 is out !
+#
 # Revision 1.22  2003/07/29 09:54:03  jalet
 # Added configurable LDAP mail attribute support
@@ -271,4 +274,5 @@
     sys.stdout.write("DATABASE SCHEMA USING initscripts/postgresql/upgrade-to-1.14.sql\n")
     sys.stdout.write("PLEASE READ DOCUMENTATION IN initscripts/postgresql/ TO LEARN HOW TO DO.\n")
+    sys.stdout.write("YOU CAN DO THAT AFTER THE INSTALLATION IS FINISHED, OR PRESS CTRL+C NOW.\n")
     sys.stdout.write("\n\nYOU DON'T HAVE ANYTHING SPECIAL TO DO IF THIS IS YOUR FIRST INSTALLATION.\n\n")
     dummy = raw_input("Please press ENTER when you have read the message above. ")
Index: pykota/trunk/pykota/tool.py
===================================================================
--- pykota/trunk/pykota/tool.py (revision 1091)
+++ pykota/trunk/pykota/tool.py (revision 1113)
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.49  2003/07/29 20:55:17  jalet
+# 1.14 is out !
+#
 # Revision 1.48  2003/07/21 23:01:56  jalet
 # Modified some messages aout soft limit
@@ -234,6 +237,14 @@
         self.smtpserver = self.config.getSMTPServer()
         
+    def clean(self) :    
+        """Ensures that the database is closed."""
+        try :
+            self.storage.close()
+        except (TypeError, NameError, AttributeError) :    
+            pass
+            
     def display_version_and_quit(self) :
         """Displays version number, then exists successfully."""
+        self.clean()
         print version.__version__
         sys.exit(0)
@@ -241,4 +252,5 @@
     def display_usage_and_quit(self) :
         """Displays command line usage, then exists successfully."""
+        self.clean()
         print self.documentation
         sys.exit(0)
Index: pykota/trunk/pykota/storages/pgstorage.py
===================================================================
--- pykota/trunk/pykota/storages/pgstorage.py (revision 1087)
+++ pykota/trunk/pykota/storages/pgstorage.py (revision 1113)
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.11  2003/07/29 20:55:17  jalet
+# 1.14 is out !
+#
 # Revision 1.10  2003/07/16 21:53:08  jalet
 # Really big modifications wrt new configuration file's location and content.
@@ -90,4 +93,8 @@
             
     def __del__(self) :        
+        """Ensures that the database connection is closed."""
+        self.close()
+        
+    def close(self) :    
         """Closes the database connection."""
         if not self.closed :
Index: pykota/trunk/pykota/storages/ldapstorage.py
===================================================================
--- pykota/trunk/pykota/storages/ldapstorage.py (revision 1112)
+++ pykota/trunk/pykota/storages/ldapstorage.py (revision 1113)
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.24  2003/07/29 20:55:17  jalet
+# 1.14 is out !
+#
 # Revision 1.23  2003/07/29 19:52:32  jalet
 # Forgot to read the email field from LDAP
@@ -143,4 +146,8 @@
             
     def __del__(self) :        
+        """Ensures that the database connection is closed."""
+        self.close()
+        
+    def close(self) :    
         """Closes the database connection."""
         if not self.closed :
Index: pykota/trunk/pykota/version.py
===================================================================
--- pykota/trunk/pykota/version.py (revision 1111)
+++ pykota/trunk/pykota/version.py (revision 1113)
@@ -21,5 +21,5 @@
 #
 
-__version__ = "1.14beta2_unofficial"
+__version__ = "1.14_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 1054)
+++ pykota/trunk/cgi-bin/printquota.cgi (revision 1113)
@@ -23,4 +23,7 @@
 #
 # $Log$
+# Revision 1.12  2003/07/29 20:55:17  jalet
+# 1.14 is out !
+#
 # Revision 1.11  2003/07/01 12:37:31  jalet
 # Nicer UI
@@ -179,2 +182,9 @@
     admin.guiAction()
     admin.guiDisplay()
+
+    try :
+        admin.storage.close()
+    except (TypeError, NameError, AttributeError) :    
+        pass
+        
+    sys.exit(0)
Index: pykota/trunk/bin/warnpykota
===================================================================
--- pykota/trunk/bin/warnpykota (revision 1071)
+++ pykota/trunk/bin/warnpykota (revision 1113)
@@ -23,4 +23,7 @@
 #
 # $Log$
+# Revision 1.22  2003/07/29 20:55:17  jalet
+# 1.14 is out !
+#
 # Revision 1.21  2003/07/07 12:19:52  jalet
 # Now repykota and warnpykota --groups check the groups the user is a member of
@@ -199,4 +202,5 @@
                      
 if __name__ == "__main__" : 
+    retcode = 0
     try :
         defaults = { \
@@ -226,8 +230,14 @@
             raise PyKotaToolError, _("incompatible options, see help.")
         else :
-            sys.exit(sender.main(args, options))
+            retcode = sender.main(args, options)
     except (PyKotaToolError, PyKotaConfigError, PyKotaStorageError), msg :            
         sys.stderr.write("%s\n" % msg)
         sys.stderr.flush()
-        sys.exit(-1)
-
+        retcode = -1
+        
+    try :
+        sender.storage.close()
+    except (TypeError, NameError, AttributeError) :    
+        pass
+        
+    sys.exit(retcode)    
Index: pykota/trunk/bin/edpykota
===================================================================
--- pykota/trunk/bin/edpykota (revision 1105)
+++ pykota/trunk/bin/edpykota (revision 1113)
@@ -23,4 +23,7 @@
 #
 # $Log$
+# Revision 1.56  2003/07/29 20:55:17  jalet
+# 1.14 is out !
+#
 # Revision 1.55  2003/07/28 09:11:12  jalet
 # PyKota now tries to add its attributes intelligently in existing LDAP
@@ -538,4 +541,5 @@
                      
 if __name__ == "__main__" : 
+    retcode = 0
     try :
         defaults = { \
@@ -584,8 +588,14 @@
             raise PyKotaToolError, _("incompatible options, see help.")
         else :
-            sys.exit(editor.main(args, options))
+            retcode = editor.main(args, options)
     except (PyKotaToolError, PyKotaConfigError, PyKotaStorageError), msg :            
         sys.stderr.write("%s\n" % msg)
         sys.stderr.flush()
-        sys.exit(-1)
-
+        retcode = -1
+
+    try :
+        editor.storage.close()
+    except (TypeError, NameError, AttributeError) :    
+        pass
+        
+    sys.exit(retcode)    
Index: pykota/trunk/bin/pykota
===================================================================
--- pykota/trunk/bin/pykota (revision 1080)
+++ pykota/trunk/bin/pykota (revision 1113)
@@ -23,4 +23,7 @@
 #
 # $Log$
+# Revision 1.37  2003/07/29 20:55:17  jalet
+# 1.14 is out !
+#
 # Revision 1.36  2003/07/10 06:09:52  jalet
 # Incorrect documentation string
@@ -232,24 +235,21 @@
             return -1
             
-def main() :    
+def main(thefilter) :    
     """Do it, and do it right !"""
-    # Initializes the current tool
-    kotafilter = PyKotaFilter()    
-    
     #
     # If this is a CUPS filter, we should act and die like a CUPS filter when needed
-    if kotafilter.printingsystem == "CUPS" :
+    if thefilter.printingsystem == "CUPS" :
         if len(sys.argv) not in (6, 7) :    
             sys.stderr.write("ERROR: %s job-id user title copies options [file]\n" % sys.argv[0])
-            return kotafilter.removeJob()
+            return thefilter.removeJob()
     
     # Get the last page counter and last username from the Quota Storage backend
-    printer = kotafilter.storage.getPrinter(kotafilter.printername)
+    printer = thefilter.storage.getPrinter(thefilter.printername)
     if not printer.Exists :
         # The printer is unknown from the Quota Storage perspective
         # we let the job pass through, but log a warning message
-        kotafilter.logger.log_message(_("Printer %s not registered in the PyKota system") % kotafilter.printername, "warn")
+        thefilter.logger.log_message(_("Printer %s not registered in the PyKota system") % thefilter.printername, "warn")
     else :    
-        user = kotafilter.storage.getUser(kotafilter.username)
+        user = thefilter.storage.getUser(thefilter.username)
         if not user.Exists :
             # The user is unknown from the Quota Storage perspective
@@ -257,33 +257,41 @@
             # either let the job pass through or reject it, but we
             # log a message in any case.
-            policy = kotafilter.config.getPrinterPolicy(kotafilter.printername)
+            policy = thefilter.config.getPrinterPolicy(thefilter.printername)
             if policy == "ALLOW" :
                 action = "POLICY_ALLOW"
             else :    
                 action = "POLICY_DENY"
-            kotafilter.logger.log_message(_("User %s not registered in the PyKota system, applying default policy (%s) for printer %s") % (kotafilter.username, action, kotafilter.printername), "warn")
+            thefilter.logger.log_message(_("User %s not registered in the PyKota system, applying default policy (%s) for printer %s") % (thefilter.username, action, thefilter.printername), "warn")
             if action == "POLICY_DENY" :
-                return kotafilter.removeJob()
+                return thefilter.removeJob()
         else :
             # Now does the accounting and act depending on the result
-            action = kotafilter.accounter.doAccounting(printer, user)
+            action = thefilter.accounter.doAccounting(printer, user)
             
             # if not allowed to print then die, else proceed.
             if action == "DENY" :
                 # No, just die cleanly
-                return kotafilter.removeJob()
+                return thefilter.removeJob()
         
     # pass the job untouched to the underlying layer
-    kotafilter.accounter.filterInput(kotafilter.inputfile)      
+    thefilter.accounter.filterInput(thefilter.inputfile)      
     
-    return kotafilter.acceptJob()
+    return thefilter.acceptJob()
 
 if __name__ == "__main__" :    
     retcode = -1
     try :
-        retcode = main()
+        # Initializes the current tool
+        kotafilter = PyKotaFilter()    
+        retcode = main(kotafilter)
     except (PyKotaToolError, PyKotaConfigError, PyKotaStorageError, PyKotaAccounterError, AttributeError, KeyError, IndexError, ValueError, IOError), msg :
         sys.stderr.write("ERROR : PyKota filter failed (%s)\n" % msg)
         sys.stderr.flush()
+        retcode = -1
+
+    try :
+        kotafilter.storage.close()
+    except (TypeError, NameError, AttributeError) :    
+        pass
+        
     sys.exit(retcode)    
-    
Index: pykota/trunk/bin/pykotme
===================================================================
--- pykota/trunk/bin/pykotme (revision 1099)
+++ pykota/trunk/bin/pykotme (revision 1113)
@@ -23,4 +23,7 @@
 #
 # $Log$
+# Revision 1.3  2003/07/29 20:55:17  jalet
+# 1.14 is out !
+#
 # Revision 1.2  2003/07/25 10:41:29  jalet
 # Better documentation.
@@ -150,4 +153,5 @@
         
 if __name__ == "__main__" : 
+    retcode = 0
     try :
         defaults = { \
@@ -173,8 +177,14 @@
             sender.display_version_and_quit()
         else :
-            sys.exit(sender.main(args, options))
+            retcode = sender.main(args, options)
     except (PyKotaToolError, PyKotaConfigError, PyKotaStorageError), msg :            
         sys.stderr.write("%s\n" % msg)
         sys.stderr.flush()
-        sys.exit(-1)
+        retcode = -1
 
+    try :
+        sender.storage.close()
+    except (TypeError, NameError, AttributeError) :    
+        pass
+        
+    sys.exit(retcode)    
Index: pykota/trunk/bin/repykota
===================================================================
--- pykota/trunk/bin/repykota (revision 1071)
+++ pykota/trunk/bin/repykota (revision 1113)
@@ -23,4 +23,7 @@
 #
 # $Log$
+# Revision 1.42  2003/07/29 20:55:17  jalet
+# 1.14 is out !
+#
 # Revision 1.41  2003/07/07 12:19:52  jalet
 # Now repykota and warnpykota --groups check the groups the user is a member of
@@ -287,8 +290,14 @@
             raise PyKotaToolError, _("incompatible options, see help.")
         else :
-            sys.exit(reportTool.main(args, options))
+            retcode = reportTool.main(args, options)
     except (PyKotaToolError, PyKotaConfigError, PyKotaStorageError, PyKotaReporterError), msg :            
         sys.stderr.write("%s\n" % msg)
         sys.stderr.flush()
-        sys.exit(-1)
-
+        retcode = -1 
+
+    try :
+        reportTool.storage.close()
+    except (TypeError, NameError, AttributeError) :    
+        pass
+        
+    sys.exit(retcode)    
Index: pykota/trunk/NEWS
===================================================================
--- pykota/trunk/NEWS (revision 1111)
+++ pykota/trunk/NEWS (revision 1113)
@@ -22,4 +22,10 @@
 PyKota NEWS :
 
+    - 1.14 : 
+    
+        - The PostgreSQL database connection is now always closed before
+          exit. The LDAP database connection too, but it didn't suffer
+          from the problem anyway, AFAICT.
+        
     - 1.14beta2 :
     
