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/accounters/stupid.py

    r1203 r1239  
    2222# 
    2323# $Log$ 
     24# Revision 1.9  2003/12/27 15:43:36  uid67467 
     25# Savannah is back online... 
     26# 
    2427# Revision 1.8  2003/11/23 19:01:37  jalet 
    2528# Job price added to history 
     
    5558 
    5659class Accounter(AccounterBase) : 
    57     def beginJob(self) :     
    58         """Saves the computed job size.""" 
    59         self.JobSize = self.computeJobSize() 
    60          
    61         # get last job information for this printer 
    62         if not printer.LastJob.Exists : 
    63             # The printer hasn't been used yet, from PyKota's point of view 
    64             self.LastPageCounter = 0 
    65         else :     
    66             # get last job size and page counter from Quota Storage 
    67             # Last lifetime page counter before actual job is  
    68             # last page counter + last job size 
    69             self.LastPageCounter = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0) 
    70          
    71     def endJob(self) :     
    72         """Do nothing.""" 
    73         pass 
    74          
    75     def getJobSize(self) :     
    76         """Returns the actual job size.""" 
    77         try : 
    78             return self.JobSize 
    79         except AttributeError :     
    80             return 0 
    81          
    82     def doAccounting(self, printer, user) : 
    83         """Does print accounting by stupidly counting the 'showpage' postscript instructions in the document. 
    84          
    85            This method is essentially unreliable, but shows how to create a simple accounter. 
    86         """ 
    87         # first we log a message because using this accounting method is not recommended. 
    88         self.filter.logger.log_message(_("Using the 'stupid' accounting method is unreliable."), "warn") 
    89          
    90         # get the job size     
    91         jobsize = self.computeJobSize() * self.filter.copies 
    92              
    93         # get last job information for this printer 
    94         if not printer.LastJob.Exists : 
    95             # The printer hasn't been used yet, from PyKota's point of view 
    96             counterbeforejob = 0 
    97         else :     
    98             # get last job size and page counter from Quota Storage 
    99             # Last lifetime page counter before actual job is  
    100             # last page counter + last job size 
    101             counterbeforejob = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0) 
    102              
    103         # Is the current user allowed to print at all ? 
    104         userpquota = self.filter.storage.getUserPQuota(user, printer) 
    105         action = self.filter.warnUserPQuota(userpquota) 
    106          
    107         # update the quota for the current user on this printer, if allowed to print 
    108         if action == "DENY" : 
    109             jobsize = 0 
    110         else :     
    111             userpquota.increasePagesUsage(jobsize) 
    112          
    113         # adds the current job to history     
    114         jobprice = (float(printer.PricePerPage or 0.0) * jobsize) + float(printer.PricePerJob or 0.0) 
    115         printer.addJobToHistory(self.filter.jobid, user, counterbeforejob, action, jobsize, jobprice, self.filter.preserveinputfile, self.filter.title, self.filter.copies, self.filter.options) 
    116              
    117         return action 
    118          
    11960    def computeJobSize(self) :     
    12061        """Computes the job size and return its value. 
     
    12263           THIS METHOD IS COMPLETELY UNRELIABLE BUT SERVES AS AN EXAMPLE. 
    12364        """ 
     65        # first we log a message because using this accounting method is not recommended. 
     66        self.filter.logger.log_message(_("Using the 'stupid' accounting method is unreliable."), "warn") 
     67         
    12468        temporary = None     
    12569        if self.filter.inputfile is None :     
     
    14690        else : 
    14791            infile.close() 
    148              
    14992        return pagecount     
    150