Changeset 1624 for pykota/trunk
- Timestamp:
- 07/23/04 00:41:48 (20 years ago)
- Location:
- pykota/trunk
- Files:
-
- 5 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r1606 r1624 24 24 # 25 25 # $Log$ 26 # Revision 1.69 2004/07/22 22:41:47 jalet 27 # Hardware accounting for LPRng should be OK now. UNTESTED. 28 # 26 29 # Revision 1.68 2004/07/20 22:19:44 jalet 27 30 # Sanitized a bit + use of gettext … … 400 403 401 404 self.printInfo(_("Job accounting begins.")) 402 self.accounter.beginJob( userpquota)405 self.accounter.beginJob(printer) 403 406 else : 404 407 action = "ALLOW" … … 419 422 420 423 # stops accounting. 421 self.accounter.endJob( userpquota)424 self.accounter.endJob(printer) 422 425 self.printInfo(_("Job accounting ends.")) 423 426 -
pykota/trunk/bin/lprngpykota
r1611 r1624 24 24 # 25 25 # $Log$ 26 # Revision 1.4 2004/07/22 22:41:48 jalet 27 # Hardware accounting for LPRng should be OK now. UNTESTED. 28 # 26 29 # Revision 1.3 2004/07/21 09:35:48 jalet 27 30 # Software accounting seems to be OK with LPRng support now … … 84 87 # and that the second pass didn't work or wasn't even launched 85 88 # we know have to act just as if we were in second pass 86 raise PyKotaToolError, "Not implemented yet !" 89 # for previous user on this printer, then we will continue 90 # with normal processing of current user. 91 self.secondPass(policy, printer, None, None) 92 93 # export user info with initial values 94 self.exportUserInfo(userpquota) 87 95 88 96 # tries to extract job-originating-hostname … … 119 127 120 128 self.logdebug("Job accounting begins.") 121 self.accounter.beginJob( userpquota)129 self.accounter.beginJob(printer) 122 130 123 131 jobsize = None 124 132 if self.accounter.isSoftware : 125 self.accounter.endJob( userpquota)133 self.accounter.endJob(printer) 126 134 jobsize = self.accounter.getJobSize() 127 135 self.logdebug("Job accounting ends.") … … 131 139 self.logdebug("Job size forced to 0 because printing was denied.") 132 140 133 if jobsize is not None :141 if self.accounter.isSoftware : 134 142 # update the quota for the current user on this printer 135 143 self.logdebug("Job size : %i" % jobsize) … … 180 188 raise PyKotaToolError, _("Hardware accounting already finished ! This should be impossible, please report this problem ASAP.") 181 189 190 # here if user and userpquota are both None 191 # then it's a special second pass for a job 192 # which should have had one but didn't, so 193 # we need to get the last user, not the current one. 194 if (user is None) and (userpquota is None) : 195 user = printer.LastJob.User 196 userpquota = self.storage.getUserPQuota(user, printer) 197 198 # exports user info for last user 199 self.exportUserInfo(userpquota) 200 182 201 # indicate phase change 183 202 os.environ["PYKOTAPHASE"] = "AFTER" 184 203 204 # fakes beginning of job with old page counter 205 self.accounter.LastPageCounter = int(printer.LastJob.PrinterPageCounter or 0) 206 self.accounter.fakeBeginJob() 207 self.logdebug("Fakes beginning of job with LastPageCounter: %s" % self.accounter.getLastPageCounter()) 208 185 209 # stops accounting. 186 self.accounter.endJob( userpquota)210 self.accounter.endJob(printer) 187 211 self.logdebug("Job accounting ends.") 188 212 189 213 # retrieve the job size 190 214 jobsize = self.accounter.getJobSize() 215 191 216 self.logdebug("Job size : %i" % jobsize) 192 raise PyKotaToolError, "Not implemented !" 217 self.logdebug("Updating user %s's quota on printer %s" % (user.Name, printer.Name)) 218 jobprice = userpquota.increasePagesUsage(jobsize) 219 220 self.storage.writeLastJobSize(printer.LastJob, jobsize, jobprice) 221 self.logdebug("Job size and price now set in history.") 222 223 # exports some new environment variables 224 os.environ["PYKOTAPHASE"] = "AFTER" 225 os.environ["PYKOTAJOBSIZE"] = str(jobsize) 226 os.environ["PYKOTAJOBPRICE"] = str(jobprice) 227 228 # then re-export user information with new value 229 self.exportUserInfo(userpquota) 230 231 # Launches the post hook 232 self.posthook(userpquota) 233 234 # here hardware accounting was completed. 193 235 return self.acceptJob() 194 236 … … 204 246 return self.acceptJob() 205 247 else : 206 # exports user information with initial values207 self.exportUserInfo(userpquota)208 209 248 if (not printer.LastJob.Exists) or (printer.LastJob.JobId != self.jobid) : 210 249 # Last job for current printer has a different JobId than -
pykota/trunk/pykota/accounter.py
r1600 r1624 22 22 # 23 23 # $Log$ 24 # Revision 1.18 2004/07/22 22:41:48 jalet 25 # Hardware accounting for LPRng should be OK now. UNTESTED. 26 # 24 27 # Revision 1.17 2004/07/16 12:22:47 jalet 25 28 # LPRng support early version … … 103 106 return 0 104 107 105 def beginJob(self, userpquota) :108 def beginJob(self, printer) : 106 109 """Saves the computed job size.""" 107 110 # computes job's size … … 113 116 114 117 # get last job information for this printer 115 if not userpquota.Printer.LastJob.Exists :118 if not printer.LastJob.Exists : 116 119 # The printer hasn't been used yet, from PyKota's point of view 117 120 self.LastPageCounter = 0 … … 120 123 # Last lifetime page counter before actual job is 121 124 # last page counter + last job size 122 self.LastPageCounter = int( userpquota.Printer.LastJob.PrinterPageCounter or 0) + int(userpquota.Printer.LastJob.JobSize or 0)125 self.LastPageCounter = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0) 123 126 124 def endJob(self, userpquota) : 127 def fakeBeginJob(self) : 128 """Do nothing.""" 129 pass 130 131 def endJob(self, printer) : 125 132 """Do nothing.""" 126 133 pass -
pykota/trunk/pykota/accounters/hardware.py
r1600 r1624 22 22 # 23 23 # $Log$ 24 # Revision 1.8 2004/07/22 22:41:48 jalet 25 # Hardware accounting for LPRng should be OK now. UNTESTED. 26 # 24 27 # Revision 1.7 2004/07/16 12:22:47 jalet 25 28 # LPRng support early version … … 72 75 return counter 73 76 74 def beginJob(self, userpquota) :77 def beginJob(self, printer) : 75 78 """Saves printer internal page counter at start of job.""" 76 79 # save page counter before job 77 self.LastPageCounter = self.counterbefore = self.getPrinterInternalPageCounter() 80 self.LastPageCounter = self.getPrinterInternalPageCounter() 81 self.fakeBeginJob() 78 82 79 def endJob(self, userpquota) : 83 def fakeBeginJob(self) : 84 """Fakes a begining of a job.""" 85 self.counterbefore = self.getLastPageCounter() 86 87 def endJob(self, printer) : 80 88 """Saves printer internal page counter at end of job.""" 81 89 # save page counter after job -
pykota/trunk/pykota/storage.py
r1582 r1624 22 22 # 23 23 # $Log$ 24 # Revision 1.57 2004/07/22 22:41:48 jalet 25 # Hardware accounting for LPRng should be OK now. UNTESTED. 26 # 24 27 # Revision 1.56 2004/07/01 17:45:49 jalet 25 28 # Added code to handle the description field for printers … … 513 516 self.Printer = printer 514 517 515 def __getattr__(self, name) :516 """Delays data retrieval until it's really needed."""517 if name == "User" :518 self.User = self.parent.getUser(self.UserName)519 return self.User520 else :521 raise AttributeError, name522 523 def setSize(self, userpquota, jobsize) :524 """Sets the last job's size."""525 jobprice = userpquota.computeJobPrice(jobsize)526 self.parent.writeLastJobSize(self, jobsize, jobprice)527 self.JobSize = jobsize528 self.JobPrice = jobprice529 return jobprice530 531 518 class BaseStorage : 532 519 def __init__(self, pykotatool) :