253 | | if options["add"] : |
254 | | self.display("%s...\n" % _("Creation")) |
255 | | dicnames = {} |
256 | | for m in entries : |
257 | | dicnames[m.Name] = None |
258 | | for name in names : |
259 | | if not dicnames.has_key(name) : |
260 | | self.printInfo(_("Impossible to create print quota entries if the user or group object '%s' doesn't already exist. Please use pkusers to create it first.") % name, "warn") |
261 | | |
262 | | factory = globals()["Storage%sPQuota" % suffix] |
263 | | nbtotal = len(printers) * len(entries) |
264 | | i = 0 |
265 | | for printer in printers : |
266 | | pname = printer.Name |
267 | | for entry in entries : |
268 | | ename = entry.Name |
269 | | pqkey = "%s@%s" % (ename, pname) |
270 | | pqentry = factory(self.storage, entry, printer) |
271 | | self.modifyPQEntry(pqkey, pqentry, noquota, \ |
272 | | softlimit, hardlimit, \ |
273 | | increase, reset, \ |
274 | | hardreset, suffix, used) |
275 | | oldpqentry = getattr(self.storage, "add%sPQuota" % suffix)(pqentry) |
276 | | if oldpqentry is not None : |
277 | | if skipexisting : |
278 | | self.logdebug("%s print quota entry %s@%s already exists, skipping." % (suffix, ename, pname)) |
279 | | else : |
280 | | self.logdebug("%s print quota entry %s@%s already exists, will be modified." % (suffix, ename, pname)) |
281 | | self.modifyPQEntry(pqkey, oldpqentry, noquota, \ |
282 | | softlimit, hardlimit, \ |
283 | | increase, reset, \ |
284 | | hardreset, suffix, used) |
285 | | oldpqentry.save() |
286 | | i += 1 |
287 | | percent = 100.0 * float(i) / float(nbtotal) |
288 | | self.display("\r%.02f%%" % percent) |
289 | | else : |
290 | | nbtotal = len(entries) * len(printers) |
291 | | if nbtotal : |
292 | | self.display("%s...\n" % _("Modification")) |
| 252 | self.storage.beginTransaction() |
| 253 | try : |
| 254 | if options["add"] : |
| 255 | self.display("%s...\n" % _("Creation")) |
| 256 | dicnames = {} |
| 257 | for m in entries : |
| 258 | dicnames[m.Name] = None |
| 259 | for name in names : |
| 260 | if not dicnames.has_key(name) : |
| 261 | self.printInfo(_("Impossible to create print quota entries if the user or group object '%s' doesn't already exist. Please use pkusers to create it first.") % name, "warn") |
| 262 | |
| 263 | factory = globals()["Storage%sPQuota" % suffix] |
| 264 | nbtotal = len(printers) * len(entries) |
296 | | pqkey = "%s@%s" % (entry.Name, printer.Name) |
297 | | pqentry = getattr(self.storage, "get%sPQuota" % suffix)(entry, printer) |
298 | | if pqentry.Exists : |
299 | | self.modifyPQEntry(pqkey, pqentry, noquota, \ |
300 | | softlimit, hardlimit, \ |
301 | | increase, reset, \ |
302 | | hardreset, suffix, used) |
303 | | pqentry.save() |
304 | | i += 1 |
| 269 | ename = entry.Name |
| 270 | pqkey = "%s@%s" % (ename, pname) |
| 271 | pqentry = factory(self.storage, entry, printer) |
| 272 | self.modifyPQEntry(pqkey, pqentry, noquota, \ |
| 273 | softlimit, hardlimit, \ |
| 274 | increase, reset, \ |
| 275 | hardreset, suffix, used) |
| 276 | oldpqentry = getattr(self.storage, "add%sPQuota" % suffix)(pqentry) |
| 277 | if oldpqentry is not None : |
| 278 | if skipexisting : |
| 279 | self.logdebug("%s print quota entry %s@%s already exists, skipping." % (suffix, ename, pname)) |
| 280 | else : |
| 281 | self.logdebug("%s print quota entry %s@%s already exists, will be modified." % (suffix, ename, pname)) |
| 282 | self.modifyPQEntry(pqkey, oldpqentry, noquota, \ |
| 283 | softlimit, hardlimit, \ |
| 284 | increase, reset, \ |
| 285 | hardreset, suffix, used) |
| 286 | oldpqentry.save() |
| 287 | i += 1 |
| 290 | else : |
| 291 | nbtotal = len(entries) * len(printers) |
| 292 | if nbtotal : |
| 293 | self.display("%s...\n" % _("Modification")) |
| 294 | i = 0 |
| 295 | for printer in printers : |
| 296 | for entry in entries : |
| 297 | pqkey = "%s@%s" % (entry.Name, printer.Name) |
| 298 | pqentry = getattr(self.storage, "get%sPQuota" % suffix)(entry, printer) |
| 299 | if pqentry.Exists : |
| 300 | self.modifyPQEntry(pqkey, pqentry, noquota, \ |
| 301 | softlimit, hardlimit, \ |
| 302 | increase, reset, \ |
| 303 | hardreset, suffix, used) |
| 304 | pqentry.save() |
| 305 | i += 1 |
| 306 | percent = 100.0 * float(i) / float(nbtotal) |
| 307 | self.display("\r%.02f%%" % percent) |
| 308 | except : |
| 309 | self.storage.rollbackTransaction() |
| 310 | raise |
| 311 | else : |
| 312 | self.storage.commitTransaction() |
| 313 | |
| 314 | if not options["list"] : |