Index: /pykota/trunk/conf/pykota.conf.sample
===================================================================
--- /pykota/trunk/conf/pykota.conf.sample (revision 1622)
+++ /pykota/trunk/conf/pykota.conf.sample (revision 1687)
@@ -302,4 +302,25 @@
 # accounter: hardware(/usr/share/pykota/waitprinter.sh %(printer)s && /usr/bin/snmpget -v1 -c public -Ov %(printer)s mib-2.43.10.2.1.4.1.1 | cut -f 2,2 -d " ")
 accounter: software(/usr/bin/pkpgcounter)
+
+# What should we do if the accounter's subprocess doesn't return
+# a valid result (for example doesn't return an integer on its stdout)
+#
+# Valid values are : 'continue' and 'stop'. 'stop' is the default
+# if unset.
+#
+# 'continue' means try to process as usual, this may introduce
+# accounting errors and free jobs. This was the default behavior
+# until v1.20alpha5.
+#
+# 'stop' means fail and stop the print queue. If an accounter
+# error occurs, most of the time this is a misconfiguration, so
+# stopping the print queue is usually the better thing to do 
+# until the admin has fixed the configuration.
+#
+# This value can be set either globally or on a per printer basis
+# If both are defined, the printer option has priority.
+#
+# onaccountererror: continue
+onaccountererror: stop
 
 # Print Quota administrator
Index: /pykota/trunk/pykota/accounters/software.py
===================================================================
--- /pykota/trunk/pykota/accounters/software.py (revision 1680)
+++ /pykota/trunk/pykota/accounters/software.py (revision 1687)
@@ -22,4 +22,10 @@
 #
 # $Log$
+# Revision 1.10  2004/08/31 23:29:53  jalet
+# Introduction of the new 'onaccountererror' configuration directive.
+# Small fix for software accounter's return code which can't be None anymore.
+# Make software and hardware accounting code look similar : will be factorized
+# later.
+#
 # Revision 1.9  2004/08/25 22:34:39  jalet
 # Now both software and hardware accounting raise an exception when no valid
@@ -99,18 +105,19 @@
         
         try :
-            retcode = child.wait()
+            status = child.wait()
         except OSError, msg :    
             self.filter.printInfo(_("Problem while waiting for software accounter pid %s to exit : %s") % (child.pid, msg))
         else :    
-            if os.WIFEXITED(retcode) :
-                status = os.WEXITSTATUS(retcode)
-            else :    
-                status = retcode
+            if os.WIFEXITED(status) :
+                status = os.WEXITSTATUS(status)
             self.filter.printInfo(_("Software accounter %s exit code is %s") % (self.arguments, str(status)))
             
         if pagecounter is None :    
-            raise PyKotaAccounterError, _("Unable to compute job size with accounter %s") % self.arguments
+            message = _("Unable to compute job size with accounter %s") % self.arguments
+            if self.onerror == "CONTINUE" :
+                self.filter.printInfo(message, "error")
+            else :
+                raise PyKotaAccounterError, message
             
-        self.filter.logdebug("Software accounter %s said job is %s pages long." % (self.arguments, pagecounter))
-        return pagecounter    
-            
+        self.filter.logdebug("Software accounter %s said job is %s pages long." % (self.arguments, repr(pagecounter)))
+        return pagecounter or 0
Index: /pykota/trunk/pykota/accounters/hardware.py
===================================================================
--- /pykota/trunk/pykota/accounters/hardware.py (revision 1685)
+++ /pykota/trunk/pykota/accounters/hardware.py (revision 1687)
@@ -22,4 +22,10 @@
 #
 # $Log$
+# Revision 1.11  2004/08/31 23:29:53  jalet
+# Introduction of the new 'onaccountererror' configuration directive.
+# Small fix for software accounter's return code which can't be None anymore.
+# Make software and hardware accounting code look similar : will be factorized
+# later.
+#
 # Revision 1.10  2004/08/27 22:49:04  jalet
 # No answer from subprocess now is really a fatal error. Waiting for some
@@ -154,7 +160,14 @@
         except OSError, msg :    
             self.filter.logdebug("Error while waiting for hardware accounter pid %s : %s" % (child.pid, msg))
