Show
Ignore:
Timestamp:
03/01/06 10:47:49 (18 years ago)
Author:
jerome
Message:

Optimized pkprinters like pkbcodes and edpykota.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkbcodes

    r2765 r2768  
    106106                raise PyKotaCommandLineError, _("There's no billingcode matching %s") % " ".join(names) 
    107107                         
    108         reset = options["reset"] 
    109         description = options["description"] 
    110         if description : 
    111             description = options["description"].strip() 
    112                  
    113         if options["delete"] :     
     108        if options["list"] : 
     109            for billingcode in billingcodes : 
     110                print "%s [%s] %s %s %s %.2f %s" % \ 
     111                      (billingcode.BillingCode, billingcode.Description, \ 
     112                       billingcode.PageCounter, \ 
     113                       _("pages"), \ 
     114                       _("and"), \ 
     115                       billingcode.Balance, \ 
     116                       _("credits")) 
     117        elif options["delete"] :     
    114118            self.display("\n%s..." % _("Deletion")) 
    115119            self.storage.deleteManyBillingCodes(billingcodes) 
    116120            self.display("\n") 
    117         elif options["add"] :     
    118             self.display("%s...\n" % _("Creation")) 
    119             nbtotal = len(names) 
    120             for i in range(nbtotal) : 
    121                 bname = names[i] 
    122                 billingcode = StorageBillingCode(self.storage, bname) 
    123                 self.modifyBillingCode(billingcode, reset, description) 
    124                 oldbillingcode = self.storage.addBillingCode(billingcode) 
    125                 if oldbillingcode is not None : 
    126                     if options["skipexisting"] : 
    127                         self.printInfo(_("Billing code [%s] already exists, skipping.") % bname) 
    128                     else :     
    129                         self.printInfo(_("Billing code [%s] already exists, will be modified.") % bname) 
    130                         self.modifyBillingCode(oldbillingcode, reset, description) 
    131                         oldbillingcode.save() 
    132                 percent = 100.0 * float(i) / float(nbtotal) 
    133                 self.display("\r%.02f%%" % percent) 
    134         else :         
    135             if options["list"] : 
    136                 for billingcode in billingcodes : 
    137                     if billingcode.Exists : 
    138                         print "%s [%s] %s %s %s %.2f %s" % \ 
    139                           (billingcode.BillingCode, billingcode.Description, \ 
    140                            billingcode.PageCounter, \ 
    141                            _("pages"), \ 
    142                            _("and"), \ 
    143                            billingcode.Balance, \ 
    144                            _("credits")) 
    145             else :                
     121        else : 
     122            reset = options["reset"] 
     123            description = options["description"] 
     124            if description : 
     125                description = options["description"].strip() 
     126            skipexisting = options["skipexisting"]         
     127            if options["add"] :     
     128                self.display("%s...\n" % _("Creation")) 
     129                nbtotal = len(names) 
     130                for i in range(nbtotal) : 
     131                    bname = names[i] 
     132                    billingcode = StorageBillingCode(self.storage, bname) 
     133                    self.modifyBillingCode(billingcode, reset, description) 
     134                    oldbillingcode = self.storage.addBillingCode(billingcode) 
     135                    if oldbillingcode is not None : 
     136                        if skipexisting : 
     137                            self.printInfo(_("Billing code [%s] already exists, skipping.") % bname) 
     138                        else :     
     139                            self.printInfo(_("Billing code [%s] already exists, will be modified.") % bname) 
     140                            self.modifyBillingCode(oldbillingcode, reset, description) 
     141                            oldbillingcode.save() 
     142                    percent = 100.0 * float(i) / float(nbtotal) 
     143                    self.display("\r%.02f%%" % percent) 
     144            else :         
    146145                self.display("\n%s...\n" % _("Modification")) 
    147146                nbtotal = len(billingcodes)             
     
    152151                    percent = 100.0 * float(i) / float(nbtotal) 
    153152                    self.display("\r%.02f%%" % percent) 
    154                      
     153                         
    155154        if not options["list"] :                 
    156155            self.done()