Index: pykota/trunk/bin/edpykota
===================================================================
--- pykota/trunk/bin/edpykota (revision 2743)
+++ pykota/trunk/bin/edpykota (revision 2749)
@@ -32,5 +32,5 @@
 from pykota.tool import PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_
 from pykota.config import PyKotaConfigError
-from pykota.storage import PyKotaStorageError
+from pykota.storage import PyKotaStorageError, StorageUserPQuota, StorageGroupPQuota
 
 __doc__ = N_("""edpykota v%(__version__)s (c) %(__years__)s %(__author__)s
@@ -163,138 +163,90 @@
             names = ["*"]
             
-        before = time.time()
-        (printers, entries, pqentries) = getattr(self.storage, "getPrinters%ssAndPQuotas" % suffix)(printernames, names)
-        after = time.time()
-        self.printInfo("Data extraction took : %.4f seconds" % (after - before))
+        if not options["list"] :
+            self.display(_("Extracting datas..."))
+        printers = self.storage.getMatchingPrinters(options["printer"])
+        entries = getattr(self.storage, "getMatching%ss" % suffix)(",".join(names))
         
         if options["delete"] :    
-            self.display("%s...\n" % _("Deletion"))
-            nbtotal = len(pqentries)
-            for i in range(nbtotal) :
-                (pqkey, pqentry) = pqentries.popitem()
-                if pqentry.Exists :
-                    pqentry.delete()
-                percent = 100.0 * float(i) / float(nbtotal)
-                self.display("\r%.02f%%" % percent)
+            self.display("\n%s..." % _("Deletion"))
+            getattr(self.storage, "deleteMany%sPQuotas" % suffix)(printers, entries)
+            self.display("\n")
+            self.display("\r100.00%%\r        \r%s\n" % _("Done."))
         else :
             skipexisting = options["skipexisting"]
+            used = options["used"]
+            if used :
+                used = used.strip()
+                try :
+                    int(used)
+                except ValueError :
+                    raise PyKotaCommandLineError, _("Invalid used value %s.") % used
+                    
+            increase = options["increase"]
+            if increase :
+                try :
+                    increase = int(increase.strip())
+                except ValueError :
+                    raise PyKotaCommandLineError, _("Invalid increase value %s.") % increase
+            
+            softlimit = hardlimit = None
+            noquota = options["noquota"]
+            if not noquota :
+                if options["softlimit"] :
+                    try :
+                        softlimit = int(options["softlimit"].strip())
+                        if softlimit < 0 :
+                            raise ValueError
+                    except ValueError :    
+                        raise PyKotaCommandLineError, _("Invalid softlimit value %s.") % options["softlimit"]
+                if options["hardlimit"] :
+                    try :
+                        hardlimit = int(options["hardlimit"].strip())
+                        if hardlimit < 0 :
+                            raise ValueError
+                    except ValueError :    
+                        raise PyKotaCommandLineError, _("Invalid hardlimit value %s.") % options["hardlimit"]
+                if (softlimit is not None) and (hardlimit is not None) and (hardlimit < softlimit) :        
+                    # error, exchange them
+                    self.printInfo(_("Hard limit %i is less than soft limit %i, values will be exchanged.") % (hardlimit, softlimit))
+                    (softlimit, hardlimit) = (hardlimit, softlimit)
+                if hardlimit is None :    
+                    hardlimit = softlimit
+                    if hardlimit is not None :
+                        self.printInfo(_("Undefined hard limit set to soft limit (%s).") % str(hardlimit))
+                if softlimit is None :    
+                    softlimit = hardlimit
+                    if softlimit is not None :
+                        self.printInfo(_("Undefined soft limit set to hard limit (%s).") % str(softlimit))
+                        
+            pqentries = []            
             if options["add"] :
-                self.display("%s...\n" % _("Creation"))
-                mentries = getattr(self.storage, "getMatching%ss" % suffix)(",".join(names))
+                self.display("\n%s...\n" % _("Creation"))
                 dicnames = {}
-                for m in mentries :
+                for m in entries :
                     dicnames[m.Name] = None
                 for name in names :
                     if not dicnames.has_key(name) :
-                        self.printInfo(_("Impossible to create print quota entries if the user or group object %s doesn't already exist. Please use pkusers to create it first.") % name, "warn")
-                mprinters = self.storage.getMatchingPrinters(options["printer"])
-                nbtotal = len(mprinters) * len(mentries)
+                        self.printInfo(_("Impossible to create print quota entries if the user or group object '%s' doesn't already exist. Please use pkusers to create it first.") % name, "warn")
+                        
+                factory = globals()["Storage%sPQuota" % suffix]
+                nbtotal = len(printers) * len(entries)
                 i = 0
-                for printer in mprinters :
+                for printer in printers :
                     pname = printer.Name
-                    for entry in mentries :
+                    for entry in entries :
                         ename = entry.Name
                         pqkey = "%s@%s" % (ename, pname)
-                        if pqentries.has_key(pqkey) and pqentries[pqkey].Exists :
-                            if skipexisting :
-                                self.printInfo(_("%s print quota entry %s@%s already exists, skipping.") % (suffix, ename, pname))
-                                del pqentries[pqkey]
-                            else :    
-                                self.printInfo(_("%s print quota entry %s@%s already exists, will be modified.") % (suffix, ename, pname))
-                        else :        
-                            newpqentry = getattr(self.storage, "add%sPQuota" % suffix)(entry, printer)
-                            if not newpqentry.Exists :
-                                self.printInfo(_("Impossible to create a print quota entry for %s@%s") % (ename, pname))
-                            else :
-                                pqentries[pqkey] = newpqentry
-                        i += 1
-                        percent = 100.0 * float(i) / float(nbtotal)
-                        self.display("\r%.02f%%" % percent)
-                self.display("\r100.00%%\r        \r%s\n" % _("Done."))
-                
-            if not pqentries :
-                raise PyKotaCommandLineError, _("There's no %s print quota entry matching %s") % (suffix.lower(), " ".join(names))
-                    
-            if options["list"] :
-                for (name, entry) in pqentries.items() :
-                    if entry.Exists :
-                        print name
-                        print "    %s" % (_("Page counter : %s") % entry.PageCounter)
-                        print "    %s" % (_("Lifetime page counter : %s") % entry.LifePageCounter)
-                        print "    %s" % (_("Soft limit : %s") % entry.SoftLimit)
-                        print "    %s" % (_("Hard limit : %s") % entry.HardLimit)
-                        print "    %s" % (_("Date limit : %s") % entry.DateLimit)
-                        # TODO : print "    %s" % (_("Maximum job size : %s") % ((entry.MaxJobSize and (_("%s pages") % entry.MaxJobSize)) or _("Unlimited")))
-                        if hasattr(entry, "WarnCount") :
-                            print "    %s" % (_("Warning banners printed : %s") % entry.WarnCount)
-                        print
-            else :
-                self.display("%s...\n" % _("Modification"))
-                
-                used = options["used"]
-                if used :
-                    used = used.strip()
-                    try :
-                        int(used)
-                    except ValueError :
-                        raise PyKotaCommandLineError, _("Invalid used value %s.") % used
-                        
-                increase = options["increase"]
-                if increase :
-                    try :
-                        increase = int(increase.strip())
-                    except ValueError :
-                        raise PyKotaCommandLineError, _("Invalid increase value %s.") % increase
-                
-                softlimit = hardlimit = None
-                noquota = options["noquota"]
-                if not noquota :
-                    if options["softlimit"] :
-                        try :
-                            softlimit = int(options["softlimit"].strip())
-                            if softlimit < 0 :
-                                raise ValueError
-                        except ValueError :    
-                            raise PyKotaCommandLineError, _("Invalid softlimit value %s.") % options["softlimit"]
-                    if options["hardlimit"] :
-                        try :
-                            hardlimit = int(options["hardlimit"].strip())
-                            if hardlimit < 0 :
-                                raise ValueError
-                        except ValueError :    
-                            raise PyKotaCommandLineError, _("Invalid hardlimit value %s.") % options["hardlimit"]
-                    if (softlimit is not None) and (hardlimit is not None) and (hardlimit < softlimit) :        
-                        # error, exchange them
-                        self.printInfo(_("Hard limit %i is less than soft limit %i, values will be exchanged.") % (hardlimit, softlimit))
-                        (softlimit, hardlimit) = (hardlimit, softlimit)
-                    if hardlimit is None :    
-                        hardlimit = softlimit
-                        if hardlimit is not None :
-                            self.printInfo(_("Undefined hard limit set to soft limit (%s) on printer %s.") % (str(hardlimit), printer.Name))
-                    if softlimit is None :    
-                        softlimit = hardlimit
-                        if softlimit is not None :
-                            self.printInfo(_("Undefined soft limit set to hard limit (%s) on printer %s.") % (str(softlimit), printer.Name))
-                    
-                nbtotal = len(pqentries)    
-                i = 0
-                for (pqkey, pqentry) in pqentries.items() :
-                    ename = getattr(pqentry, suffix).Name
-                    pname = pqentry.Printer.Name
-                    if pqentry.Exists :     
+                        pqentry = factory(self.storage, entry, printer)
                         if noquota or ((softlimit is not None) and (hardlimit is not None)) :
                             pqentry.setLimits(softlimit, hardlimit)
                             
                         if increase :
-                           if (pqentry.SoftLimit is None) \
-                               or (pqentry.HardLimit is None) :
-                               self.printInfo(_("You can't increase limits by %s when no limit is set.") % increase, "error")
-                           else :
-                               newsoft = pqentry.SoftLimit + increase         
-                               newhard = pqentry.HardLimit + increase         
-                               if (newsoft >= 0) and (newhard >= 0) :
-                                   pqentry.setLimits(newsoft, newhard)
-                               else :    
-                                   self.printInfo(_("You can't set negative limits."), "error")
+                            newsoft = (pqentry.SoftLimit or 0) + increase         
+                            newhard = (pqentry.HardLimit or 0) + increase         
+                            if (newsoft >= 0) and (newhard >= 0) :
+                                pqentry.setLimits(newsoft, newhard)
+                            else :    
+                                self.printInfo(_("You can't set negative limits."), "error")
                         
                         if options["reset"] :
@@ -307,12 +259,72 @@
                             if used :
                                 pqentry.setUsage(used)
+                        
+                        oldpqentry = getattr(self.storage, "add%sPQuota" % suffix)(pqentry)
+                        if oldpqentry is not None :    
+                            if skipexisting :
+                                self.printInfo(_("%s print quota entry %s@%s already exists, skipping.") % (suffix, ename, pname))
+                            else :    
+                                self.printInfo(_("%s print quota entry %s@%s already exists, will be modified.") % (suffix, ename, pname))
+                                pqentries.append(oldpqentry)
+                        i += 1
+                        percent = 100.0 * float(i) / float(nbtotal)
+                        self.display("\r%.02f%%" % percent)
+                self.display("\r100.00%%\r        \r%s" % _("Done."))
+            else :    
+                for printer in printers :
+                    for entry in entries :
+                        pqentries.append(getattr(self.storage, "get%sPQuota" % suffix)(entry, printer))
+                if not pqentries :        
+                    raise PyKotaCommandLineError, _("There's no %s print quota entry matching %s") % (suffix.lower(), " ".join(names))
+                    
+            if options["list"] :
+                for pqentry in pqentries :
+                    if pqentry.Exists :
+                        print "%s@%s" % (getattr(pqentry, suffix).Name, pqentry.Printer.Name)
+                        print "    %s" % (_("Page counter : %s") % pqentry.PageCounter)
+                        print "    %s" % (_("Lifetime page counter : %s") % pqentry.LifePageCounter)
+                        print "    %s" % (_("Soft limit : %s") % pqentry.SoftLimit)
+                        print "    %s" % (_("Hard limit : %s") % pqentry.HardLimit)
+                        print "    %s" % (_("Date limit : %s") % pqentry.DateLimit)
+                        print "    %s (Not supported yet)" % (_("Maximum job size : %s") % ((pqentry.MaxJobSize and (_("%s pages") % pqentry.MaxJobSize)) or _("Unlimited")))
+                        if hasattr(pqentry, "WarnCount") :
+                            print "    %s" % (_("Warning banners printed : %s") % pqentry.WarnCount)
+                        print
+            else :
+                self.display("\n")
+                nbtotal = len(pqentries)    
+                if nbtotal :
+                    self.display("%s...\n" % _("Modification"))
+                    i = 0
+                    for pqentry in pqentries :
+                        ename = getattr(pqentry, suffix).Name
+                        pname = pqentry.Printer.Name
+                        if pqentry.Exists :     
+                            if noquota or ((softlimit is not None) and (hardlimit is not None)) :
+                                pqentry.setLimits(softlimit, hardlimit)
                                 
-                        pqentry.save()        
-                    i += 1            
-                    percent = 100.0 * float(i) / float(nbtotal)
-                    self.display("\r%.02f%%" % percent)
+                            if increase :
+                                newsoft = (pqentry.SoftLimit or 0) + increase         
+                                newhard = (pqentry.HardLimit or 0) + increase         
+                                if (newsoft >= 0) and (newhard >= 0) :
+                                    pqentry.setLimits(newsoft, newhard)
+                                else :    
+                                    self.printInfo(_("You can't set negative limits for %s@%s") % (ename, pname), "error")
+                            
+                            if options["reset"] :
+                                pqentry.reset()
                                 
-        if not options["list"] :                
-            self.display("\r100.00%%\r        \r%s\n" % _("Done."))
+                            if options["hardreset"] :    
+                                pqentry.hardreset()
+                                
+                            if not options["groups"] :
+                                if used :
+                                    pqentry.setUsage(used)
+                                    
+                            pqentry.save()        
+                        i += 1            
+                        percent = 100.0 * float(i) / float(nbtotal)
+                        self.display("\r%.02f%%" % percent)
+                    self.display("\r100.00%%\r        \r%s\n" % _("Done."))
                      
 if __name__ == "__main__" : 
