53 | | -d | --delete Deletes users/groups from the quota storage. |
54 | | Printers are never deleted. |
55 | | |
56 | | -c | --charge p[,j] Sets the price per page and per job to charge |
57 | | for a particular printer. Job price is optional. |
58 | | If both are to be set, separate them with a comma. |
59 | | Floating point values are allowed. |
60 | | |
61 | | -o | --overcharge f Sets the overcharging factor applied to the user |
62 | | when computing the cost of a print job. Positive or |
63 | | negative floating point values are allowed, |
64 | | this allows you to do some really creative |
65 | | things like giving money to an user whenever |
66 | | he prints. The number of pages in a print job |
67 | | is not modified by this coefficient, only the |
68 | | cost of the job for a particular user. |
69 | | Only users have a coefficient. |
70 | | |
71 | | -i | --ingroups g1[,g2...] Puts the users into each of the groups |
72 | | listed, separated by commas. The groups |
73 | | must already exist in the Quota Storage. |
74 | | |
75 | | -u | --users Edit users print quotas, this is the default. |
| 53 | -d | --delete Deletes users or groups print quota entries. |
| 54 | Users or groups are never deleted, you have |
| 55 | to use the pkusers command to delete them. |
84 | | -G | --pgroups pg1[,pg2...] Adds the printer(s) to the printer groups |
85 | | pg1, pg2, etc... which must already exist. |
86 | | A printer group is just like a normal printer, |
87 | | only that it is usually unknown from the printing |
88 | | system. Create printer groups exactly the same |
89 | | way that you create printers, then add other |
90 | | printers to them with this option. |
91 | | Accounting is done on a printer and on all |
92 | | the printer groups it belongs to, quota checking |
93 | | is done on a printer and on all the printer groups |
94 | | it belongs to. |
95 | | |
96 | | -g | --groups Edit users groups print quotas instead of users. |
| 64 | -g | --groups Edit groups print quota entries instead of |
| 65 | users print quota entries. |
115 | | -l | --limitby l Choose if the user/group is limited in printing |
116 | | by its account balance or by its page quota. |
117 | | The default value is 'quota'. Allowed values |
118 | | are 'quota' 'balance' 'noquota' 'noprint' |
119 | | and 'nochange' : |
120 | | |
121 | | - quota : limit by number of pages per printer. |
122 | | - balance : limit by number of credits in account. |
123 | | - noquota : no limit, accounting still done. |
124 | | - nochange : no limit, accounting not done. |
125 | | - noprint : printing is denied. |
126 | | NB : nochange and noprint are not supported for groups. |
127 | | |
128 | | -b | --balance b Sets the user's account balance to b. |
129 | | Account balance may be increase or decreased |
130 | | if b is prefixed with + or -. |
131 | | WARNING : when decreasing account balance, |
132 | | the total paid so far by the user is decreased |
133 | | too. |
134 | | Groups don't have a real balance, but the |
135 | | sum of their users' account balance. |
136 | | |
137 | | -C | --comment txt Defines some informational text to be associated |
138 | | with a change to an user's account balance. |
139 | | Only meaningful if -b | --balance is also used. |
140 | | |
164 | | $ edpykota --add -p jerome john paul george ringo/ringo@example.com |
165 | | |
166 | | This will add users john, paul, george and ringo to the quota |
167 | | database, and set their print quotas to the same values than user |
168 | | jerome. User jerome must already exist. |
169 | | User ringo's email address will also be set to 'ringo@example.com' |
| 104 | $ edpykota --add john paul george ringo |
| 105 | |
| 106 | This will create print quota entries for users john, paul, george |
| 107 | and ringo on all printers. These print quota entries will have no |
| 108 | limit set. |
174 | | of 50 pages, and a hard limit of 60 pages. If either user jerome or |
175 | | printer lp doesn't exist on the Quota Storage Server then nothing is done. |
176 | | |
177 | | $ edpykota --add --printer lp --ingroups coders,it -S 50 -H 60 jerome |
178 | | |
179 | | Same as above, but if either user jerome or printer lp doesn't exist |
180 | | on the Quota Storage Server they are automatically added. Also |
181 | | user jerome is put into the groups "coders" and "it" which must |
182 | | already exist in the Quota Storage. |
183 | | |
| 113 | of 50 pages, and a hard limit of 60 pages. Both user jerome and |
| 114 | printer lp have been previously created with the pkusers and pkprinters |
| 115 | commands, respectively. |
| 116 | |
204 | | $ edpykota --limitby balance jerome |
205 | | |
206 | | This will tell PyKota to limit jerome by his account's balance |
207 | | when printing. |
208 | | |
209 | | $ edpykota --balance +10.0 jerome |
210 | | |
211 | | This will increase jerome's account balance by 10.0 (in your |
212 | | own currency). You can decrease the account balance with a |
213 | | dash prefix, and set it to a fixed amount with no prefix. |
214 | | |
215 | | $ edpykota --delete jerome rachel |
216 | | |
217 | | This will completely delete jerome and rachel from the Quota Storage |
218 | | database. All their quotas and jobs will be deleted too. |
219 | | |
220 | | $ edpykota --printer lp --charge 0.1 |
221 | | |
222 | | This will set the page price for printer lp to 0.1. Job price |
223 | | will not be changed. |
224 | | |
225 | | $ edpykota --printer hplj1,hplj2 --pgroups Laser,HP |
226 | | |
227 | | This will put printers hplj1 and hplj2 in printers groups Laser and HP. |
228 | | When printing either on hplj1 or hplj2, print quota will also be |
229 | | checked and accounted for on virtual printers Laser and HP. |
230 | | |
231 | | $ edpykota --overcharge 2.5 poorstudent |
232 | | |
233 | | This will overcharge the poorstudent user by a factor of 2.5. |
234 | | |
235 | | $ edpykota --overcharge -1 jerome |
236 | | |
237 | | User jerome will actually earn money whenever he prints. |
238 | | |
239 | | $ edpykota --overcharge 0 boss |
240 | | |
241 | | User boss can print at will, it won't cost him anything because the |
242 | | cost of each print job will be multiplied by zero before charging |
243 | | his account. |
| 137 | $ edpykota --delete --printer "HP*,XER*" jerome rachel |
| 138 | |
| 139 | This will delete users jerome and rachel's print quota |
| 140 | entries on all printers which name begin with 'HP' or |
| 141 | 'XER'. The jobs printed by these users on these printers |
| 142 | will be deleted from the history. |
267 | | |
268 | | limitby = options["limitby"] |
269 | | if limitby : |
270 | | limitby = limitby.strip().lower() |
271 | | if limitby : |
272 | | if limitby not in ('quota', 'balance', 'noquota', \ |
273 | | 'noprint', 'nochange') : |
274 | | raise PyKotaCommandLineError, _("Invalid limitby value %s") % options["limitby"] |
275 | | if limitby in ('noquota', 'nochange') : |
276 | | options["noquota"] = 1 |
277 | | if (limitby in ('nochange', 'noprint')) and options["groups"] : |
278 | | raise PyKotaCommandLineError, _("Invalid limitby value %s") % options["limitby"] |
315 | | overcharge = options["overcharge"] |
316 | | if overcharge : |
317 | | try : |
318 | | overcharge = float(overcharge.strip()) |
319 | | except (ValueError, AttributeError) : |
320 | | raise PyKotaCommandLineError, _("Invalid overcharge value %s") % options["overcharge"] |
321 | | |
322 | | balance = options["balance"] |
323 | | if balance : |
324 | | balance = balance.strip() |
325 | | try : |
326 | | balancevalue = float(balance) |
327 | | except ValueError : |
328 | | raise PyKotaCommandLineError, _("Invalid balance value %s") % options["balance"] |
329 | | |
330 | | if options["charge"] : |
331 | | try : |
332 | | charges = [float(part) for part in options["charge"].split(',', 1)] |
333 | | except ValueError : |
334 | | raise PyKotaCommandLineError, _("Invalid charge amount value %s") % options["charge"] |
335 | | else : |
336 | | if len(charges) > 2 : |
337 | | charges = charges[:2] |
338 | | if len(charges) != 2 : |
339 | | charges = [charges[0], None] |
340 | | |
341 | | if options["ingroups"] : |
342 | | groupnames = [gname.strip() for gname in options["ingroups"].split(',')] |
343 | | else : |
344 | | groupnames = [] |
345 | | |
346 | | rejectunknown = self.config.getRejectUnknown() |
347 | | printeradded = 0 |
348 | | printers = self.storage.getMatchingPrinters(options["printer"]) |
349 | | if not printers : |
350 | | pname = options["printer"] |
351 | | if options["add"] and pname : |
352 | | if self.isValidName(pname) : |
353 | | printers = [ self.storage.addPrinter(pname) ] |
354 | | if printers[0].Exists : |
355 | | printeradded = 1 |
356 | | else : |
357 | | raise PyKotaToolError, _("Impossible to add printer %s") % pname |
358 | | else : |
359 | | raise PyKotaCommandLineError, _("Invalid printer name %s") % pname |
360 | | else : |
361 | | raise PyKotaCommandLineError, _("There's no printer matching %s") % pname |
362 | | if not names : |
363 | | names = getattr(self.storage, "getAll%ssNames" % suffix)() # all users or groups |
364 | | |
365 | | printersgroups = [] |
366 | | if options["pgroups"] : |
367 | | printersgroups = self.storage.getMatchingPrinters(options["pgroups"]) |
368 | | |
369 | | if options["prototype"] : |
370 | | protoentry = getattr(self.storage, "get%s" % suffix)(options["prototype"]) |
371 | | if not protoentry.Exists : |
372 | | raise PyKotaCommandLineError, _("Prototype object %s not found in Quota Storage.") % protoentry.Name |
373 | | else : |
374 | | limitby = protoentry.LimitBy |
375 | | balancevalue = protoentry.AccountBalance |
376 | | if balancevalue is not None : |
377 | | balance = str(abs(balancevalue)) |
378 | | else : |
379 | | balance = None |
380 | | overcharge = getattr(protoentry, "OverCharge", None) |
381 | | |
388 | | for pgroup in printersgroups : |
389 | | pgroup.addPrinterToGroup(printer) |
390 | | |
391 | | if options["charge"] : |
392 | | (perpage, perjob) = charges |
393 | | printer.setPrices(perpage, perjob) |
394 | | printer.save() |
395 | | |
396 | | if options["prototype"] : |
397 | | protoquota = getattr(self.storage, "get%sPQuota" % suffix)(protoentry, printer) |
398 | | if not protoquota.Exists : |
399 | | self.printInfo(_("Prototype %s not found in Quota Storage for printer %s.") % (protoentry.Name, printer.Name)) |
400 | | else : |
401 | | (softlimit, hardlimit) = (protoquota.SoftLimit, protoquota.HardLimit) |
402 | | |
448 | | if not entry.Exists : |
449 | | # not found |
450 | | if options["add"] : |
451 | | # In case we want to add something, it is crucial |
452 | | # that we DON'T check with the system accounts files |
453 | | # like /etc/passwd because users may be defined |
454 | | # only remotely |
455 | | if self.isValidName(entry.Name) : |
456 | | reject = 0 |
457 | | if rejectunknown : |
458 | | if options["groups"] : |
459 | | try : |
460 | | grp.getgrnam(entry.Name) |
461 | | except KeyError : |
462 | | self.printInfo(_("Unknown group %s") % entry.Name, "error") |
463 | | reject = 1 |
464 | | else : |
465 | | try : |
466 | | pwd.getpwnam(entry.Name) |
467 | | except KeyError : |
468 | | self.printInfo(_("Unknown user %s") % entry.Name, "error") |
469 | | reject = 1 |
470 | | if not reject : |
471 | | entry = getattr(self.storage, "add%s" % suffix)(entry) |
472 | | else : |
473 | | if options["groups"] : |
474 | | self.printInfo(_("Invalid group name %s") % entry.Name) |
475 | | else : |
476 | | self.printInfo(_("Invalid user name %s") % entry.Name) |
477 | | else : |
478 | | if options["groups"] : |
479 | | missinggroups[entry.Name] = 1 |
480 | | else : |
481 | | missingusers[entry.Name] = 1 |
482 | | |
520 | | if overcharge is not None : |
521 | | if changed[entry.Name].get("overcharge") is None : |
522 | | entry.setOverChargeFactor(overcharge) |
523 | | changed[entry.Name]["overcharge"] = overcharge |
524 | | |
525 | | if balance : |
526 | | if changed[entry.Name].get("balance") is None : |
527 | | if balance.startswith("+") or balance.startswith("-") : |
528 | | newbalance = float(entry.AccountBalance or 0.0) + balancevalue |
529 | | newlifetimepaid = float(entry.LifeTimePaid or 0.0) + balancevalue |
530 | | entry.setAccountBalance(newbalance, newlifetimepaid, options["comment"]) |
531 | | else : |
532 | | diff = balancevalue - float(entry.AccountBalance or 0.0) |
533 | | newlifetimepaid = float(entry.LifeTimePaid or 0.0) + diff |
534 | | entry.setAccountBalance(balancevalue, newlifetimepaid, options["comment"]) |
535 | | changed[entry.Name]["balance"] = balance |
536 | | |
537 | | for groupname in groupnames : |
538 | | # not executed if option --ingroups is not used |
539 | | if groupname not in changed[entry.Name]["ingroups"] : |
540 | | group = self.storage.getGroup(groupname) |
541 | | if group.Exists : |
542 | | self.storage.addUserToGroup(entry, group) |
543 | | changed[entry.Name]["ingroups"].append(groupname) |
544 | | else : |
545 | | self.printInfo(_("Group %s not found in the PyKota Storage.") % groupname) |
546 | | |
547 | | # Now outputs the list of nonexistent users and groups |
548 | | for name in missingusers.keys() : |
549 | | self.printInfo(_("Nonexistent user %s or missing print quota entry.") % name, level="warn") |
550 | | for name in missinggroups.keys() : |
551 | | self.printInfo(_("Nonexistent group %s or missing print quota entry.") % name, level="warn") |
552 | | |
563 | | short_options = "vhdo:c:C:l:b:i:naugrp:P:S:H:G:RU:I:" |
564 | | long_options = ["help", "version", "comment=", \ |
565 | | "overcharge=", "charge=", "delete", "limitby=", \ |
566 | | "balance=", "ingroups=", "noquota", "add", "users", \ |
567 | | "groups", "reset", "hardreset", "prototype=", \ |
568 | | "printer=", "softlimit=", "hardlimit=", "pgroups=", \ |
| 287 | short_options = "vhdnagrP:S:H:G:RU:I:" |
| 288 | long_options = ["help", "version", \ |
| 289 | "delete", \ |
| 290 | "noquota", "add", \ |
| 291 | "groups", "reset", "hardreset", \ |
| 292 | "printer=", "softlimit=", "hardlimit=", \ |
610 | | elif (options["reset"] or options["hardreset"] or options["limitby"] or options["used"] or options["balance"] or options["overcharge"] or options["softlimit"] or options["hardlimit"]) and options["prototype"] : |
611 | | raise PyKotaCommandLineError, _("incompatible options, see help.") |
612 | | elif options["noquota"] and (options["prototype"] or options["hardlimit"] or options["softlimit"]) : |
613 | | raise PyKotaCommandLineError, _("incompatible options, see help.") |
614 | | elif options["groups"] and (options["balance"] or options["ingroups"] or options["used"] or options["overcharge"]) : |
615 | | raise PyKotaCommandLineError, _("incompatible options, see help.") |
616 | | elif options["comment"] and not options["balance"] : |
| 325 | elif options["groups"] and options["used"] : |