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/pkusers

    r2774 r2782  
    3030import grp 
    3131 
    32 from pykota.tool import PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
     32from pykota.tool import Percent, PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
    3333from pykota.storage import StorageUser, StorageGroup 
    3434 
     
    235235                    print 
    236236        elif options["delete"] :     
    237             self.display("\n%s..." % _("Deletion")) 
     237            percent = Percent(self, "\n%s..." % _("Deletion"), len(entries)) 
    238238            getattr(self.storage, "deleteMany%ss" % suffix)(entries) 
    239             self.display("\n") 
     239            percent.display("\n") 
    240240        else : 
    241241            limitby = options["limitby"] 
     
    286286            try :     
    287287                if options["add"] :     
    288                     self.display("%s...\n" % _("Creation")) 
    289288                    rejectunknown = self.config.getRejectUnknown()     
    290                     nbtotal = len(names) 
    291                     for i in range(nbtotal) : 
    292                         ename = names[i] 
     289                    percent = Percent(self, "%s...\n" % _("Creation"), len(names)) 
     290                    for ename in names : 
    293291                        email = None 
    294292                        if not groups : 
     
    347345                        else : 
    348346                            raise PyKotaCommandLineError, _("Invalid name %s") % ename 
    349                         percent = 100.0 * float(i) / float(nbtotal) 
    350                         self.display("\r%.02f%%" % percent) 
     347                        percent.oneMore() 
    351348                else : 
    352                     self.display("\n%s...\n" % _("Modification")) 
    353                     nbtotal = len(entries) 
    354                     for i in range(nbtotal) :         
    355                         entry = entries[i] 
     349                    percent = Percent(self, "\n%s...\n" % _("Modification"), len(entries))  
     350                    for entry in entries : 
    356351                        if groups : 
    357352                            self.modifyEntry(entry, groups, limitby, description) 
     
    362357                            self.manageUsersGroups(usersgroups, entry, remove)                 
    363358                        entry.save()     
    364                         percent = 100.0 * float(i) / float(nbtotal) 
    365                         self.display("\r%.02f%%" % percent) 
     359                        percent.oneMore() 
    366360            except :                     
    367361                self.storage.rollbackTransaction() 
     
    369363            else :     
    370364                self.storage.commitTransaction() 
    371                                  
    372         if not options["list"] :                 
    373             self.done() 
     365                 
     366        try : 
     367            percent.done() 
     368        except NameError :     
     369            pass 
    374370                      
    375371if __name__ == "__main__" :