Index: /pykota/trunk/pykota/storages/sql.py
===================================================================
--- /pykota/trunk/pykota/storages/sql.py (revision 2721)
+++ /pykota/trunk/pykota/storages/sql.py (revision 2722)
@@ -462,8 +462,85 @@
         return codes        
         
+    def getMatchingUserPQuotas(self, pnames = ["*"], unames=["*"]) :    
+        """Returns all printers, users and users print quota entries which match a set of names."""
+        printers = {}
+        users = {}
+        upquotas = {}
+        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;")
+        if result :
+            for record in result :
+                uname = self.databaseToUserCharset(record.get("username"))
+                pname = self.databaseToUserCharset(record.get("printername"))
+                if self.tool.matchString(pname, pnames) and self.tool.matchString(uname, unames) :
+                    if not printers.has_key(pname) :
+                        printer = StoragePrinter(self, pname)
+                        printer.ident = record.get("pid")
+                        printer.PricePerJob = record.get("priceperjob") or 0.0
+                        printer.PricePerPage = record.get("priceperpage") or 0.0
+                        printer.Description = self.databaseToUserCharset(record.get("pdesc") or "") 
+                        printer.MaxJobSize = record.get("pmaxjobsize") or 0
+                        printer.PassThrough = record.get("passthrough") or 0
+                        if printer.PassThrough in (1, "1", "t", "true", "TRUE", "True") :
+                            printer.PassThrough = 1
+                        else :
+                            printer.PassThrough = 0
+                        printer.Exists = 1
+                        printers[pname] = printer
+                        self.cacheEntry("PRINTERS", pname, printer)
+                    
+                    if not users.has_key(uname) :
+                        user = StorageUser(self, uname)
+                        user.ident = record.get("uid")
+                        user.LimitBy = record.get("limitby") or "quota"
+                        user.AccountBalance = record.get("balance")
+                        user.LifeTimePaid = record.get("lifetimepaid")
+                        user.Email = record.get("email") 
+                        user.OverCharge = record.get("overcharge")
+                        user.Description = self.databaseToUserCharset(record.get("udesc"))
+                        user.Exists = 1
+                        users[uname] = user
+                        self.cacheEntry("USERS", uname, user)
+                    
+                    upqkey = "%s@%s" % (uname, pname)
+                    if not upquotas.has_key(upqkey) : # NB : should always be verified.
+                        userpquota = StorageUserPQuota(self, users[uname], printers[pname])
+                        userpquota.ident = record.get("id")
+                        userpquota.PageCounter = record.get("pagecounter")
+                        userpquota.LifePageCounter = record.get("lifepagecounter")
+                        userpquota.SoftLimit = record.get("softlimit")
+                        userpquota.HardLimit = record.get("hardlimit")
+                        userpquota.DateLimit = record.get("datelimit")
+                        userpquota.WarnCount = record.get("warncount")
+                        userpquota.Exists = 1
+                        upquotas[upqkey] = userpquota
+                        self.cacheEntry("USERPQUOTAS", upqkey, userpquota)
+        return (printers, users, upquotas)
+        
+    def getMatchingGroupPQuotas(self, pnames = ["*"], gnames=["*"]) :    
+        """Returns all printers, groups and groups print quota entries which match a set of names."""
+        printers = {}
+        groups = {}
+        gpquotas = {}
+        result = self.doSearch("SELECT printername, groupname FROM printers, groups")
+        if result :
+            for record in result :
+                gname = self.databaseToUserCharset(record.get("groupname"))
+                pname = self.databaseToUserCharset(record.get("printername"))
+                if self.tool.matchString(pname, pnames) and self.tool.matchString(gname, gnames) :
+                    if not printers.has_key(pname) :
+                        printers[pname] = self.getPrinter(pname)
+                    
+                    if not groups.has_key(gname) :
+                        groups[gname] = self.getGroup(gname)
+                    
+                    gpqkey = "%s@%s" % (gname, pname)
+                    if not gpquotas.has_key(gpqkey) : # NB : should always be verified.
+                        gpquotas[upqkey] = self.getGroupPQuota(groups[gname], printers[pname])
+        return (printers, groups, gpquotas)
+        
     def getPrinterUsersAndQuotas(self, printer, names=["*"]) :        
         """Returns the list of users who uses a given printer, along with their quotas."""
         usersandquotas = []
-        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))
+        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))
         if result :
             for record in result :
Index: /pykota/trunk/pykota/storages/ldapstorage.py
===================================================================
--- /pykota/trunk/pykota/storages/ldapstorage.py (revision 2721)
+++ /pykota/trunk/pykota/storages/ldapstorage.py (revision 2722)
@@ -827,4 +827,34 @@
         return usersandquotas
                 
+    def getMatchingUserPQuotas(self, pnames = ["*"], unames=["*"]) :    
+        """Returns all printers, users and users print quota entries which match a set of names."""
+        printers = {}
+        users = {}
+        upquotas = {}
+        for printer in self.getMatchingPrinters(",".join(pnames)) :
+            printers[printer.Name] = printer
+        for user in self.getMatchingUsers(",".join(unames)) :
+            users[user.Name] = user
+        for (p, printer) in printers.items() :
+            for (u, user) in users.items() :
+                upqkey = "%s@%s" % (u, p)
+                upquotas[upqkey] = self.getUserPQuota(user, printer)
+        return (printers, users, upquotas)
+        
+    def getMatchingGroupPQuotas(self, pnames = ["*"], gnames=["*"]) :    
+        """Returns all printers, groups and groups print quota entries which match a set of names."""
+        printers = {}
+        groups = {}
+        gpquotas = {}
+        for printer in self.getMatchingPrinters(",".join(pnames)) :
+            printers[printer.Name] = printer
+        for group in self.getMatchingGroups(",".join(gnames)) :
+            groups[group.Name] = group
+        for (p, printer) in printers.items() :
+            for (g, group) in groups.items() :
+                gpqkey = "%s@%s" % (g, p)
+                gpquotas[gpqkey] = self.getGroupPQuota(group, printer)
+        return (printers, groups, gpquotas)
+        
     def getPrinterGroupsAndQuotas(self, printer, names=["*"]) :        
         """Returns the list of groups which uses a given printer, along with their quotas."""
