260 | | sys.stdout.write(_("Managing print quotas... (this may take a lot of time)")) |
261 | | sys.stdout.flush() |
262 | | missingusers = {} |
263 | | missinggroups = {} |
264 | | changed = {} # tracks changes made at the user/group level |
265 | | for printer in printers : |
266 | | if not options["noquota"] : |
267 | | if hardlimit is None : |
268 | | hardlimit = softlimit |
269 | | if hardlimit is not None : |
270 | | self.printInfo(_("Undefined hard limit set to soft limit (%s) on printer %s.") % (str(hardlimit), printer.Name)) |
271 | | if softlimit is None : |
272 | | softlimit = hardlimit |
273 | | if softlimit is not None : |
274 | | self.printInfo(_("Undefined soft limit set to hard limit (%s) on printer %s.") % (str(softlimit), printer.Name)) |
| 269 | nbtotal = len(pqentries) |
| 270 | i = 0 |
| 271 | for pqentry in pqentries : |
| 272 | ename = getattr(pqentry, suffix).Name |
| 273 | pname = pqentry.Printer.Name |
| 274 | if pqentry.Exists : |
| 275 | if noquota or ((softlimit is not None) and (hardlimit is not None)) : |
| 276 | pqentry.setLimits(softlimit, hardlimit) |
| 277 | |
| 278 | if increase : |
| 279 | if (pqentry.SoftLimit is None) \ |
| 280 | or (pqentry.HardLimit is None) : |
| 281 | self.printInfo(_("You can't increase limits by %s when no limit is set.") % increase, "error") |
| 282 | else : |
| 283 | newsoft = pqentry.SoftLimit + increase |
| 284 | newhard = pqentry.HardLimit + increase |
| 285 | if (newsoft >= 0) and (newhard >= 0) : |
| 286 | pqentry.setLimits(newsoft, newhard) |
| 287 | else : |
| 288 | self.printInfo(_("You can't set negative limits."), "error") |
| 289 | |
| 290 | if options["reset"] : |
| 291 | pqentry.reset() |
| 292 | |
| 293 | if options["hardreset"] : |
| 294 | pqentry.hardreset() |
| 295 | |
| 296 | if not options["groups"] : |
| 297 | if used : |
| 298 | pqentry.setUsage(used) |
276 | | if options["add"] : |
277 | | allentries = [] |
278 | | for name in names : |
279 | | email = "" |
280 | | if not options["groups"] : |
281 | | splitname = name.split('/', 1) # username/email |
282 | | if len(splitname) == 1 : |
283 | | splitname.append("") |
284 | | (name, email) = splitname |
285 | | if email and (email.count('@') != 1) : |
286 | | self.printInfo(_("Invalid email address %s") % email) |
287 | | email = "" |
288 | | entry = getattr(self.storage, "get%s" % suffix)(name) |
289 | | if email and not options["groups"] : |
290 | | entry.Email = email |
291 | | entrypquota = getattr(self.storage, "get%sPQuota" % suffix)(entry, printer) |
292 | | allentries.append((entry, entrypquota)) |
293 | | else : |
294 | | allentries = getattr(self.storage, "getPrinter%ssAndQuotas" % suffix)(printer, names) |
295 | | |
296 | | for (entry, entrypquota) in allentries : |
297 | | if not changed.has_key(entry.Name) : |
298 | | changed[entry.Name] = {} |
299 | | if not options["groups"] : |
300 | | changed[entry.Name]["ingroups"] = [] |
301 | | |
302 | | if entry.Exists and (not entrypquota.Exists) : |
303 | | # not found |
304 | | if options["add"] : |
305 | | entrypquota = getattr(self.storage, "add%sPQuota" % suffix)(entry, printer) |
306 | | |
307 | | if not entrypquota.Exists : |
308 | | self.printInfo(_("Quota not found for object %s on printer %s.") % (entry.Name, printer.Name)) |
309 | | else : |
310 | | if options["noquota"] \ |
311 | | or ((softlimit is not None) and (hardlimit is not None)) : |
312 | | entrypquota.setLimits(softlimit, hardlimit) |
313 | | |
314 | | if increase : |
315 | | if (entrypquota.SoftLimit is None) \ |
316 | | or (entrypquota.HardLimit is None) : |
317 | | self.printInfo(_("You can't increase limits by %s when no limit is set.") % increase, "error") |
318 | | else : |
319 | | newsoft = entrypquota.SoftLimit + increase |
320 | | newhard = entrypquota.HardLimit + increase |
321 | | if (newsoft >= 0) and (newhard >= 0) : |
322 | | entrypquota.setLimits(newsoft, newhard) |
323 | | else : |
324 | | self.printInfo(_("You can't set negative limits."), "error") |
325 | | |
326 | | if options["reset"] : |
327 | | entrypquota.reset() |
328 | | |
329 | | if options["hardreset"] : |
330 | | entrypquota.hardreset() |
331 | | |
332 | | if not options["groups"] : |
333 | | if used : |
334 | | entrypquota.setUsage(used) |
| 300 | pqentry.save() |
| 301 | i += 1 |
| 302 | percent = 100.0 * float(i) / float(nbtotal) |
| 303 | self.display("\r%.02f%%" % percent) |