175 | | increase = options["increase"] |
176 | | if increase : |
177 | | try : |
178 | | increase = int(increase.strip()) |
179 | | except ValueError : |
180 | | raise PyKotaCommandLineError, _("Invalid increase value %s.") % increase |
181 | | |
182 | | if not options["noquota"] : |
183 | | if options["softlimit"] : |
| 181 | if options["list"] : |
| 182 | for (name, entry) in pqentries.items() : |
| 183 | if entry.Exists : |
| 184 | print name |
| 185 | print " %s" % (_("Page counter : %s") % entry.PageCounter) |
| 186 | print " %s" % (_("Lifetime page counter : %s") % entry.LifePageCounter) |
| 187 | print " %s" % (_("Soft limit : %s") % entry.SoftLimit) |
| 188 | print " %s" % (_("Hard limit : %s") % entry.HardLimit) |
| 189 | print " %s" % (_("Date limit : %s") % entry.DateLimit) |
| 190 | # TODO : print " %s" % (_("Maximum job size : %s") % ((entry.MaxJobSize and (_("%s pages") % entry.MaxJobSize)) or _("Unlimited"))) |
| 191 | if hasattr(entry, "WarnCount") : |
| 192 | print " %s" % (_("Warning banners printed : %s") % entry.WarnCount) |
| 193 | print |
| 194 | else : |
| 195 | self.display("%s...\n" % _("Modification")) |
| 196 | raise PyKotaCommandLineError, "Not implemented yet." |
| 197 | softlimit = hardlimit = None |
| 198 | |
| 199 | used = options["used"] |
| 200 | if used : |
| 201 | used = used.strip() |
202 | | sys.stdout.write(_("Managing print quotas... (this may take a lot of time)")) |
203 | | sys.stdout.flush() |
204 | | missingusers = {} |
205 | | missinggroups = {} |
206 | | changed = {} # tracks changes made at the user/group level |
207 | | for printer in printers : |
208 | | if not options["noquota"] : |
209 | | if hardlimit is None : |
210 | | hardlimit = softlimit |
211 | | if hardlimit is not None : |
212 | | self.printInfo(_("Undefined hard limit set to soft limit (%s) on printer %s.") % (str(hardlimit), printer.Name)) |
213 | | if softlimit is None : |
214 | | softlimit = hardlimit |
215 | | if softlimit is not None : |
216 | | self.printInfo(_("Undefined soft limit set to hard limit (%s) on printer %s.") % (str(softlimit), printer.Name)) |
| 214 | if not options["noquota"] : |
| 215 | if options["softlimit"] : |
| 216 | try : |
| 217 | softlimit = int(options["softlimit"].strip()) |
| 218 | if softlimit < 0 : |
| 219 | raise ValueError |
| 220 | except ValueError : |
| 221 | raise PyKotaCommandLineError, _("Invalid softlimit value %s.") % options["softlimit"] |
| 222 | if options["hardlimit"] : |
| 223 | try : |
| 224 | hardlimit = int(options["hardlimit"].strip()) |
| 225 | if hardlimit < 0 : |
| 226 | raise ValueError |
| 227 | except ValueError : |
| 228 | raise PyKotaCommandLineError, _("Invalid hardlimit value %s.") % options["hardlimit"] |
| 229 | if (softlimit is not None) and (hardlimit is not None) and (hardlimit < softlimit) : |
| 230 | # error, exchange them |
| 231 | self.printInfo(_("Hard limit %i is less than soft limit %i, values will be exchanged.") % (hardlimit, softlimit)) |
| 232 | (softlimit, hardlimit) = (hardlimit, softlimit) |
| 233 | |
| 234 | sys.stdout.write(_("Managing print quotas... (this may take a lot of time)")) |
| 235 | sys.stdout.flush() |
| 236 | missingusers = {} |
| 237 | missinggroups = {} |
| 238 | changed = {} # tracks changes made at the user/group level |
| 239 | for printer in printers : |
| 240 | if not options["noquota"] : |
| 241 | if hardlimit is None : |
| 242 | hardlimit = softlimit |
| 243 | if hardlimit is not None : |
| 244 | self.printInfo(_("Undefined hard limit set to soft limit (%s) on printer %s.") % (str(hardlimit), printer.Name)) |
| 245 | if softlimit is None : |
| 246 | softlimit = hardlimit |
| 247 | if softlimit is not None : |
| 248 | self.printInfo(_("Undefined soft limit set to hard limit (%s) on printer %s.") % (str(softlimit), printer.Name)) |
| 249 | |
| 250 | if options["add"] : |
| 251 | allentries = [] |
| 252 | for name in names : |
| 253 | email = "" |
| 254 | if not options["groups"] : |
| 255 | splitname = name.split('/', 1) # username/email |
| 256 | if len(splitname) == 1 : |
| 257 | splitname.append("") |
| 258 | (name, email) = splitname |
| 259 | if email and (email.count('@') != 1) : |
| 260 | self.printInfo(_("Invalid email address %s") % email) |
| 261 | email = "" |
| 262 | entry = getattr(self.storage, "get%s" % suffix)(name) |
| 263 | if email and not options["groups"] : |
| 264 | entry.Email = email |
| 265 | entrypquota = getattr(self.storage, "get%sPQuota" % suffix)(entry, printer) |
| 266 | allentries.append((entry, entrypquota)) |
| 267 | else : |
| 268 | allentries = getattr(self.storage, "getPrinter%ssAndQuotas" % suffix)(printer, names) |
| 269 | |
| 270 | for (entry, entrypquota) in allentries : |
| 271 | if not changed.has_key(entry.Name) : |
| 272 | changed[entry.Name] = {} |
| 273 | if not options["groups"] : |
| 274 | changed[entry.Name]["ingroups"] = [] |
| 275 | |
| 276 | if entry.Exists and (not entrypquota.Exists) : |
| 277 | # not found |
| 278 | if options["add"] : |
| 279 | entrypquota = getattr(self.storage, "add%sPQuota" % suffix)(entry, printer) |
| 280 | |
| 281 | if not entrypquota.Exists : |
| 282 | self.printInfo(_("Quota not found for object %s on printer %s.") % (entry.Name, printer.Name)) |
| 283 | else : |
| 284 | if options["noquota"] \ |
| 285 | or ((softlimit is not None) and (hardlimit is not None)) : |
| 286 | entrypquota.setLimits(softlimit, hardlimit) |
| 287 | |
| 288 | if increase : |
| 289 | if (entrypquota.SoftLimit is None) \ |
| 290 | or (entrypquota.HardLimit is None) : |
| 291 | self.printInfo(_("You can't increase limits by %s when no limit is set.") % increase, "error") |
| 292 | else : |
| 293 | newsoft = entrypquota.SoftLimit + increase |
| 294 | newhard = entrypquota.HardLimit + increase |
| 295 | if (newsoft >= 0) and (newhard >= 0) : |
| 296 | entrypquota.setLimits(newsoft, newhard) |
| 297 | else : |
| 298 | self.printInfo(_("You can't set negative limits."), "error") |
218 | | if options["add"] : |
219 | | allentries = [] |
220 | | for name in names : |
221 | | email = "" |
222 | | if not options["groups"] : |
223 | | splitname = name.split('/', 1) # username/email |
224 | | if len(splitname) == 1 : |
225 | | splitname.append("") |
226 | | (name, email) = splitname |
227 | | if email and (email.count('@') != 1) : |
228 | | self.printInfo(_("Invalid email address %s") % email) |
229 | | email = "" |
230 | | entry = getattr(self.storage, "get%s" % suffix)(name) |
231 | | if email and not options["groups"] : |
232 | | entry.Email = email |
233 | | entrypquota = getattr(self.storage, "get%sPQuota" % suffix)(entry, printer) |
234 | | allentries.append((entry, entrypquota)) |
235 | | else : |
236 | | allentries = getattr(self.storage, "getPrinter%ssAndQuotas" % suffix)(printer, names) |
237 | | |
238 | | for (entry, entrypquota) in allentries : |
239 | | if not changed.has_key(entry.Name) : |
240 | | changed[entry.Name] = {} |
241 | | if not options["groups"] : |
242 | | changed[entry.Name]["ingroups"] = [] |
243 | | |
244 | | if entry.Exists and (not entrypquota.Exists) : |
245 | | # not found |
246 | | if options["add"] : |
247 | | entrypquota = getattr(self.storage, "add%sPQuota" % suffix)(entry, printer) |
248 | | |
249 | | if not entrypquota.Exists : |
250 | | self.printInfo(_("Quota not found for object %s on printer %s.") % (entry.Name, printer.Name)) |
251 | | else : |
252 | | if options["noquota"] \ |
253 | | or ((softlimit is not None) and (hardlimit is not None)) : |
254 | | entrypquota.setLimits(softlimit, hardlimit) |
255 | | |
256 | | if increase : |
257 | | if (entrypquota.SoftLimit is None) \ |
258 | | or (entrypquota.HardLimit is None) : |
259 | | self.printInfo(_("You can't increase limits by %s when no limit is set.") % increase, "error") |
260 | | else : |
261 | | newsoft = entrypquota.SoftLimit + increase |
262 | | newhard = entrypquota.HardLimit + increase |
263 | | if (newsoft >= 0) and (newhard >= 0) : |
264 | | entrypquota.setLimits(newsoft, newhard) |
265 | | else : |
266 | | self.printInfo(_("You can't set negative limits."), "error") |
267 | | |
268 | | if options["reset"] : |
269 | | entrypquota.reset() |
270 | | |
271 | | if options["hardreset"] : |
272 | | entrypquota.hardreset() |
273 | | |
274 | | if not options["groups"] : |
275 | | if used : |
276 | | entrypquota.setUsage(used) |
277 | | |
278 | | sys.stdout.write("\nDone.\n") |
| 300 | if options["reset"] : |
| 301 | entrypquota.reset() |
| 302 | |
| 303 | if options["hardreset"] : |
| 304 | entrypquota.hardreset() |
| 305 | |
| 306 | if not options["groups"] : |
| 307 | if used : |
| 308 | entrypquota.setUsage(used) |
| 309 | |
| 310 | if not options["list"] : |
| 311 | self.display("\r100.00%%\r \r%s\n" % _("Done.")) |