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