Changeset 1133
- Timestamp:
- 10/03/03 14:27:03 (21 years ago)
- Location:
- pykota/trunk
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/edpykota
r1120 r1133 23 23 # 24 24 # $Log$ 25 # Revision 1.58 2003/10/03 12:27:01 jalet 26 # Several optimizations, especially with LDAP backend 27 # 25 28 # Revision 1.57 2003/08/20 16:01:19 jalet 26 29 # Comment added. … … 473 476 allentries.append((entry, entrypquota)) 474 477 else : 475 allentries = getattr(self.storage, "getPrinter%ssAndQuotas" % suffix)(printer )478 allentries = getattr(self.storage, "getPrinter%ssAndQuotas" % suffix)(printer, names) 476 479 477 for (entry, entrypquota) in [(e, q) for (e, q) in allentries if self.matchString(e.Name, names)]:480 for (entry, entrypquota) in allentries : 478 481 if not changed.has_key(entry.Name) : 479 482 changed[entry.Name] = {} -
pykota/trunk/pykota/storages/ldapstorage.py
r1131 r1133 21 21 # 22 22 # $Log$ 23 # Revision 1.28 2003/10/03 12:27:02 jalet 24 # Several optimizations, especially with LDAP backend 25 # 23 26 # Revision 1.27 2003/10/03 08:57:55 jalet 24 27 # Caching mechanism now caches all that's cacheable. … … 403 406 printers = [] 404 407 # see comment at the same place in pgstorage.py 405 result = self.doSearch(" objectClass=pykotaPrinter", ["pykotaPrinterName", "pykotaPricePerPage", "pykotaPricePerJob"], base=self.info["printerbase"])408 result = self.doSearch("(&(objectClass=pykotaPrinter)(|%s))" % "".join(["(pykotaPrinterName=%s)" % pname for pname in printerpattern.split(",")]), ["pykotaPrinterName", "pykotaPricePerPage", "pykotaPricePerJob"], base=self.info["printerbase"]) 406 409 if result : 407 410 for (printerid, fields) in result : 408 411 printername = fields["pykotaPrinterName"][0] 409 if self.tool.matchString(printername, [ printerpattern ]) : 410 printer = StoragePrinter(self, printername) 411 printer.ident = printerid 412 printer.PricePerJob = float(fields.get("pykotaPricePerJob")[0] or 0.0) 413 printer.PricePerPage = float(fields.get("pykotaPricePerPage")[0] or 0.0) 414 printer.LastJob = self.getPrinterLastJob(printer) 415 printer.Exists = 1 416 printers.append(printer) 417 self.cacheEntry("PRINTERS", printer.Name, printer) 412 printer = StoragePrinter(self, printername) 413 printer.ident = printerid 414 printer.PricePerJob = float(fields.get("pykotaPricePerJob")[0] or 0.0) 415 printer.PricePerPage = float(fields.get("pykotaPricePerPage")[0] or 0.0) 416 printer.LastJob = self.getPrinterLastJob(printer) 417 printer.Exists = 1 418 printers.append(printer) 419 self.cacheEntry("PRINTERS", printer.Name, printer) 418 420 return printers 419 421 420 def getPrinterUsersAndQuotas(self, printer, names= None) :422 def getPrinterUsersAndQuotas(self, printer, names=["*"]) : 421 423 """Returns the list of users who uses a given printer, along with their quotas.""" 422 424 usersandquotas = [] 423 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s) )" % printer.Name, ["pykotaUserName", "pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], base=self.info["userquotabase"])425 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s)(|%s))" % (printer.Name, "".join(["(pykotaUserName=%s)" % uname for uname in names])), ["pykotaUserName", "pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], base=self.info["userquotabase"]) 424 426 if result : 425 427 for (userquotaid, fields) in result : 426 user = self.getUser(fields["pykotaUserName"][0]) 427 if (names is None) or self.tool.matchString(user.Name, names) : 428 userpquota = StorageUserPQuota(self, user, printer) 429 userpquota.ident = userquotaid 430 userpquota.PageCounter = int(fields.get("pykotaPageCounter")[0] or 0) 431 userpquota.LifePageCounter = int(fields.get("pykotaLifePageCounter")[0] or 0) 432 userpquota.SoftLimit = fields.get("pykotaSoftLimit") 433 if userpquota.SoftLimit is not None : 434 if userpquota.SoftLimit[0].upper() == "NONE" : 435 userpquota.SoftLimit = None 436 else : 437 userpquota.SoftLimit = int(userpquota.SoftLimit[0]) 438 userpquota.HardLimit = fields.get("pykotaHardLimit") 439 if userpquota.HardLimit is not None : 440 if userpquota.HardLimit[0].upper() == "NONE" : 441 userpquota.HardLimit = None 442 elif userpquota.HardLimit is not None : 443 userpquota.HardLimit = int(userpquota.HardLimit[0]) 444 userpquota.DateLimit = fields.get("pykotaDateLimit") 445 if userpquota.DateLimit is not None : 446 if userpquota.DateLimit[0].upper() == "NONE" : 447 userpquota.DateLimit = None 448 else : 449 userpquota.DateLimit = userpquota.DateLimit[0] 450 userpquota.Exists = 1 451 usersandquotas.append((user, userpquota)) 452 self.cacheEntry("USERPQUOTAS", "%s@%s" % (user.Name, printer.Name), userpquota) 428 user = self.getUser(fields.get("pykotaUserName")[0]) 429 userpquota = StorageUserPQuota(self, user, printer) 430 userpquota.ident = userquotaid 431 userpquota.PageCounter = int(fields.get("pykotaPageCounter")[0] or 0) 432 userpquota.LifePageCounter = int(fields.get("pykotaLifePageCounter")[0] or 0) 433 userpquota.SoftLimit = fields.get("pykotaSoftLimit") 434 if userpquota.SoftLimit is not None : 435 if userpquota.SoftLimit[0].upper() == "NONE" : 436 userpquota.SoftLimit = None 437 else : 438 userpquota.SoftLimit = int(userpquota.SoftLimit[0]) 439 userpquota.HardLimit = fields.get("pykotaHardLimit") 440 if userpquota.HardLimit is not None : 441 if userpquota.HardLimit[0].upper() == "NONE" : 442 userpquota.HardLimit = None 443 elif userpquota.HardLimit is not None : 444 userpquota.HardLimit = int(userpquota.HardLimit[0]) 445 userpquota.DateLimit = fields.get("pykotaDateLimit") 446 if userpquota.DateLimit is not None : 447 if userpquota.DateLimit[0].upper() == "NONE" : 448 userpquota.DateLimit = None 449 else : 450 userpquota.DateLimit = userpquota.DateLimit[0] 451 userpquota.Exists = 1 452 usersandquotas.append((user, userpquota)) 453 self.cacheEntry("USERPQUOTAS", "%s@%s" % (user.Name, printer.Name), userpquota) 453 454 usersandquotas.sort(lambda x, y : cmp(x[0].Name, y[0].Name)) 454 455 return usersandquotas 455 456 456 def getPrinterGroupsAndQuotas(self, printer, names= None) :457 def getPrinterGroupsAndQuotas(self, printer, names=["*"]) : 457 458 """Returns the list of groups which uses a given printer, along with their quotas.""" 458 459 groupsandquotas = [] 459 result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaPrinterName=%s) )" % printer.Name, ["pykotaGroupName"], base=self.info["groupquotabase"])460 result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaPrinterName=%s)(|%s))" % (printer.Name, "".join(["(pykotaGroupName=%s)" % gname for gname in names])), ["pykotaGroupName"], base=self.info["groupquotabase"]) 460 461 if result : 461 462 for (groupquotaid, fields) in result : 462 463 group = self.getGroup(fields.get("pykotaGroupName")[0]) 463 if (names is None) or self.tool.matchString(group.Name, names) : 464 grouppquota = self.getGroupPQuota(group, printer) 465 groupsandquotas.append((group, grouppquota)) 464 grouppquota = self.getGroupPQuota(group, printer) 465 groupsandquotas.append((group, grouppquota)) 466 466 groupsandquotas.sort(lambda x, y : cmp(x[0].Name, y[0].Name)) 467 467 return groupsandquotas -
pykota/trunk/pykota/storages/pgstorage.py
r1131 r1133 21 21 # 22 22 # $Log$ 23 # Revision 1.15 2003/10/03 12:27:03 jalet 24 # Several optimizations, especially with LDAP backend 25 # 23 26 # Revision 1.14 2003/10/03 08:57:55 jalet 24 27 # Caching mechanism now caches all that's cacheable. … … 302 305 if result : 303 306 for record in result : 304 user = StorageUser(self, record.get("username"))305 if (names is None) or self.tool.matchString(user.Name, names) :307 if (names is None) or self.tool.matchString(record.get("username"), names) : 308 user = StorageUser(self, record.get("username")) 306 309 user.ident = record.get("uid") 307 310 user.LimitBy = record.get("limitby") … … 329 332 if result : 330 333 for record in result : 331 group = self.getGroup(record.get("groupname"))332 if (names is None) or self.tool.matchString(group.Name, names) :334 if (names is None) or self.tool.matchString(record.get("groupname"), names) : 335 group = self.getGroup(record.get("groupname")) 333 336 grouppquota = self.getGroupPQuota(group, printer) 334 337 groupsandquotas.append((group, grouppquota))