Index: pykota/trunk/pykota/accounters/hardware.py
===================================================================
--- pykota/trunk/pykota/accounters/hardware.py (revision 1703)
+++ pykota/trunk/pykota/accounters/hardware.py (revision 1713)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.13  2004/09/13 16:02:45  jalet
+# Added fix for incorrect job's size when hardware accounting fails
+#
 # Revision 1.12  2004/09/06 15:42:34  jalet
 # Fix missing import statement for the signal module
@@ -105,25 +108,47 @@
         self.LastPageCounter = self.counterafter = self.getPrinterInternalPageCounter()
         
-    def getJobSize(self) :    
+    def getJobSize(self, printer) :    
         """Returns the actual job size."""
-        try :
-            jobsize = (self.counterafter - self.counterbefore)    
-            if jobsize < 0 :
-                # Try to take care of HP printers 
-                # Their internal page counter is saved to NVRAM
-                # only every 10 pages. If the printer was switched
-                # off then back on during the job, and that the
-                # counters difference is negative, we know 
-                # the formula (we can't know if more than eleven
-                # pages were printed though) :
-                if jobsize > -10 :
-                    jobsize += 10
-                else :    
-                    # here we may have got a printer being replaced
-                    # DURING the job. This is HIGHLY improbable !
-                    jobsize = 0
-        except :    
-            # takes care of the case where one counter (or both) was never set.
-            jobsize = 0
+        if (not self.counterbefore) or (not self.counterafter) :
+            # there was a problem retrieving page counter
+            self.filter.printInfo(_("A problem occured while reading printer %s's internal page counter.") % printer.Name, "warn")
+            if printer.LastJob.Exists :
+                # if there's a previous job, use the last value from database
+                self.filter.printInfo(_("Retrieving printer %s's page counter from database instead.") % printer.Name, "warn")
+                if not self.counterbefore : 
+                    self.counterbefore = printer.LastJob.PrinterPageCounter or 0
+                if not self.counterafter :
+                    self.counterafter = printer.LastJob.PrinterPageCounter or 0
+                before = min(self.counterbefore, self.counterafter)    
+                after = max(self.counterbefore, self.counterafter)    
+                self.counterbefore = before
+                self.counterafter = after
+                if self.counterbefore == self.counterafter :
+                    self.filter.printInfo(_("Couldn't retrieve printer %s's internal page counter either before or after printing.") % printer.Name, "warn")
+                    self.filter.printInfo(_("Job's size forced to 1 page for printer %s.") % printer.Name, "warn")
+                    self.counterafter = self.counterbefore + 1
+            else :
+                self.filter.printInfo(_("No previous job in database for printer %s.") % printer.Name, "warn")
+                self.filter.printInfo(_("Job's size forced to 1 page for printer %s.") % printer.Name, "warn")
+                self.counterbefore = 0
+                self.counterafter = 1
+                
+        jobsize = (self.counterafter - self.counterbefore)    
+        if jobsize < 0 :
+            # Try to take care of HP printers 
+            # Their internal page counter is saved to NVRAM
+            # only every 10 pages. If the printer was switched
+            # off then back on during the job, and that the
+            # counters difference is negative, we know 
+            # the formula (we can't know if more than eleven
+            # pages were printed though) :
+            if jobsize > -10 :
+                jobsize += 10
+            else :    
+                # here we may have got a printer being replaced
+                # DURING the job. This is HIGHLY improbable !
+                self.filter.printInfo(_("Inconsistent values for printer %s's internal page counter.") % printer.Name, "warn")
+                self.filter.printInfo(_("Job's size forced to 1 page for printer %s.") % printer.Name, "warn")
+                jobsize = 1
         return jobsize
         
Index: pykota/trunk/pykota/accounter.py
===================================================================
--- pykota/trunk/pykota/accounter.py (revision 1687)
+++ pykota/trunk/pykota/accounter.py (revision 1713)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.20  2004/09/13 16:02:45  jalet
+# Added fix for incorrect job's size when hardware accounting fails
+#
 # Revision 1.19  2004/08/31 23:29:53  jalet
 # Introduction of the new 'onaccountererror' configuration directive.
@@ -140,5 +143,5 @@
         pass
         
-    def getJobSize(self) :    
+    def getJobSize(self, printer) :    
         """Returns the actual job size."""
         try :
Index: pykota/trunk/pykota/version.py
===================================================================
--- pykota/trunk/pykota/version.py (revision 1705)
+++ pykota/trunk/pykota/version.py (revision 1713)
@@ -22,5 +22,5 @@
 #
 
-__version__ = "1.20alpha9_unofficial"
+__version__ = "1.20alpha10_unofficial"
 
 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""
Index: pykota/trunk/bin/cupspykota
===================================================================
--- pykota/trunk/bin/cupspykota (revision 1704)
+++ pykota/trunk/bin/cupspykota (revision 1713)
@@ -24,4 +24,7 @@
 #
 # $Log$
+# Revision 1.72  2004/09/13 16:02:44  jalet
+# Added fix for incorrect job's size when hardware accounting fails
+#
 # Revision 1.71  2004/09/06 17:05:06  jalet
 # Fix for autodetection of SC_OPEN_MAX
@@ -439,5 +442,5 @@
                 self.printInfo(_("Job size forced to 0 because printing is denied."))
             else :    
-                jobsize = self.accounter.getJobSize()
+                jobsize = self.accounter.getJobSize(printer)
             self.printInfo(_("Job size : %i") % jobsize)
             
Index: pykota/trunk/bin/lprngpykota
===================================================================
--- pykota/trunk/bin/lprngpykota (revision 1696)
+++ pykota/trunk/bin/lprngpykota (revision 1713)
@@ -24,4 +24,7 @@
 #
 # $Log$
+# Revision 1.7  2004/09/13 16:02:44  jalet
+# Added fix for incorrect job's size when hardware accounting fails
+#
 # Revision 1.6  2004/09/02 14:40:13  jalet
 # Another bunch of LPRng fixes
@@ -141,5 +144,5 @@
         if self.accounter.isSoftware :
             self.accounter.endJob(printer)
-            jobsize = self.accounter.getJobSize()
+            jobsize = self.accounter.getJobSize(printer)
             self.logdebug("Job accounting ends.")
             
@@ -216,5 +219,5 @@
                 
             # retrieve the job size    
-            jobsize = self.accounter.getJobSize()
+            jobsize = self.accounter.getJobSize(printer)
             
             self.logdebug("Job size : %i" % jobsize)
Index: pykota/trunk/NEWS
===================================================================
--- pykota/trunk/NEWS (revision 1705)
+++ pykota/trunk/NEWS (revision 1713)
@@ -22,4 +22,9 @@
 PyKota NEWS :
 
+    - 1.20alpha10 :
+    
+        - Added fix for incorrect job's size computation when
+          hardware accounting fails.
+          
     - 1.20alpha9 :
     
