Changeset 2388
- Timestamp:
- 07/27/05 15:17:28 (19 years ago)
- Location:
- pykota/trunk
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r2314 r2388 220 220 (chtype, clienthost) = ippmessage.operation_attributes.get("job-originating-host-name", \ 221 221 ippmessage.job_attributes.get("job-originating-host-name", (None, None))) 222 (jbtype, b illingcode) = ippmessage.job_attributes.get("job-billing", (None, None))222 (jbtype, bcode) = ippmessage.job_attributes.get("job-billing", (None, None)) 223 223 except AttributeError : 224 224 clienthost = None 225 b illingcode = None225 bcode = None 226 226 if clienthost is None : 227 (b illingcode, clienthost) = self.getJobInfosFromPageLog(cupsdconf, printer.Name, user.Name, self.jobid)227 (bcode, clienthost) = self.getJobInfosFromPageLog(cupsdconf, printer.Name, user.Name, self.jobid) 228 228 self.logdebug("Client Hostname : %s" % (clienthost or "Unknown")) 229 self.logdebug("Billing Code : %s" % (b illingcode or "None"))229 self.logdebug("Billing Code : %s" % (bcode or "None")) 230 230 231 231 os.environ["PYKOTAJOBORIGINATINGHOSTNAME"] = str(clienthost or "") 232 os.environ["PYKOTAJOBBILLING"] = str(b illingcode or "")232 os.environ["PYKOTAJOBBILLING"] = str(bcode or "") 233 233 234 234 # enters first phase … … 269 269 else : 270 270 self.printMoreInfo(user, printer, _("Job is a duplicate. Printing is allowed by subprocess."), "warn") 271 action = "ALLOW" # just to be sure, in the case the external command returns something else...271 action = self.warnUserPQuota(userpquota) 272 272 else : 273 273 # checks the user's quota 274 274 action = self.warnUserPQuota(userpquota) 275 276 # Now handle the billing code 277 if bcode is not None : 278 billingcode = self.storage.getBillingCode(bcode) 279 if billingcode.Exists : 280 self.logdebug("Billing code [%s] exists in database." % bcode) 281 else : 282 msg = "Unknown billing code [%s] : " % bcode 283 (newaction, script) = self.config.getUnknownBillingCode(printer.Name) 284 if newaction == "CREATE" : 285 self.logdebug(msg + "will be created.") 286 billingcode = self.storage.addBillingCode(bcode) 287 if billingcode.Exists : 288 self.logdebug(msg + "has been created.") 289 else : 290 self.printInfo(msg + "couldn't be created.", "error") 291 else : 292 self.logdebug(msg + "job will be denied.") 293 action = newaction 294 if script is not None : 295 self.logdebug(msg + "launching subprocess [%s] to notify user." % script) 296 os.system(script) 297 else : 298 billingcode = None 275 299 276 300 # exports some new environment variables … … 386 410 action, jobsize, jobprice, self.preserveinputfile, \ 387 411 self.title, self.copies, self.options, clienthost, \ 388 self.jobSizeBytes, self.checksum, None, b illingcode)412 self.jobSizeBytes, self.checksum, None, bcode) 389 413 self.printMoreInfo(user, printer, _("Job added to history.")) 390 414 415 if billingcode and billingcode.Exists : 416 billingcode.consume(jobsize, jobprice) 417 self.printMoreInfo(user, printer, _("Billing code %s was updated.") % billingcode.BillingCode) 418 391 419 # exports some new environment variables 392 420 os.environ["PYKOTAJOBSIZE"] = str(jobsize) -
pykota/trunk/pykota/storage.py
r2342 r2388 304 304 upq.PageCounter = int(upq.PageCounter or 0) + jobsize 305 305 upq.LifePageCounter = int(upq.LifePageCounter or 0) + jobsize 306 # TODO : consume from the billing code as well307 306 except PyKotaStorageError, msg : 308 307 self.parent.rollbackTransaction() … … 433 432 def reset(self, balance=0.0, pagecounter=0) : 434 433 """Resets the pagecounter and balance for this billing code.""" 435 self.parent.setBillingCodeValues(self, balance, pagecounter)434 self.parent.setBillingCodeValues(self, pagecounter, balance) 436 435 self.Balance = balance 437 436 self.PageCounter = pagecounter -
pykota/trunk/pykota/storages/ldapstorage.py
r2386 r2388 1420 1420 """Returns the list of all billing codes which match a certain pattern.""" 1421 1421 codes = [] 1422 result = self.doSearch("(&(objectClass=pykotaBilling) %s)" % "".join(["(pykotaBillingCode=%s)" % self.userCharsetToDatabase(bcode) for bcode in billingcodepattern.split(",")]), \1422 result = self.doSearch("(&(objectClass=pykotaBilling)(|%s))" % "".join(["(pykotaBillingCode=%s)" % self.userCharsetToDatabase(bcode) for bcode in billingcodepattern.split(",")]), \ 1423 1423 ["pykotaBillingCode", "description", "pykotaPageCounter", "pykotaBalance"], \ 1424 1424 base=self.info["billingcodebase"]) … … 1437 1437 return codes 1438 1438 1439 def setBillingCodeValues(self, code, new balance, newpagecounter) :1439 def setBillingCodeValues(self, code, newpagecounter, newbalance) : 1440 1440 """Sets the new page counter and balance for a billing code.""" 1441 1441 fields = { … … 1445 1445 return self.doModify(code.ident, fields) 1446 1446 1447 def consumeBillingCode(self, code, balance, pagecounter) :1447 def consumeBillingCode(self, code, pagecounter, balance) : 1448 1448 """Consumes from a billing code.""" 1449 1449 fields = { -
pykota/trunk/pykota/storages/sql.py
r2374 r2388 495 495 self.doModify("UPDATE billingcodes SET description=%s WHERE id=%s" % (self.doQuote(self.userCharsetToDatabase(code.Description or "")), self.doQuote(code.ident))) 496 496 497 def setBillingCodeValues(self, code, new balance, newpagecounter) :497 def setBillingCodeValues(self, code, newpagecounter, newbalance) : 498 498 """Sets the new page counter and balance for a billing code.""" 499 499 self.doModify("UPDATE billingcodes SET balance=%s, pagecounter=%s WHERE id=%s" % (self.doQuote(newbalance), self.doQuote(newpagecounter), self.doQuote(code.ident))) 500 500 501 def consumeBillingCode(self, code, balance, pagecounter) :501 def consumeBillingCode(self, code, pagecounter, balance) : 502 502 """Consumes from a billing code.""" 503 503 self.doModify("UPDATE billingcodes SET balance=balance + %s, pagecounter=pagecounter + %s WHERE id=%s" % (self.doQuote(balance), self.doQuote(pagecounter), self.doQuote(code.ident)))