| 177 | used = options["used"] |
| 178 | if used : |
| 179 | used = used.strip() |
| 180 | try : |
| 181 | int(used) |
| 182 | except ValueError : |
| 183 | raise PyKotaCommandLineError, _("Invalid used value %s.") % used |
| 184 | |
| 185 | increase = options["increase"] |
| 186 | if increase : |
| 187 | try : |
| 188 | increase = int(increase.strip()) |
| 189 | except ValueError : |
| 190 | raise PyKotaCommandLineError, _("Invalid increase value %s.") % increase |
| 191 | |
| 192 | softlimit = hardlimit = None |
| 193 | noquota = options["noquota"] |
| 194 | if not noquota : |
| 195 | if options["softlimit"] : |
| 196 | try : |
| 197 | softlimit = int(options["softlimit"].strip()) |
| 198 | if softlimit < 0 : |
| 199 | raise ValueError |
| 200 | except ValueError : |
| 201 | raise PyKotaCommandLineError, _("Invalid softlimit value %s.") % options["softlimit"] |
| 202 | if options["hardlimit"] : |
| 203 | try : |
| 204 | hardlimit = int(options["hardlimit"].strip()) |
| 205 | if hardlimit < 0 : |
| 206 | raise ValueError |
| 207 | except ValueError : |
| 208 | raise PyKotaCommandLineError, _("Invalid hardlimit value %s.") % options["hardlimit"] |
| 209 | if (softlimit is not None) and (hardlimit is not None) and (hardlimit < softlimit) : |
| 210 | # error, exchange them |
| 211 | self.printInfo(_("Hard limit %i is less than soft limit %i, values will be exchanged.") % (hardlimit, softlimit)) |
| 212 | (softlimit, hardlimit) = (hardlimit, softlimit) |
| 213 | if hardlimit is None : |
| 214 | hardlimit = softlimit |
| 215 | if hardlimit is not None : |
| 216 | self.printInfo(_("Undefined hard limit set to soft limit (%s).") % str(hardlimit)) |
| 217 | if softlimit is None : |
| 218 | softlimit = hardlimit |
| 219 | if softlimit is not None : |
| 220 | self.printInfo(_("Undefined soft limit set to hard limit (%s).") % str(softlimit)) |
| 221 | |
| 222 | pqentries = [] |
198 | | if pqentries.has_key(pqkey) and pqentries[pqkey].Exists : |
199 | | if skipexisting : |
200 | | self.printInfo(_("%s print quota entry %s@%s already exists, skipping.") % (suffix, ename, pname)) |
201 | | del pqentries[pqkey] |
202 | | else : |
203 | | self.printInfo(_("%s print quota entry %s@%s already exists, will be modified.") % (suffix, ename, pname)) |
204 | | else : |
205 | | newpqentry = getattr(self.storage, "add%sPQuota" % suffix)(entry, printer) |
206 | | if not newpqentry.Exists : |
207 | | self.printInfo(_("Impossible to create a print quota entry for %s@%s") % (ename, pname)) |
208 | | else : |
209 | | pqentries[pqkey] = newpqentry |
210 | | i += 1 |
211 | | percent = 100.0 * float(i) / float(nbtotal) |
212 | | self.display("\r%.02f%%" % percent) |
213 | | self.display("\r100.00%%\r \r%s\n" % _("Done.")) |
214 | | |
215 | | if not pqentries : |
216 | | raise PyKotaCommandLineError, _("There's no %s print quota entry matching %s") % (suffix.lower(), " ".join(names)) |
217 | | |
218 | | if options["list"] : |
219 | | for (name, entry) in pqentries.items() : |
220 | | if entry.Exists : |
221 | | print name |
222 | | print " %s" % (_("Page counter : %s") % entry.PageCounter) |
223 | | print " %s" % (_("Lifetime page counter : %s") % entry.LifePageCounter) |
224 | | print " %s" % (_("Soft limit : %s") % entry.SoftLimit) |
225 | | print " %s" % (_("Hard limit : %s") % entry.HardLimit) |
226 | | print " %s" % (_("Date limit : %s") % entry.DateLimit) |
227 | | # TODO : print " %s" % (_("Maximum job size : %s") % ((entry.MaxJobSize and (_("%s pages") % entry.MaxJobSize)) or _("Unlimited"))) |
228 | | if hasattr(entry, "WarnCount") : |
229 | | print " %s" % (_("Warning banners printed : %s") % entry.WarnCount) |
230 | | print |
231 | | else : |
232 | | self.display("%s...\n" % _("Modification")) |
233 | | |
234 | | used = options["used"] |
235 | | if used : |
236 | | used = used.strip() |
237 | | try : |
238 | | int(used) |
239 | | except ValueError : |
240 | | raise PyKotaCommandLineError, _("Invalid used value %s.") % used |
241 | | |
242 | | increase = options["increase"] |
243 | | if increase : |
244 | | try : |
245 | | increase = int(increase.strip()) |
246 | | except ValueError : |
247 | | raise PyKotaCommandLineError, _("Invalid increase value %s.") % increase |
248 | | |
249 | | softlimit = hardlimit = None |
250 | | noquota = options["noquota"] |
251 | | if not noquota : |
252 | | if options["softlimit"] : |
253 | | try : |
254 | | softlimit = int(options["softlimit"].strip()) |
255 | | if softlimit < 0 : |
256 | | raise ValueError |
257 | | except ValueError : |
258 | | raise PyKotaCommandLineError, _("Invalid softlimit value %s.") % options["softlimit"] |
259 | | if options["hardlimit"] : |
260 | | try : |
261 | | hardlimit = int(options["hardlimit"].strip()) |
262 | | if hardlimit < 0 : |
263 | | raise ValueError |
264 | | except ValueError : |
265 | | raise PyKotaCommandLineError, _("Invalid hardlimit value %s.") % options["hardlimit"] |
266 | | if (softlimit is not None) and (hardlimit is not None) and (hardlimit < softlimit) : |
267 | | # error, exchange them |
268 | | self.printInfo(_("Hard limit %i is less than soft limit %i, values will be exchanged.") % (hardlimit, softlimit)) |
269 | | (softlimit, hardlimit) = (hardlimit, softlimit) |
270 | | if hardlimit is None : |
271 | | hardlimit = softlimit |
272 | | if hardlimit is not None : |
273 | | self.printInfo(_("Undefined hard limit set to soft limit (%s) on printer %s.") % (str(hardlimit), printer.Name)) |
274 | | if softlimit is None : |
275 | | softlimit = hardlimit |
276 | | if softlimit is not None : |
277 | | self.printInfo(_("Undefined soft limit set to hard limit (%s) on printer %s.") % (str(softlimit), printer.Name)) |
278 | | |
279 | | nbtotal = len(pqentries) |
280 | | i = 0 |
281 | | for (pqkey, pqentry) in pqentries.items() : |
282 | | ename = getattr(pqentry, suffix).Name |
283 | | pname = pqentry.Printer.Name |
284 | | if pqentry.Exists : |
| 240 | pqentry = factory(self.storage, entry, printer) |
289 | | if (pqentry.SoftLimit is None) \ |
290 | | or (pqentry.HardLimit is None) : |
291 | | self.printInfo(_("You can't increase limits by %s when no limit is set.") % increase, "error") |
292 | | else : |
293 | | newsoft = pqentry.SoftLimit + increase |
294 | | newhard = pqentry.HardLimit + increase |
295 | | if (newsoft >= 0) and (newhard >= 0) : |
296 | | pqentry.setLimits(newsoft, newhard) |
297 | | else : |
298 | | self.printInfo(_("You can't set negative limits."), "error") |
| 245 | newsoft = (pqentry.SoftLimit or 0) + increase |
| 246 | newhard = (pqentry.HardLimit or 0) + increase |
| 247 | if (newsoft >= 0) and (newhard >= 0) : |
| 248 | pqentry.setLimits(newsoft, newhard) |
| 249 | else : |
| 250 | self.printInfo(_("You can't set negative limits."), "error") |
| 261 | |
| 262 | oldpqentry = getattr(self.storage, "add%sPQuota" % suffix)(pqentry) |
| 263 | if oldpqentry is not None : |
| 264 | if skipexisting : |
| 265 | self.printInfo(_("%s print quota entry %s@%s already exists, skipping.") % (suffix, ename, pname)) |
| 266 | else : |
| 267 | self.printInfo(_("%s print quota entry %s@%s already exists, will be modified.") % (suffix, ename, pname)) |
| 268 | pqentries.append(oldpqentry) |
| 269 | i += 1 |
| 270 | percent = 100.0 * float(i) / float(nbtotal) |
| 271 | self.display("\r%.02f%%" % percent) |
| 272 | self.display("\r100.00%%\r \r%s" % _("Done.")) |
| 273 | else : |
| 274 | for printer in printers : |
| 275 | for entry in entries : |
| 276 | pqentries.append(getattr(self.storage, "get%sPQuota" % suffix)(entry, printer)) |
| 277 | if not pqentries : |
| 278 | raise PyKotaCommandLineError, _("There's no %s print quota entry matching %s") % (suffix.lower(), " ".join(names)) |
| 279 | |
| 280 | if options["list"] : |
| 281 | for pqentry in pqentries : |
| 282 | if pqentry.Exists : |
| 283 | print "%s@%s" % (getattr(pqentry, suffix).Name, pqentry.Printer.Name) |
| 284 | print " %s" % (_("Page counter : %s") % pqentry.PageCounter) |
| 285 | print " %s" % (_("Lifetime page counter : %s") % pqentry.LifePageCounter) |
| 286 | print " %s" % (_("Soft limit : %s") % pqentry.SoftLimit) |
| 287 | print " %s" % (_("Hard limit : %s") % pqentry.HardLimit) |
| 288 | print " %s" % (_("Date limit : %s") % pqentry.DateLimit) |
| 289 | print " %s (Not supported yet)" % (_("Maximum job size : %s") % ((pqentry.MaxJobSize and (_("%s pages") % pqentry.MaxJobSize)) or _("Unlimited"))) |
| 290 | if hasattr(pqentry, "WarnCount") : |
| 291 | print " %s" % (_("Warning banners printed : %s") % pqentry.WarnCount) |
| 292 | print |
| 293 | else : |
| 294 | self.display("\n") |
| 295 | nbtotal = len(pqentries) |
| 296 | if nbtotal : |
| 297 | self.display("%s...\n" % _("Modification")) |
| 298 | i = 0 |
| 299 | for pqentry in pqentries : |
| 300 | ename = getattr(pqentry, suffix).Name |
| 301 | pname = pqentry.Printer.Name |
| 302 | if pqentry.Exists : |
| 303 | if noquota or ((softlimit is not None) and (hardlimit is not None)) : |
| 304 | pqentry.setLimits(softlimit, hardlimit) |