Changeset 1239 for pykota/trunk/pykota/accounters
- Timestamp:
- 12/27/03 16:43:36 (20 years ago)
- Location:
- pykota/trunk/pykota/accounters
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/accounters/external.py
r1203 r1239 22 22 # 23 23 # $Log$ 24 # Revision 1.11 2003/12/27 15:43:36 uid67467 25 # Savannah is back online... 26 # 24 27 # Revision 1.10 2003/11/23 19:01:36 jalet 25 28 # Job price added to history … … 63 66 64 67 class Accounter(AccounterBase) : 65 def beginJob(self, printer, user) :66 """Saves the computed job size."""67 # computes job's size68 self.JobSize = self.computeJobSize()69 70 # get last job information for this printer71 if not printer.LastJob.Exists :72 # The printer hasn't been used yet, from PyKota's point of view73 self.LastPageCounter = 074 else :75 # get last job size and page counter from Quota Storage76 # Last lifetime page counter before actual job is77 # last page counter + last job size78 self.LastPageCounter = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0)79 80 def endJob(self, printer, user) :81 """Do nothing."""82 pass83 84 def getJobSize(self) :85 """Returns the actual job size."""86 try :87 return self.JobSize88 except AttributeError :89 return 090 91 def doAccounting(self, printer, user) :92 """Deletgates the computation of the job size to an external command.93 94 The command must print the job size on its standard output and exit successfully.95 """96 self.beginJob(printer, user)97 98 # get the job size, which is real job size * number of copies.99 jobsize = self.getJobSize() * self.filter.copies100 101 # Is the current user allowed to print at all ?102 userpquota = self.filter.storage.getUserPQuota(user, printer)103 action = self.filter.warnUserPQuota(userpquota)104 105 # update the quota for the current user on this printer, if allowed to print106 if action == "DENY" :107 jobsize = 0108 else :109 userpquota.increasePagesUsage(jobsize)110 111 # adds the current job to history112 jobprice = (float(printer.PricePerPage or 0.0) * jobsize) + float(printer.PricePerJob or 0.0)113 printer.addJobToHistory(self.filter.jobid, user, self.getLastPageCounter(), action, jobsize, jobprice, self.filter.preserveinputfile, self.filter.title, self.filter.copies, self.filter.options)114 115 self.endJob(printer, user)116 117 return action118 119 68 def computeJobSize(self) : 120 69 """Feeds an external command with our datas to let it compute the job size, and return its value.""" … … 181 130 else : 182 131 infile.close() 183 184 132 return pagecount 185 133 -
pykota/trunk/pykota/accounters/querying.py
r1200 r1239 22 22 # 23 23 # $Log$ 24 # Revision 1.9 2003/12/27 15:43:36 uid67467 25 # Savannah is back online... 26 # 24 27 # Revision 1.8 2003/11/21 14:28:46 jalet 25 28 # More complete job history. … … 182 185 # adds the current job to history 183 186 printer.addJobToHistory(self.filter.jobid, user, counterbeforejob, action, filename=self.filter.preserveinputfile, title=self.filter.title, copies=self.filter.copies, options=self.filter.options) 184 185 187 return action 186 188 -
pykota/trunk/pykota/accounters/stupid.py
r1203 r1239 22 22 # 23 23 # $Log$ 24 # Revision 1.9 2003/12/27 15:43:36 uid67467 25 # Savannah is back online... 26 # 24 27 # Revision 1.8 2003/11/23 19:01:37 jalet 25 28 # Job price added to history … … 55 58 56 59 class 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 printer62 if not printer.LastJob.Exists :63 # The printer hasn't been used yet, from PyKota's point of view64 self.LastPageCounter = 065 else :66 # get last job size and page counter from Quota Storage67 # Last lifetime page counter before actual job is68 # last page counter + last job size69 self.LastPageCounter = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0)70 71 def endJob(self) :72 """Do nothing."""73 pass74 75 def getJobSize(self) :76 """Returns the actual job size."""77 try :78 return self.JobSize79 except AttributeError :80 return 081 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 size91 jobsize = self.computeJobSize() * self.filter.copies92 93 # get last job information for this printer94 if not printer.LastJob.Exists :95 # The printer hasn't been used yet, from PyKota's point of view96 counterbeforejob = 097 else :98 # get last job size and page counter from Quota Storage99 # Last lifetime page counter before actual job is100 # last page counter + last job size101 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 print108 if action == "DENY" :109 jobsize = 0110 else :111 userpquota.increasePagesUsage(jobsize)112 113 # adds the current job to history114 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 action118 119 60 def computeJobSize(self) : 120 61 """Computes the job size and return its value. … … 122 63 THIS METHOD IS COMPLETELY UNRELIABLE BUT SERVES AS AN EXAMPLE. 123 64 """ 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 124 68 temporary = None 125 69 if self.filter.inputfile is None : … … 146 90 else : 147 91 infile.close() 148 149 92 return pagecount 150