Changeset 2342 for pykota/trunk/pykota
- Timestamp:
- 07/06/05 20:11:00 (19 years ago)
- Location:
- pykota/trunk/pykota
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/dumper.py
r2302 r2342 52 52 "pmembers" : N_("Printers Groups Membership"), 53 53 "umembers" : N_("Users Groups Membership"), 54 "billingcodes" : N_("Billing Codes"), 54 55 } 55 56 validformats = { "csv" : N_("Comma Separated Values"), -
pykota/trunk/pykota/storage.py
r2340 r2342 431 431 self.Exists = 0 432 432 433 def reset(self, pagecounter=0, balance=0.0) :433 def reset(self, balance=0.0, pagecounter=0) : 434 434 """Resets the pagecounter and balance for this billing code.""" 435 self.parent.setBillingCodeValues(self, pagecounter, balance) 435 self.parent.setBillingCodeValues(self, balance, pagecounter) 436 self.Balance = balance 436 437 self.PageCounter = pagecounter 437 self.Balance = balance438 438 439 439 def setDescription(self, description=None) : … … 464 464 if self.usecache : 465 465 self.tool.logdebug("Caching enabled.") 466 self.caches = { "USERS" : {}, "GROUPS" : {}, "PRINTERS" : {}, "USERPQUOTAS" : {}, "GROUPPQUOTAS" : {}, "JOBS" : {}, "LASTJOBS" : {} }466 self.caches = { "USERS" : {}, "GROUPS" : {}, "PRINTERS" : {}, "USERPQUOTAS" : {}, "GROUPPQUOTAS" : {}, "JOBS" : {}, "LASTJOBS" : {}, "BILLINGCODES" : {} } 467 467 468 468 def close(self) : … … 539 539 self.cacheEntry("LASTJOBS", printer.Name, lastjob) 540 540 return lastjob 541 542 def getBillingCode(self, label) : 543 """Returns the user from cache.""" 544 code = self.getFromCache("BILLINGCODES", label) 545 if code is None : 546 code = self.getBillingCodeFromBackend(label) 547 self.cacheEntry("BILLINGCODES", label, code) 548 return code 541 549 542 550 def getParentPrinters(self, printer) : -
pykota/trunk/pykota/storages/sql.py
r2320 r2342 24 24 25 25 from types import StringType 26 from pykota.storage import PyKotaStorageError,BaseStorage,StorageObject,StorageUser,StorageGroup,StoragePrinter,StorageJob,StorageLastJob,StorageUserPQuota,StorageGroupPQuota 26 from pykota.storage import PyKotaStorageError, BaseStorage, StorageObject, \ 27 StorageUser, StorageGroup, StoragePrinter, \ 28 StorageJob, StorageLastJob, StorageUserPQuota, \ 29 StorageGroupPQuota, StorageBillingCode 27 30 28 31 class SQLStorage : … … 67 70 return self.prepareRawResult(result) 68 71 72 def extractBillingcodes(self, extractonly={}) : 73 """Extracts all billing codes records.""" 74 thefilter = self.createFilter(extractonly) 75 if thefilter : 76 thefilter = "WHERE %s" % thefilter 77 result = self.doRawSearch("SELECT * FROM billingcodes %s ORDER BY id ASC" % thefilter) 78 return self.prepareRawResult(result) 79 69 80 def extractGroups(self, extractonly={}) : 70 81 """Extracts all group records.""" … … 206 217 printer.Exists = 1 207 218 return printer 219 220 def getBillingCodeFromBackend(self, label) : 221 """Extracts a billing code information given its name.""" 222 code = StorageBillingCode(self, label) 223 result = self.doSearch("SELECT * FROM billingcodes WHERE billingcode=%s LIMIT 1" % self.doQuote(label)) 224 if result : 225 fields = result[0] 226 code.ident = fields.get("id") 227 code.BillingCode = fields.get("billingcode", label) 228 code.Description = self.databaseToUserCharset(fields.get("description") or "") 229 code.Balance = fields.get("balance") or 0.0 230 code.PageCounter = fields.get("pagecounter") or 0 231 code.Exists = 1 232 return code 208 233 209 234 def getUserPQuotaFromBackend(self, user, printer) : … … 329 354 self.cacheEntry("PRINTERS", printer.Name, printer) 330 355 return printers 356 357 def getMatchingBillingCodes(self, billingcodepattern) : 358 """Returns the list of all billing codes for which the label matches a certain pattern.""" 359 codes = [] 360 result = self.doSearch("SELECT * FROM billingcodes") 361 if result : 362 for record in result : 363 if self.tool.matchString(record["billingcode"], billingcodepattern.split(",")) : 364 code = StorageBillingCode(self, record["billingcode"]) 365 code.ident = record.get("id") 366 code.Balance = record.get("balance") or 0.0 367 code.PageCounter = record.get("pagecounter") or 0 368 code.Description = self.databaseToUserCharset(record.get("description") or "") 369 code.Exists = 1 370 codes.append(code) 371 self.cacheEntry("BILLINGCODES", code.BillingCode, code) 372 return codes 331 373 332 374 def getPrinterUsersAndQuotas(self, printer, names=["*"]) : … … 376 418 return self.getPrinter(printername) 377 419 420 def addBillingCode(self, label) : 421 """Adds a billing code to the quota storage, returns it.""" 422 self.doModify("INSERT INTO billingcodes (billingcode) VALUES (%s)" % self.doQuote(label)) 423 return self.getBillingCode(label) 424 378 425 def addUser(self, user) : 379 """Adds a user to the quota storage, returns it s id."""426 """Adds a user to the quota storage, returns it.""" 380 427 self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid, email, overcharge) VALUES (%s, %s, %s, %s, %s, %s)" % (self.doQuote(user.Name), self.doQuote(user.LimitBy or 'quota'), self.doQuote(user.AccountBalance or 0.0), self.doQuote(user.LifeTimePaid or 0.0), self.doQuote(user.Email), self.doQuote(user.OverCharge))) 381 428 return self.getUser(user.Name) 382 429 383 430 def addGroup(self, group) : 384 """Adds a group to the quota storage, returns it s id."""431 """Adds a group to the quota storage, returns it.""" 385 432 self.doModify("INSERT INTO groups (groupname, limitby) VALUES (%s, %s)" % (self.doQuote(group.Name), self.doQuote(group.LimitBy or "quota"))) 386 433 return self.getGroup(group.Name) … … 442 489 """Sets the new page counters permanently for a user print quota.""" 443 490 self.doModify("UPDATE userpquota SET pagecounter=%s, lifepagecounter=%s, warncount=0, datelimit=NULL WHERE id=%s" % (self.doQuote(newpagecounter), self.doQuote(newlifepagecounter), self.doQuote(userpquota.ident))) 491 492 def writeBillingCodeDescription(self, code) : 493 """Sets the new description for a billing code.""" 494 self.doModify("UPDATE billingcodes SET description=%s WHERE id=%s" % (self.doQuote(self.userCharsetToDatabase(code.Description or "")), self.doQuote(code.ident))) 495 496 def setBillingCodeValues(self, code, newbalance, newpagecounter) : 497 """Sets the new page counter and balance for a billing code.""" 498 self.doModify("UPDATE billingcodes SET balance=%s, pagecounter=%s WHERE id=%s" % (self.doQuote(newbalance), self.doQuote(newpagecounter), self.doQuote(code.ident))) 499 500 def consumeBillingCode(self, code, balance, pagecounter) : 501 """Consumes from a billing code.""" 502 self.doModify("UPDATE billingcodes SET balance=balance + %s, pagecounter=pagecounter + %s WHERE id=%s" % (self.doQuote(balance), self.doQuote(pagecounter), self.doQuote(code.ident))) 444 503 445 504 def decreaseUserAccountBalance(self, user, amount) : … … 593 652 ] : 594 653 self.doModify(q) 595 654 655 def deleteBillingCode(self, code) : 656 """Completely deletes a billing code from the Quota Storage.""" 657 for q in [ 658 "DELETE FROM billingcodes WHERE id=%s" % self.doQuote(code.ident), 659 ] : 660 self.doModify(q) 661 662 -
pykota/trunk/pykota/version.py
r2323 r2342 22 22 # 23 23 24 __version__ = "1.23alpha1 4_unofficial"24 __version__ = "1.23alpha15_unofficial" 25 25 26 26 __doc__ = "PyKota : a complete Printing Quota Solution for CUPS and LPRng."