Changeset 2770

Show
Ignore:
Timestamp:
03/01/06 15:39:56 (18 years ago)
Author:
jerome
Message:

Now does all modifications in a single database transaction.

Location:
pykota/trunk/bin
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkbcodes

    r2769 r2770  
    125125                description = options["description"].strip() 
    126126            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.logdebug(_("Billing code [%s] already exists, skipping.") % bname) 
    138                         else :     
    139                             self.logdebug(_("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 :         
    145                 self.display("\n%s...\n" % _("Modification")) 
    146                 nbtotal = len(billingcodes)             
    147                 for i in range(nbtotal) :         
    148                     billingcode = billingcodes[i] 
    149                     self.modifyBillingCode(billingcode, reset, description) 
    150                     billingcode.save()     
    151                     percent = 100.0 * float(i) / float(nbtotal) 
    152                     self.display("\r%.02f%%" % percent) 
     127             
     128            self.storage.beginTransaction() 
     129            try : 
     130                if options["add"] :     
     131                    self.display("%s...\n" % _("Creation")) 
     132                    nbtotal = len(names) 
     133                    for i in range(nbtotal) : 
     134                        bname = names[i] 
     135                        billingcode = StorageBillingCode(self.storage, bname) 
     136                        self.modifyBillingCode(billingcode, reset, description) 
     137                        oldbillingcode = self.storage.addBillingCode(billingcode) 
     138                        if oldbillingcode is not None : 
     139                            if skipexisting : 
     140                                self.logdebug(_("Billing code [%s] already exists, skipping.") % bname) 
     141                            else :     
     142                                self.logdebug(_("Billing code [%s] already exists, will be modified.") % bname) 
     143                                self.modifyBillingCode(oldbillingcode, reset, description) 
     144                                oldbillingcode.save() 
     145                        percent = 100.0 * float(i) / float(nbtotal) 
     146                        self.display("\r%.02f%%" % percent) 
     147                else :         
     148                    self.display("\n%s...\n" % _("Modification")) 
     149                    nbtotal = len(billingcodes)             
     150                    for i in range(nbtotal) :         
     151                        billingcode = billingcodes[i] 
     152                        self.modifyBillingCode(billingcode, reset, description) 
     153                        billingcode.save()     
     154                        percent = 100.0 * float(i) / float(nbtotal) 
     155                        self.display("\r%.02f%%" % percent) 
     156            except :                     
     157                self.storage.rollbackTransaction() 
     158                raise 
     159            else :     
     160                self.storage.commitTransaction() 
    153161                         
    154162        if not options["list"] :                 
  • pykota/trunk/bin/pkprinters

    r2769 r2770  
    214214            remove = options["remove"] 
    215215            skipexisting = options["skipexisting"] 
    216             if options["add"] :     
    217                 self.display("%s...\n" % _("Creation")) 
    218                 nbtotal = len(names) 
    219                 for i in range(nbtotal) : 
    220                     pname = names[i] 
    221                     if self.isValidName(pname) : 
    222                         printer = StoragePrinter(self.storage, pname) 
    223                         self.modifyPrinter(printer, charges, perpage, perjob,\ 
    224                                        description, passthrough, \ 
    225                                        nopassthrough, maxjobsize) 
    226                         oldprinter = self.storage.addPrinter(printer)                
    227                         if oldprinter is not None : 
    228                             if skipexisting : 
    229                                 self.logdebug(_("Printer %s already exists, skipping.") % pname) 
    230                             else :     
    231                                 self.logdebug(_("Printer %s already exists, will be modified.") % pname) 
    232                                 self.modifyPrinter(oldprinter, charges, \ 
    233                                            perpage, perjob, description, \ 
    234                                            passthrough, nopassthrough, \ 
    235                                            maxjobsize) 
    236                                 oldprinter.save()            
    237                                 self.managePrintersGroups(printersgroups, oldprinter, remove) 
    238                         elif printersgroups :         
    239                             self.managePrintersGroups(printersgroups, \ 
    240                                                       self.storage.getPrinter(pname), \ 
    241                                                       remove) 
    242                     else :     
    243                         raise PyKotaCommandLineError, _("Invalid printer name %s") % pname 
    244                     percent = 100.0 * float(i) / float(nbtotal) 
    245                     self.display("\r%.02f%%" % percent) 
    246             else :         
    247                 self.display("\n%s...\n" % _("Modification")) 
    248                 nbtotal = len(printers) 
    249                 for i in range(nbtotal) :         
    250                     printer = printers[i] 
    251                     self.modifyPrinter(printer, charges, perpage, perjob, \ 
    252                                        description, passthrough, \ 
    253                                        nopassthrough, maxjobsize) 
    254                     printer.save()     
    255                     self.managePrintersGroups(printersgroups, printer, remove) 
    256                     percent = 100.0 * float(i) / float(nbtotal) 
    257                     self.display("\r%.02f%%" % percent) 
    258                                  
     216            self.storage.beginTransaction() 
     217            try : 
     218                if options["add"] :     
     219                    self.display("%s...\n" % _("Creation")) 
     220                    nbtotal = len(names) 
     221                    for i in range(nbtotal) : 
     222                        pname = names[i] 
     223                        if self.isValidName(pname) : 
     224                            printer = StoragePrinter(self.storage, pname) 
     225                            self.modifyPrinter(printer, charges, perpage, perjob,\ 
     226                                           description, passthrough, \ 
     227                                           nopassthrough, maxjobsize) 
     228                            oldprinter = self.storage.addPrinter(printer)                
     229                            if oldprinter is not None : 
     230                                if skipexisting : 
     231                                    self.logdebug(_("Printer %s already exists, skipping.") % pname) 
     232                                else :     
     233                                    self.logdebug(_("Printer %s already exists, will be modified.") % pname) 
     234                                    self.modifyPrinter(oldprinter, charges, \ 
     235                                               perpage, perjob, description, \ 
     236                                               passthrough, nopassthrough, \ 
     237                                               maxjobsize) 
     238                                    oldprinter.save()            
     239                                    self.managePrintersGroups(printersgroups, oldprinter, remove) 
     240                            elif printersgroups :         
     241                                self.managePrintersGroups(printersgroups, \ 
     242                                                          self.storage.getPrinter(pname), \ 
     243                                                          remove) 
     244                        else :     
     245                            raise PyKotaCommandLineError, _("Invalid printer name %s") % pname 
     246                        percent = 100.0 * float(i) / float(nbtotal) 
     247                        self.display("\r%.02f%%" % percent) 
     248                else :         
     249                    self.display("\n%s...\n" % _("Modification")) 
     250                    nbtotal = len(printers) 
     251                    for i in range(nbtotal) :         
     252                        printer = printers[i] 
     253                        self.modifyPrinter(printer, charges, perpage, perjob, \ 
     254                                           description, passthrough, \ 
     255                                           nopassthrough, maxjobsize) 
     256                        printer.save()     
     257                        self.managePrintersGroups(printersgroups, printer, remove) 
     258                        percent = 100.0 * float(i) / float(nbtotal) 
     259                        self.display("\r%.02f%%" % percent) 
     260            except :                     
     261                self.storage.rollbackTransaction() 
     262                raise 
     263            else :     
     264                self.storage.commitTransaction() 
    259265        if not options["list"] :                 
    260266            self.done()