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

    r2770 r2782  
    2929import pwd 
    3030 
    31 from pykota.tool import PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
     31from pykota.tool import Percent, PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
    3232from pykota.storage import StorageBillingCode 
    3333 
     
    116116                       _("credits")) 
    117117        elif options["delete"] :     
    118             self.display("\n%s..." % _("Deletion")) 
     118            percent = Percent(self, "\n%s..." % _("Deletion"), len(billingcodes)) 
    119119            self.storage.deleteManyBillingCodes(billingcodes) 
    120             self.display("\n") 
     120            percent.display("\n") 
    121121        else : 
    122122            reset = options["reset"] 
     
    129129            try : 
    130130                if options["add"] :     
    131                     self.display("%s...\n" % _("Creation")) 
    132                     nbtotal = len(names) 
    133                     for i in range(nbtotal) : 
    134                         bname = names[i] 
     131                    percent = Percent(self, "%s...\n" % _("Creation"), len(names)) 
     132                    for bname in names : 
    135133                        billingcode = StorageBillingCode(self.storage, bname) 
    136134                        self.modifyBillingCode(billingcode, reset, description) 
     
    143141                                self.modifyBillingCode(oldbillingcode, reset, description) 
    144142                                oldbillingcode.save() 
    145                         percent = 100.0 * float(i) / float(nbtotal) 
    146                         self.display("\r%.02f%%" % percent) 
     143                        percent.oneMore() 
    147144                else :         
    148                     self.display("\n%s...\n" % _("Modification")) 
    149                     nbtotal = len(billingcodes)             
    150                     for i in range(nbtotal) :         
    151                         billingcode = billingcodes[i] 
     145                    percent = Percent(self, "\n%s...\n" % _("Modification"), len(billingcodes)) 
     146                    for billingcode in billingcodes : 
    152147                        self.modifyBillingCode(billingcode, reset, description) 
    153148                        billingcode.save()     
    154                         percent = 100.0 * float(i) / float(nbtotal) 
    155                         self.display("\r%.02f%%" % percent) 
     149                        percent.oneMore() 
    156150            except :                     
    157151                self.storage.rollbackTransaction() 
     
    160154                self.storage.commitTransaction() 
    161155                         
    162         if not options["list"] :                 
    163             self.done() 
     156        try : 
     157            percent.done() 
     158        except NameError :     
     159            pass 
    164160                      
    165161if __name__ == "__main__" :