| 464 | def getMatchingUserPQuotas(self, pnames = ["*"], unames=["*"]) : |
| 465 | """Returns all printers, users and users print quota entries which match a set of names.""" |
| 466 | printers = {} |
| 467 | users = {} |
| 468 | upquotas = {} |
| 469 | result = self.doSearch("SELECT users.id AS uid, users.description AS udesc, printers.id AS pid, printers.description AS pdesc, printers.maxjobsize AS pmaxjobsize, userpquota.id AS upqid, userpquota.maxjobsize AS upqmaxjobsize, users.*, printers.*, userpquota.* FROM users, printers, userpquota WHERE users.id=userpquota.userid AND printers.id=userpquota.printerid;") |
| 470 | if result : |
| 471 | for record in result : |
| 472 | uname = self.databaseToUserCharset(record.get("username")) |
| 473 | pname = self.databaseToUserCharset(record.get("printername")) |
| 474 | if self.tool.matchString(pname, pnames) and self.tool.matchString(uname, unames) : |
| 475 | if not printers.has_key(pname) : |
| 476 | printer = StoragePrinter(self, pname) |
| 477 | printer.ident = record.get("pid") |
| 478 | printer.PricePerJob = record.get("priceperjob") or 0.0 |
| 479 | printer.PricePerPage = record.get("priceperpage") or 0.0 |
| 480 | printer.Description = self.databaseToUserCharset(record.get("pdesc") or "") |
| 481 | printer.MaxJobSize = record.get("pmaxjobsize") or 0 |
| 482 | printer.PassThrough = record.get("passthrough") or 0 |
| 483 | if printer.PassThrough in (1, "1", "t", "true", "TRUE", "True") : |
| 484 | printer.PassThrough = 1 |
| 485 | else : |
| 486 | printer.PassThrough = 0 |
| 487 | printer.Exists = 1 |
| 488 | printers[pname] = printer |
| 489 | self.cacheEntry("PRINTERS", pname, printer) |
| 490 | |
| 491 | if not users.has_key(uname) : |
| 492 | user = StorageUser(self, uname) |
| 493 | user.ident = record.get("uid") |
| 494 | user.LimitBy = record.get("limitby") or "quota" |
| 495 | user.AccountBalance = record.get("balance") |
| 496 | user.LifeTimePaid = record.get("lifetimepaid") |
| 497 | user.Email = record.get("email") |
| 498 | user.OverCharge = record.get("overcharge") |
| 499 | user.Description = self.databaseToUserCharset(record.get("udesc")) |
| 500 | user.Exists = 1 |
| 501 | users[uname] = user |
| 502 | self.cacheEntry("USERS", uname, user) |
| 503 | |
| 504 | upqkey = "%s@%s" % (uname, pname) |
| 505 | if not upquotas.has_key(upqkey) : # NB : should always be verified. |
| 506 | userpquota = StorageUserPQuota(self, users[uname], printers[pname]) |
| 507 | userpquota.ident = record.get("id") |
| 508 | userpquota.PageCounter = record.get("pagecounter") |
| 509 | userpquota.LifePageCounter = record.get("lifepagecounter") |
| 510 | userpquota.SoftLimit = record.get("softlimit") |
| 511 | userpquota.HardLimit = record.get("hardlimit") |
| 512 | userpquota.DateLimit = record.get("datelimit") |
| 513 | userpquota.WarnCount = record.get("warncount") |
| 514 | userpquota.Exists = 1 |
| 515 | upquotas[upqkey] = userpquota |
| 516 | self.cacheEntry("USERPQUOTAS", upqkey, userpquota) |
| 517 | return (printers, users, upquotas) |
| 518 | |
| 519 | def getMatchingGroupPQuotas(self, pnames = ["*"], gnames=["*"]) : |
| 520 | """Returns all printers, groups and groups print quota entries which match a set of names.""" |
| 521 | printers = {} |
| 522 | groups = {} |
| 523 | gpquotas = {} |
| 524 | result = self.doSearch("SELECT printername, groupname FROM printers, groups") |
| 525 | if result : |
| 526 | for record in result : |
| 527 | gname = self.databaseToUserCharset(record.get("groupname")) |
| 528 | pname = self.databaseToUserCharset(record.get("printername")) |
| 529 | if self.tool.matchString(pname, pnames) and self.tool.matchString(gname, gnames) : |
| 530 | if not printers.has_key(pname) : |
| 531 | printers[pname] = self.getPrinter(pname) |
| 532 | |
| 533 | if not groups.has_key(gname) : |
| 534 | groups[gname] = self.getGroup(gname) |
| 535 | |
| 536 | gpqkey = "%s@%s" % (gname, pname) |
| 537 | if not gpquotas.has_key(gpqkey) : # NB : should always be verified. |
| 538 | gpquotas[upqkey] = self.getGroupPQuota(groups[gname], printers[pname]) |
| 539 | return (printers, groups, gpquotas) |
| 540 | |
467 | | result = self.doSearch("SELECT users.id as uid,username,balance,lifetimepaid,limitby,email,overcharge,userpquota.id,lifepagecounter,pagecounter,softlimit,hardlimit,datelimit,warncount FROM users JOIN userpquota ON users.id=userpquota.userid AND printerid=%s ORDER BY username ASC" % self.doQuote(printer.ident)) |
| 544 | result = self.doSearch("SELECT users.id as uid,username,description,balance,lifetimepaid,limitby,email,overcharge,userpquota.id,lifepagecounter,pagecounter,softlimit,hardlimit,datelimit,warncount FROM users JOIN userpquota ON users.id=userpquota.userid AND printerid=%s ORDER BY username ASC" % self.doQuote(printer.ident)) |