Show
Ignore:
Timestamp:
11/13/03 00:29:24 (21 years ago)
Author:
jalet
Message:

More work on new backend. This commit may be unstable.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/accounters/external.py

    r1144 r1180  
    2222# 
    2323# $Log$ 
     24# Revision 1.8  2003/11/12 23:29:24  jalet 
     25# More work on new backend. This commit may be unstable. 
     26# 
    2427# Revision 1.7  2003/10/07 09:07:28  jalet 
    2528# Character encoding added to please latest version of Python 
     
    5457 
    5558class Accounter(AccounterBase) : 
     59    def beginJob(self, printer, user) :     
     60        """Saves the computed job size.""" 
     61        # computes job's size 
     62        self.JobSize = self.computeJobSize() 
     63         
     64        # get last job information for this printer 
     65        if not printer.LastJob.Exists : 
     66            # The printer hasn't been used yet, from PyKota's point of view 
     67            self.LastPageCounter = 0 
     68        else :     
     69            # get last job size and page counter from Quota Storage 
     70            # Last lifetime page counter before actual job is  
     71            # last page counter + last job size 
     72            self.LastPageCounter = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0) 
     73         
     74    def endJob(self, printer, user) :     
     75        """Do nothing.""" 
     76        pass 
     77         
     78    def getJobSize(self) :     
     79        """Returns the actual job size.""" 
     80        try : 
     81            return self.JobSize 
     82        except AttributeError :     
     83            return 0 
     84         
    5685    def doAccounting(self, printer, user) : 
    5786        """Deletgates the computation of the job size to an external command. 
     
    5988           The command must print the job size on its standard output and exit successfully. 
    6089        """ 
     90        self.beginJob(printer, user) 
     91         
    6192        # get the job size, which is real job size * number of copies. 
    6293        jobsize = self.getJobSize() * self.filter.copies 
    63              
    64         # get last job information for this printer 
    65         if not printer.LastJob.Exists : 
    66             # The printer hasn't been used yet, from PyKota's point of view 
    67             counterbeforejob = 0 
    68         else :     
    69             # get last job size and page counter from Quota Storage 
    70             # Last lifetime page counter before actual job is  
    71             # last page counter + last job size 
    72             counterbeforejob = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0) 
    7394             
    7495        # Is the current user allowed to print at all ? 
     
    83104         
    84105        # adds the current job to history     
    85         printer.addJobToHistory(self.filter.jobid, user, counterbeforejob, action, jobsize) 
     106        printer.addJobToHistory(self.filter.jobid, user, self.getLastPageCounter(), action, jobsize) 
     107         
     108        self.endJob(printer, user) 
    86109             
    87110        return action 
    88111         
    89     def getJobSize(self) :     
     112    def computeJobSize(self) :     
    90113        """Feeds an external command with our datas to let it compute the job size, and return its value.""" 
    91114        temporary = None