Show
Ignore:
Timestamp:
01/12/04 00:22:42 (20 years ago)
Author:
jalet
Message:

Major code refactoring, it's way cleaner, and now allows automated addition
of printers on first print.

Files:
1 modified

Legend:

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

    r1257 r1271  
    2222# 
    2323# $Log$ 
     24# Revision 1.11  2004/01/11 23:22:42  jalet 
     25# Major code refactoring, it's way cleaner, and now allows automated addition 
     26# of printers on first print. 
     27# 
    2428# Revision 1.10  2004/01/08 14:10:32  jalet 
    2529# Copyright year changed. 
     
    6973        self.filter = kotafilter 
    7074        self.arguments = arguments 
     75        self.isDelayed = 0      # Accounting is immediate by default 
    7176         
    7277    def getLastPageCounter(self) :     
     
    7681        except :     
    7782            return 0 
    78          
    79     def filterInput(self, inputfile) : 
    80         """Transparent filter.""" 
    81         mustclose = 0     
    82         if inputfile is not None :     
    83             if hasattr(inputfile, "read") : 
    84                 infile = inputfile 
    85             else :     
    86                 infile = open(inputfile, "rb") 
    87             mustclose = 1 
    88         else :     
    89             infile = sys.stdin 
    90         data = infile.read(256*1024)     
    91         while data : 
    92             sys.stdout.write(data) 
    93             data = infile.read(256*1024) 
    94         if mustclose :     
    95             infile.close() 
    9683             
    97     def beginJob(self, printer, user) :     
     84    def beginJob(self, userpquota) :     
    9885        """Saves the computed job size.""" 
    9986        # computes job's size 
     
    10188         
    10289        # get last job information for this printer 
    103         if not printer.LastJob.Exists : 
     90        if not userpquota.Printer.LastJob.Exists : 
    10491            # The printer hasn't been used yet, from PyKota's point of view 
    10592            self.LastPageCounter = 0 
     
    10895            # Last lifetime page counter before actual job is  
    10996            # last page counter + last job size 
    110             self.LastPageCounter = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0) 
     97            self.LastPageCounter = int(userpquota.Printer.LastJob.PrinterPageCounter or 0) + int(userpquota.Printer.LastJob.JobSize or 0) 
    11198         
    112     def endJob(self, printer, user) :     
     99    def endJob(self, userpquota) :     
    113100        """Do nothing.""" 
    114101        pass 
     
    121108            return 0 
    122109         
    123     def doAccounting(self, printer, user) : 
    124         """Deletgates the computation of the job size to an external command. 
     110    def doAccounting(self, userpquota) : 
     111        """Delegates the computation of the job size to an external command. 
    125112         
    126113           The command must print the job size on its standard output and exit successfully. 
    127114        """ 
    128         self.beginJob(printer, user) 
     115        self.beginJob(userpquota) 
    129116         
    130117        # get the job size, which is real job size * number of copies. 
     118        # TODO : Double check with CUPS documentation : this is not always correct 
    131119        jobsize = self.getJobSize() * self.filter.copies 
    132120             
    133121        # Is the current user allowed to print at all ? 
    134         userpquota = self.filter.storage.getUserPQuota(user, printer) 
    135122        action = self.filter.warnUserPQuota(userpquota) 
    136123         
     
    142129         
    143130        # adds the current job to history     
    144         jobprice = (float(printer.PricePerPage or 0.0) * jobsize) + float(printer.PricePerJob or 0.0) 
    145         printer.addJobToHistory(self.filter.jobid, user, self.getLastPageCounter(), action, jobsize, jobprice, self.filter.preserveinputfile, self.filter.title, self.filter.copies, self.filter.options) 
    146         self.endJob(printer, user) 
     131        jobprice = (float(userpquota.Printer.PricePerPage or 0.0) * jobsize) + float(userpquota.Printer.PricePerJob or 0.0) 
     132        userpquota.Printer.addJobToHistory(self.filter.jobid, userpquota.User, self.getLastPageCounter(), action, jobsize, jobprice, self.filter.preserveinputfile, self.filter.title, self.filter.copies, self.filter.options) 
     133        self.endJob(userpquota) 
    147134        return action 
    148135