485 | | def getPrintersUsersAndPQuotas(self, pnames = ["*"], unames=["*"]) : |
486 | | """Returns all printers, users and users print quota entries which match a set of names.""" |
487 | | matchunames = {} |
488 | | matchpnames = {} |
489 | | printers = {} |
490 | | users = {} |
491 | | upquotas = {} |
492 | | 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;") |
493 | | if result : |
494 | | for record in result : |
495 | | uname = self.databaseToUserCharset(record.get("username")) |
496 | | pname = self.databaseToUserCharset(record.get("printername")) |
497 | | if not matchpnames.has_key(pname) : |
498 | | matchpnames[pname] = printermatches = self.tool.matchString(pname, pnames) |
499 | | else : |
500 | | printermatches = matchpnames[pname] |
501 | | if printermatches : |
502 | | if not matchunames.has_key(uname) : |
503 | | matchunames[uname] = usermatches = self.tool.matchString(uname, unames) |
504 | | else : |
505 | | usermatches = matchunames[uname] |
506 | | if usermatches : |
507 | | printer = StoragePrinter(self, pname) |
508 | | printer.ident = record.get("pid") |
509 | | printer.PricePerJob = record.get("priceperjob") or 0.0 |
510 | | printer.PricePerPage = record.get("priceperpage") or 0.0 |
511 | | printer.Description = self.databaseToUserCharset(record.get("pdesc") or "") |
512 | | printer.MaxJobSize = record.get("pmaxjobsize") or 0 |
513 | | printer.PassThrough = record.get("passthrough") or 0 |
514 | | if printer.PassThrough in (1, "1", "t", "true", "TRUE", "True") : |
515 | | printer.PassThrough = 1 |
516 | | else : |
517 | | printer.PassThrough = 0 |
518 | | printer.Exists = 1 |
519 | | printers[pname] = printer |
520 | | self.cacheEntry("PRINTERS", pname, printer) |
521 | | |
522 | | user = StorageUser(self, uname) |
523 | | user.ident = record.get("uid") |
524 | | user.LimitBy = record.get("limitby") or "quota" |
525 | | user.AccountBalance = record.get("balance") |
526 | | user.LifeTimePaid = record.get("lifetimepaid") |
527 | | user.Email = record.get("email") |
528 | | user.OverCharge = record.get("overcharge") |
529 | | user.Description = self.databaseToUserCharset(record.get("udesc")) |
530 | | user.Exists = 1 |
531 | | users[uname] = user |
532 | | self.cacheEntry("USERS", uname, user) |
533 | | |
534 | | upqkey = "%s@%s" % (uname, pname) |
535 | | userpquota = StorageUserPQuota(self, user, printer) |
536 | | userpquota.ident = record.get("id") |
537 | | userpquota.PageCounter = record.get("pagecounter") |
538 | | userpquota.LifePageCounter = record.get("lifepagecounter") |
539 | | userpquota.SoftLimit = record.get("softlimit") |
540 | | userpquota.HardLimit = record.get("hardlimit") |
541 | | userpquota.DateLimit = record.get("datelimit") |
542 | | userpquota.WarnCount = record.get("warncount") |
543 | | userpquota.Exists = 1 |
544 | | upquotas[upqkey] = userpquota |
545 | | self.cacheEntry("USERPQUOTAS", upqkey, userpquota) |
546 | | return (printers, users, upquotas) |
547 | | |
548 | | def getPrintersGroupsAndPQuotas(self, pnames = ["*"], gnames=["*"]) : |
549 | | """Returns all printers, groups and groups print quota entries which match a set of names.""" |
550 | | matchgnames = {} |
551 | | matchpnames = {} |
552 | | printers = {} |
553 | | groups = {} |
554 | | gpquotas = {} |
555 | | result = self.doSearch("SELECT printername, groupname FROM printers, groups") |
556 | | if result : |
557 | | for record in result : |
558 | | gname = self.databaseToUserCharset(record.get("groupname")) |
559 | | pname = self.databaseToUserCharset(record.get("printername")) |
560 | | if not matchpnames.has_key(pname) : |
561 | | matchpnames[pname] = printermatches = self.tool.matchString(pname, pnames) |
562 | | else : |
563 | | printermatches = matchpnames[pname] |
564 | | if printermatches : |
565 | | if not matchgnames.has_key(gname) : |
566 | | matchgnames[gname] = groupmatches = self.tool.matchString(gname, gnames) |
567 | | else : |
568 | | groupmatches = matchgnames[gname] |
569 | | if groupmatches : |
570 | | printer = self.getPrinter(pname) |
571 | | printers[pname] = printer |
572 | | group = self.getGroup(gname) |
573 | | groups[gname] = group |
574 | | gpqkey = "%s@%s" % (gname, pname) |
575 | | gpquotas[upqkey] = self.getGroupPQuota(group, printer) |
576 | | return (printers, groups, gpquotas) |
577 | | |