Show
Ignore:
Timestamp:
03/04/06 15:51:12 (18 years ago)
Author:
jerome
Message:

Code cleaning.
Topped to 10000 the number of times the percent will be displayed by not displaying it if there's no change.
This is very useful when adding 25000 users on 300 printers through an ssh connection...

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/edpykota

    r2772 r2782  
    2828import os 
    2929 
    30 from pykota.tool import PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
     30from pykota.tool import Percent, PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
    3131from pykota.config import PyKotaConfigError 
    3232from pykota.storage import PyKotaStorageError, StorageUserPQuota, StorageGroupPQuota 
     
    197197                        print 
    198198        elif options["delete"] :     
    199             self.display("\n%s..." % _("Deletion")) 
     199            percent = Percent(self, "\n%s..." % _("Deletion"), len(printers) * len(entries)) 
    200200            getattr(self.storage, "deleteMany%sPQuotas" % suffix)(printers, entries) 
    201             self.display("\n") 
     201            percent.display("\n") 
    202202        else : 
    203             self.display("\n")     
    204203            skipexisting = options["skipexisting"] 
    205204            used = options["used"] 
     
    253252            try : 
    254253                if options["add"] : 
    255                     self.display("%s...\n" % _("Creation")) 
     254                    percent = Percent(self, "\n%s...\n" % _("Creation"), len(printers) * len(entries)) 
    256255                    dicnames = {} 
    257256                    for m in entries : 
     
    262261                             
    263262                    factory = globals()["Storage%sPQuota" % suffix] 
    264                     nbtotal = len(printers) * len(entries) 
    265                     i = 0 
    266263                    for printer in printers : 
    267264                        pname = printer.Name 
     
    285282                                                        hardreset, suffix, used) 
    286283                                    oldpqentry.save()                     
    287                             i += 1 
    288                             percent = 100.0 * float(i) / float(nbtotal) 
    289                             self.display("\r%.02f%%" % percent) 
     284                            percent.oneMore() 
    290285                else :         
    291                     nbtotal = len(entries) * len(printers) 
    292                     if nbtotal : 
    293                         self.display("%s...\n" % _("Modification")) 
    294                         i = 0 
    295                         for printer in printers : 
    296                             for entry in entries : 
    297                                 pqkey = "%s@%s" % (entry.Name, printer.Name) 
    298                                 pqentry = getattr(self.storage, "get%sPQuota" % suffix)(entry, printer) 
    299                                 if pqentry.Exists :      
    300                                     self.modifyPQEntry(pqkey, pqentry, noquota, \ 
    301                                                         softlimit, hardlimit, \ 
    302                                                         increase, reset, \ 
    303                                                         hardreset, suffix, used) 
    304                                     pqentry.save()         
    305                                 i += 1             
    306                                 percent = 100.0 * float(i) / float(nbtotal) 
    307                                 self.display("\r%.02f%%" % percent) 
     286                    percent = Percent(self, "\n%s...\n" % _("Modification"), len(entries) * len(printers)) 
     287                    for printer in printers : 
     288                        for entry in entries : 
     289                            pqkey = "%s@%s" % (entry.Name, printer.Name) 
     290                            pqentry = getattr(self.storage, "get%sPQuota" % suffix)(entry, printer) 
     291                            if pqentry.Exists :      
     292                                self.modifyPQEntry(pqkey, pqentry, noquota, \ 
     293                                                    softlimit, hardlimit, \ 
     294                                                    increase, reset, \ 
     295                                                    hardreset, suffix, used) 
     296                                pqentry.save()         
     297                            percent.oneMore() 
    308298            except :                     
    309299                self.storage.rollbackTransaction() 
     
    312302                self.storage.commitTransaction() 
    313303                             
    314         if not options["list"] : 
    315             self.done()          
     304        try : 
     305            percent.done() 
     306        except NameError :     
     307            pass 
    316308             
    317309if __name__ == "__main__" :