Index: pykota/trunk/conf/pykota.conf.sample
===================================================================
--- pykota/trunk/conf/pykota.conf.sample (revision 2054)
+++ pykota/trunk/conf/pykota.conf.sample (revision 2062)
@@ -603,6 +603,6 @@
 #                else is not set.
 # PYKOTAJOBSIZEBYTES : contains the job's size in bytes. Always available.
-# PYKOTAPRECOMPUTEDJOBSIZE : contains the precomputed job's size (with enforcement: strict)
-# PYKOTAPRECOMPUTEDJOBPRICE : contains the precomputed job's price (with enforcement: strict)
+# PYKOTAPRECOMPUTEDJOBSIZE : contains the precomputed job's size
+# PYKOTAPRECOMPUTEDJOBPRICE : contains the precomputed job's price
 # PYKOTAJOBORIGINATINGHOSTNAME : contains the client's hostname if 
 #                                it is possible to retrieve it.
@@ -730,2 +730,27 @@
 # enforcement : laxist
 enforcement : strict
+
+# Should we trust the job size on this printer ?
+#
+# "yes" is the default, the jobsize, either computed
+# by the hardware or by software is trusted.
+#
+# ">N:precomputed" : uses the precomputed value if jobsize > N pages
+# ">N:25" : uses 25 if jobsize is >N pages
+#
+# General form : ">n:m" where n is a positive integer, and m is 
+# either the word 'precomputed' or a positive integer.
+# The special form "yes" is also accepted and is the default.
+#
+# This directive can be set either globally or on a per printer
+# basis. Use this directive when hardware accounting for a particular
+# printer produces some glitches due to the printer returning 
+# incorrect answers.
+#
+# NB : DON'T MODIFY THIS IF YOU DON'T NEED TO. THIS IS ONLY TO BE USED
+# AS A WORKAROUND FOR SOME PRINTERS. IT'S PROBABLY BETTER TO ALWAYS
+# SET THIS DIRECTIVE TO 'yes'. THIS DIRECTIVE WILL ONLY BE HONORED 
+# IF PYKOTA DETECTS A DIFFERENCE BETWEEN THE PRECOMPUTED JOB SIZE
+# AND THE JOB SIZE AS COMPUTED BY PYKOTA EITHER USING HARDWARE OR
+# SOFTWARE.
+trustjobsize : yes
Index: pykota/trunk/bin/cupspykota
===================================================================
--- pykota/trunk/bin/cupspykota (revision 2060)
+++ pykota/trunk/bin/cupspykota (revision 2062)
@@ -24,4 +24,8 @@
 #
 # $Log$
+# Revision 1.88  2005/02/14 23:39:50  jalet
+# Introduces the new 'trustjobsize' directive to workaround some printers
+# generating unstable internal page counter values when queried through SNMP.
+#
 # Revision 1.87  2005/02/14 22:53:44  jalet
 # Now always precomputes the job's size with the internal PDL parser, and not
@@ -625,4 +629,16 @@
                 if self.softwareJobSize and (jobsize != self.softwareJobSize) :
                     self.printInfo(_("Beware : computed job size (%s) != precomputed job size (%s)") % (jobsize, self.softwareJobSize), "error")
+                    (limit, replacement) = self.config.getTrustJobSize(printer.Name)
+                    if limit is None :
+                        self.printInfo(_("The job size will be trusted anyway according to the 'trustjobsize' directive"), "warn")
+                    else :
+                        if jobsize <= limit :
+                            self.printInfo(_("The job size will be trusted because it is inferior to the 'trustjobsize' directive's limit %s") % limit, "warn")
+                        else :
+                            self.printInfo(_("The job size will be modified according to the 'trustjobsize' directive : %s") % replacement, "warn")
+                            if replacement == "PRECOMPUTED" :
+                                jobsize = self.softwareJobSize
+                            else :    
+                                jobsize = replacement
                 jobsize += bannersize    
             self.printMoreInfo(user, printer, _("Job size : %i") % jobsize)
