Changeset 1713

Show
Ignore:
Timestamp:
09/13/04 18:02:45 (20 years ago)
Author:
jalet
Message:

Added fix for incorrect job's size when hardware accounting fails

Location:
pykota/trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r1704 r1713  
    2424# 
    2525# $Log$ 
     26# Revision 1.72  2004/09/13 16:02:44  jalet 
     27# Added fix for incorrect job's size when hardware accounting fails 
     28# 
    2629# Revision 1.71  2004/09/06 17:05:06  jalet 
    2730# Fix for autodetection of SC_OPEN_MAX 
     
    439442                self.printInfo(_("Job size forced to 0 because printing is denied.")) 
    440443            else :     
    441                 jobsize = self.accounter.getJobSize() 
     444                jobsize = self.accounter.getJobSize(printer) 
    442445            self.printInfo(_("Job size : %i") % jobsize) 
    443446             
  • pykota/trunk/bin/lprngpykota

    r1696 r1713  
    2424# 
    2525# $Log$ 
     26# Revision 1.7  2004/09/13 16:02:44  jalet 
     27# Added fix for incorrect job's size when hardware accounting fails 
     28# 
    2629# Revision 1.6  2004/09/02 14:40:13  jalet 
    2730# Another bunch of LPRng fixes 
     
    141144        if self.accounter.isSoftware : 
    142145            self.accounter.endJob(printer) 
    143             jobsize = self.accounter.getJobSize() 
     146            jobsize = self.accounter.getJobSize(printer) 
    144147            self.logdebug("Job accounting ends.") 
    145148             
     
    216219                 
    217220            # retrieve the job size     
    218             jobsize = self.accounter.getJobSize() 
     221            jobsize = self.accounter.getJobSize(printer) 
    219222             
    220223            self.logdebug("Job size : %i" % jobsize) 
  • pykota/trunk/NEWS

    r1705 r1713  
    2222PyKota NEWS : 
    2323 
     24    - 1.20alpha10 : 
     25     
     26        - Added fix for incorrect job's size computation when 
     27          hardware accounting fails. 
     28           
    2429    - 1.20alpha9 : 
    2530     
  • pykota/trunk/pykota/accounter.py

    r1687 r1713  
    2222# 
    2323# $Log$ 
     24# Revision 1.20  2004/09/13 16:02:45  jalet 
     25# Added fix for incorrect job's size when hardware accounting fails 
     26# 
    2427# Revision 1.19  2004/08/31 23:29:53  jalet 
    2528# Introduction of the new 'onaccountererror' configuration directive. 
     
    140143        pass 
    141144         
    142     def getJobSize(self) :     
     145    def getJobSize(self, printer) :     
    143146        """Returns the actual job size.""" 
    144147        try : 
  • pykota/trunk/pykota/accounters/hardware.py

    r1703 r1713  
    2222# 
    2323# $Log$ 
     24# Revision 1.13  2004/09/13 16:02:45  jalet 
     25# Added fix for incorrect job's size when hardware accounting fails 
     26# 
    2427# Revision 1.12  2004/09/06 15:42:34  jalet 
    2528# Fix missing import statement for the signal module 
     
    105108        self.LastPageCounter = self.counterafter = self.getPrinterInternalPageCounter() 
    106109         
    107     def getJobSize(self) :     
     110    def getJobSize(self, printer) :     
    108111        """Returns the actual job size.""" 
    109         try : 
    110             jobsize = (self.counterafter - self.counterbefore)     
    111             if jobsize < 0 : 
    112                 # Try to take care of HP printers  
    113                 # Their internal page counter is saved to NVRAM 
    114                 # only every 10 pages. If the printer was switched 
    115                 # off then back on during the job, and that the 
    116                 # counters difference is negative, we know  
    117                 # the formula (we can't know if more than eleven 
    118                 # pages were printed though) : 
    119                 if jobsize > -10 : 
    120                     jobsize += 10 
    121                 else :     
    122                     # here we may have got a printer being replaced 
    123                     # DURING the job. This is HIGHLY improbable ! 
    124                     jobsize = 0 
    125         except :     
    126             # takes care of the case where one counter (or both) was never set. 
    127             jobsize = 0 
     112        if (not self.counterbefore) or (not self.counterafter) : 
     113            # there was a problem retrieving page counter 
     114            self.filter.printInfo(_("A problem occured while reading printer %s's internal page counter.") % printer.Name, "warn") 
     115            if printer.LastJob.Exists : 
     116                # if there's a previous job, use the last value from database 
     117                self.filter.printInfo(_("Retrieving printer %s's page counter from database instead.") % printer.Name, "warn") 
     118                if not self.counterbefore :  
     119                    self.counterbefore = printer.LastJob.PrinterPageCounter or 0 
     120                if not self.counterafter : 
     121                    self.counterafter = printer.LastJob.PrinterPageCounter or 0 
     122                before = min(self.counterbefore, self.counterafter)     
     123                after = max(self.counterbefore, self.counterafter)     
     124                self.counterbefore = before 
     125                self.counterafter = after 
     126                if self.counterbefore == self.counterafter : 
     127                    self.filter.printInfo(_("Couldn't retrieve printer %s's internal page counter either before or after printing.") % printer.Name, "warn") 
     128                    self.filter.printInfo(_("Job's size forced to 1 page for printer %s.") % printer.Name, "warn") 
     129                    self.counterafter = self.counterbefore + 1 
     130            else : 
     131                self.filter.printInfo(_("No previous job in database for printer %s.") % printer.Name, "warn") 
     132                self.filter.printInfo(_("Job's size forced to 1 page for printer %s.") % printer.Name, "warn") 
     133                self.counterbefore = 0 
     134                self.counterafter = 1 
     135                 
     136        jobsize = (self.counterafter - self.counterbefore)     
     137        if jobsize < 0 : 
     138            # Try to take care of HP printers  
     139            # Their internal page counter is saved to NVRAM 
     140            # only every 10 pages. If the printer was switched 
     141            # off then back on during the job, and that the 
     142            # counters difference is negative, we know  
     143            # the formula (we can't know if more than eleven 
     144            # pages were printed though) : 
     145            if jobsize > -10 : 
     146                jobsize += 10 
     147            else :     
     148                # here we may have got a printer being replaced 
     149                # DURING the job. This is HIGHLY improbable ! 
     150                self.filter.printInfo(_("Inconsistent values for printer %s's internal page counter.") % printer.Name, "warn") 
     151                self.filter.printInfo(_("Job's size forced to 1 page for printer %s.") % printer.Name, "warn") 
     152                jobsize = 1 
    128153        return jobsize 
    129154         
  • pykota/trunk/pykota/version.py

    r1705 r1713  
    2222# 
    2323 
    24 __version__ = "1.20alpha9_unofficial" 
     24__version__ = "1.20alpha10_unofficial" 
    2525 
    2626__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""