-        if (pagecounter is not None) and os.WIFEXITED(status) and (not os.WEXITSTATUS(status)) :
-            return pagecounter
         else :    
-            raise PyKotaAccounterError, _("Unable to query printer %s via HARDWARE(%s)") % (printer, commandline) 
+            if os.WIFEXITED(status) :
+                status = os.WEXITSTATUS(status)
+            self.filter.printInfo(_("Hardware accounter %s exit code is %s") % (self.arguments, str(status)))
             
+        if pagecounter is None :
+            message = _("Unable to query printer %s via HARDWARE(%s)") % (printer, commandline)
+            if self.onerror == "CONTINUE" :
+                self.filter.printInfo(message, "error")
+            else :
+                raise PyKotaAccounterError, message 
+        return pagecounter        
Index: /pykota/trunk/pykota/accounter.py
===================================================================
--- /pykota/trunk/pykota/accounter.py (revision 1624)
+++ /pykota/trunk/pykota/accounter.py (revision 1687)
@@ -22,4 +22,10 @@
 #
 # $Log$
+# Revision 1.19  2004/08/31 23:29:53  jalet
+# Introduction of the new 'onaccountererror' configuration directive.
+# Small fix for software accounter's return code which can't be None anymore.
+# Make software and hardware accounting code look similar : will be factorized
+# later.
+#
 # Revision 1.18  2004/07/22 22:41:48  jalet
 # Hardware accounting for LPRng should be OK now. UNTESTED.
@@ -97,4 +103,5 @@
         self.filter = kotafilter
         self.arguments = arguments
+        self.onerror = self.filter.config.getPrinterOnAccounterError(self.filter.printername)
         self.isSoftware = 1 # by default software accounting
         
Index: /pykota/trunk/pykota/config.py
===================================================================
--- /pykota/trunk/pykota/config.py (revision 1646)
+++ /pykota/trunk/pykota/config.py (revision 1687)
@@ -22,4 +22,10 @@
 #
 # $Log$
+# Revision 1.51  2004/08/31 23:29:53  jalet
+# Introduction of the new 'onaccountererror' configuration directive.
+# Small fix for software accounter's return code which can't be None anymore.
+# Make software and hardware accounting code look similar : will be factorized
+# later.
+#
 # Revision 1.50  2004/07/27 07:07:27  jalet
 # Typo : treshold ==> threshold
@@ -366,4 +372,17 @@
             return enforcement    
             
+    def getPrinterOnAccounterError(self, printername) :    
+        """Returns what must be done whenever the accounter fails."""
+        validactions = [ "CONTINUE", "STOP" ]     
+        try :
+            action = self.getPrinterOption(printername, "onaccountererror")
+        except PyKotaConfigError :    
+            return "STOP"
+        else :    
+            action = action.upper()
+            if action not in validactions :
+                raise PyKotaConfigError, _("Option onaccountererror in section %s only supports values in %s") % (printername, str(validactions))
+            return action  
+            
     def getPrinterPolicy(self, printername) :    
         """Returns the default policy for the current printer."""
Index: /pykota/trunk/pykota/version.py
===================================================================
--- /pykota/trunk/pykota/version.py (revision 1686)
+++ /pykota/trunk/pykota/version.py (revision 1687)
@@ -22,5 +22,5 @@
 #
 
-__version__ = "1.20alpha4_unofficial"
+__version__ = "1.20alpha5_unofficial"
 
 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""
Index: /pykota/trunk/NEWS
===================================================================
--- /pykota/trunk/NEWS (revision 1686)
+++ /pykota/trunk/NEWS (revision 1687)
@@ -22,4 +22,14 @@
 PyKota NEWS :
 
+    - 1.20alpha5 :
+      
+        - Introduces the new configuration directive 'onaccountererror'
+          to specify what must be done whenever the software or
+          hardware accounter fails. Allowed values are 'continue' and
+          'stop' (default). 
+          
+        - Minor fix in software accounter for a recently introduced
+          problem.
+          
     - 1.20alpha4 :
     