Index: pykota/trunk/bin/lprngpykota
===================================================================
--- pykota/trunk/bin/lprngpykota (revision 2060)
+++ pykota/trunk/bin/lprngpykota (revision 2062)
@@ -24,4 +24,8 @@
 #
 # $Log$
+# Revision 1.16  2005/02/14 23:39:50  jalet
+# Introduces the new 'trustjobsize' directive to workaround some printers
+# generating unstable internal page counter values when queried through SNMP.
+#
 # Revision 1.15  2005/02/14 22:53:44  jalet
 # Now always precomputes the job's size with the internal PDL parser, and not
@@ -254,4 +258,16 @@
             if self.softwareJobSize and (jobsize != self.softwareJobSize) :
                 self.printInfo(_("Beware : computed job size (%s) != precomputed job size (%s)") % (jobsize, self.softwareJobSize), "error")
+                (limit, replacement) = self.config.getTrustJobSize(printer.Name)
+                if limit is None :
+                    self.printInfo(_("The job size will be trusted anyway according to the 'trustjobsize' directive"), "warn")
+                else :
+                    if jobsize <= limit :
+                        self.printInfo(_("The job size will be trusted because it is inferior to the 'trustjobsize' directive's limit %s") % limit, "warn")
+                    else :
+                        self.printInfo(_("The job size will be modified according to the 'trustjobsize' directive : %s") % replacement, "warn")
+                        if replacement == "PRECOMPUTED" :
+                            jobsize = self.softwareJobSize
+                        else :    
+                            jobsize = replacement
             
             self.printMoreInfo(user, printer, _("Job size : %i") % jobsize)
Index: pykota/trunk/NEWS
===================================================================
--- pykota/trunk/NEWS (revision 2054)
+++ pykota/trunk/NEWS (revision 2062)
@@ -22,4 +22,13 @@
 PyKota NEWS :
        
+    - 1.21alpha25 :
+    
+        - The job's size is now always precomputed, even when
+          'enforcement' is not set to 'strict'.
+          
+        - Introduction of the new 'trustjobsize' configuration directive
+          to workaround some problematic printers. See the sample
+          configuration file for details.
+          
     - 1.21alpha24 :
     
Index: pykota/trunk/pykota/config.py
===================================================================
--- pykota/trunk/pykota/config.py (revision 2054)
+++ pykota/trunk/pykota/config.py (revision 2062)
@@ -22,4 +22,8 @@
 #
 # $Log$
+# Revision 1.60  2005/02/14 23:39:50  jalet
+# Introduces the new 'trustjobsize' directive to workaround some printers
+# generating unstable internal page counter values when queried through SNMP.
+#
 # Revision 1.59  2005/02/13 22:02:29  jalet
 # Big database structure changes. Upgrade script is now included as well as
@@ -630,2 +634,27 @@
         except PyKotaConfigError :
             return None
+            
+    def getTrustJobSize(self, printername) :
+        """Returns the normalized value of the trustjobsize's directive."""
+        try :
+            value = self.getPrinterOption(printername, "trustjobsize").strip().upper()
+        except PyKotaConfigError :
+            return (None, "YES")
+        else :    
+            if value == "YES" :
+                return (None, "YES")
+            try :    
+                (limit, replacement) = [p.strip() for p in value.split(">")[1].split(":")]
+                limit = int(limit)
+                try :
+                    replacement = int(replacement) 
+                except ValueError :    
+                    if replacement != "PRECOMPUTED" :
+                        raise
+                if limit < 0 :
+                    raise ValueError
+                if (replacement != "PRECOMPUTED") and (replacement < 0) :
+                    raise ValueError
+            except (IndexError, ValueError, TypeError) :
+                raise PyKotaConfigError, _("Option trustjobsize for printer %s is incorrect") % printername
+            return (limit, replacement)    
Index: pykota/trunk/pykota/version.py
===================================================================
--- pykota/trunk/pykota/version.py (revision 2054)
+++ pykota/trunk/pykota/version.py (revision 2062)
@@ -22,5 +22,5 @@
 #
 
-__version__ = "1.21alpha24_unofficial"
+__version__ = "1.21alpha25_unofficial"
 
 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""
