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() |