Show
Ignore:
Timestamp:
12/27/03 16:43:36 (20 years ago)
Author:
uid67467
Message:

Savannah is back online...

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/accounter.py

    r1219 r1239  
    2222# 
    2323# $Log$ 
     24# Revision 1.8  2003/12/27 15:43:36  uid67467 
     25# Savannah is back online... 
     26# 
    2427# Revision 1.7  2003/11/25 23:46:40  jalet 
    2528# Don't try to verify if module name is valid, Python does this better than us. 
     
    8992            infile.close() 
    9093             
    91     def doAccounting(self, printer, user) :     
    92         """Does the real accounting.""" 
    93         raise PyKotaAccounterError, "Accounter not implemented !" 
     94    def beginJob(self, printer, user) :     
     95        """Saves the computed job size.""" 
     96        # computes job's size 
     97        self.JobSize = self.computeJobSize() 
     98         
     99        # get last job information for this printer 
     100        if not printer.LastJob.Exists : 
     101            # The printer hasn't been used yet, from PyKota's point of view 
     102            self.LastPageCounter = 0 
     103        else :     
     104            # get last job size and page counter from Quota Storage 
     105            # Last lifetime page counter before actual job is  
     106            # last page counter + last job size 
     107            self.LastPageCounter = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0) 
     108         
     109    def endJob(self, printer, user) :     
     110        """Do nothing.""" 
     111        pass 
     112         
     113    def getJobSize(self) :     
     114        """Returns the actual job size.""" 
     115        try : 
     116            return self.JobSize 
     117        except AttributeError :     
     118            return 0 
     119         
     120    def doAccounting(self, printer, user) : 
     121        """Deletgates the computation of the job size to an external command. 
     122         
     123           The command must print the job size on its standard output and exit successfully. 
     124        """ 
     125        self.beginJob(printer, user) 
     126         
     127        # get the job size, which is real job size * number of copies. 
     128        jobsize = self.getJobSize() * self.filter.copies 
     129             
     130        # Is the current user allowed to print at all ? 
     131        userpquota = self.filter.storage.getUserPQuota(user, printer) 
     132        action = self.filter.warnUserPQuota(userpquota) 
     133         
     134        # update the quota for the current user on this printer, if allowed to print 
     135        if action == "DENY" : 
     136            jobsize = 0 
     137        else :     
     138            userpquota.increasePagesUsage(jobsize) 
     139         
     140        # adds the current job to history     
     141        jobprice = (float(printer.PricePerPage or 0.0) * jobsize) + float(printer.PricePerJob or 0.0) 
     142        printer.addJobToHistory(self.filter.jobid, user, self.getLastPageCounter(), action, jobsize, jobprice, self.filter.preserveinputfile, self.filter.title, self.filter.copies, self.filter.options) 
     143        self.endJob(printer, user) 
     144        return action 
    94145         
    95146def openAccounter(kotafilter) :