32 | | |
33 | | __doc__ = N_("""edpykota v%(__version__)s (c) %(__years__)s %(__author__)s |
34 | | |
35 | | A Print Quota editor for PyKota. |
36 | | |
37 | | command line usage : |
38 | | |
39 | | edpykota [options] user1 user2 ... userN |
40 | | |
41 | | edpykota [options] group1 group2 ... groupN |
42 | | |
43 | | options : |
44 | | |
45 | | -v | --version Prints edpykota's version number then exits. |
46 | | -h | --help Prints this message then exits. |
47 | | |
48 | | -a | --add Adds users or groups print quota entries if |
49 | | they don't exist in database. |
50 | | |
51 | | -d | --delete Deletes users or groups print quota entries. |
52 | | Users or groups are never deleted, you have |
53 | | to use the pkusers command to delete them. |
54 | | The history will be purge from all matching |
55 | | jobs, unless -g | --groups is used. |
56 | | |
57 | | -P | --printer p Edit quotas on printer p only. Actually p can |
58 | | use wildcards characters to select only |
59 | | some printers. The default value is *, meaning |
60 | | all printers. |
61 | | You can specify several names or wildcards, |
62 | | by separating them with commas. |
63 | | |
64 | | -g | --groups Edit groups print quota entries instead of |
65 | | users print quota entries. |
66 | | |
67 | | -L | --list Lists users or groups print quota entries. |
68 | | |
69 | | -n | --noquota Sets both soft and hard limits to None for users |
70 | | or groups print quota entries. |
71 | | |
72 | | -r | --reset Resets the actual page counter for the user |
73 | | or group to zero on the specified printers. |
74 | | The life time page counter is kept unchanged. |
75 | | |
76 | | -R | --hardreset Resets the actual and life time page counters |
77 | | for the user or group to zero on the specified |
78 | | printers. This is a shortcut for '--used 0'. |
79 | | |
80 | | -s | --skipexisting In combination with the --add option above, tells |
81 | | edpykota to not modify existing print quota entries. |
82 | | |
83 | | -S | --softlimit sl Sets the quota soft limit to sl pages. |
84 | | |
85 | | -H | --hardlimit hl Sets the quota hard limit to hl pages. |
86 | | |
87 | | -I | --increase v Increase existing Soft and Hard limits by the value |
88 | | of v. You can prefix v with + or -, if no sign is |
89 | | used, + is assumed. |
90 | | |
91 | | -U | --used u Sets the page counters for the user u pages on |
92 | | the selected printers. Doesn't work for groups, since |
93 | | their page counters are the sum of all their members' |
94 | | page counters. |
95 | | Useful for migrating users from a different system |
96 | | where they have already used some pages. Actual |
97 | | and Life Time page counters may be increased or decreased |
98 | | if u is prefixed with + or -. |
99 | | WARNING : BOTH page counters are modified in all cases, |
100 | | so be careful. |
101 | | NB : if u equals '0', then the action taken is |
102 | | the same as if --hardreset was used. |
103 | | |
104 | | user1 through userN and group1 through groupN can use wildcards |
105 | | if the --add option is not set. |
106 | | |
107 | | examples : |
108 | | |
109 | | $ edpykota --add john paul george ringo |
110 | | |
111 | | This will create print quota entries for users john, paul, george |
112 | | and ringo on all printers. These print quota entries will have no |
113 | | limit set. |
114 | | |
115 | | $ edpykota --printer lp -S 50 -H 60 jerome |
116 | | |
117 | | This will set jerome's print quota on the lp printer to a soft limit |
118 | | of 50 pages, and a hard limit of 60 pages. Both user jerome and |
119 | | printer lp have been previously created with the pkusers and pkprinters |
120 | | commands, respectively. |
121 | | |
122 | | $ edpykota -g -S 500 -H 550 financial support |
123 | | |
124 | | This will set print quota soft limit to 500 pages and hard limit |
125 | | to 550 pages for groups financial and support on all printers. |
126 | | |
127 | | $ edpykota --reset jerome "jo*" |
128 | | |
129 | | This will reset jerome's page counter to zero on all printers, as |
130 | | well as every user whose name begins with 'jo'. |
131 | | Their life time page counter on each printer will be kept unchanged. |
132 | | You can also reset the life time page counters by using the |
133 | | --hardreset | -R command line option. |
134 | | |
135 | | $ edpykota --printer hpcolor --noquota jerome |
136 | | |
137 | | This will tell PyKota to not limit jerome when printing on the |
138 | | hpcolor printer. All his jobs will be allowed on this printer, but |
139 | | accounting of the pages he prints will still be kept. |
140 | | Print Quotas for jerome on other printers are unchanged. |
141 | | |
142 | | $ edpykota --delete --printer "HP*,XER*" jerome rachel |
143 | | |
144 | | This will delete users jerome and rachel's print quota |
145 | | entries on all printers which name begin with 'HP' or |
146 | | 'XER'. The jobs printed by these users on these printers |
147 | | will be deleted from the history. |
148 | | """) |
306 | | retcode = 0 |
307 | | try : |
308 | | defaults = { \ |
309 | | "printer" : "*", \ |
310 | | } |
311 | | short_options = "vhdnagrLP:S:H:G:RU:I:s" |
312 | | long_options = ["help", "version", \ |
313 | | "delete", "list", \ |
314 | | "noquota", "add", \ |
315 | | "groups", "reset", "hardreset", \ |
316 | | "printer=", "softlimit=", "hardlimit=", \ |
317 | | "increase=", "used=", "skipexisting"] |
318 | | |
319 | | # Initializes the command line tool |
320 | | manager = EdPyKota(doc=__doc__) |
321 | | manager.deferredInit() |
322 | | |
323 | | # parse and checks the command line |
324 | | (options, args) = manager.parseCommandline(sys.argv[1:], short_options, long_options) |
325 | | |
326 | | # sets long options |
327 | | options["help"] = options["h"] or options["help"] |
328 | | options["version"] = options["v"] or options["version"] |
329 | | options["add"] = options["a"] or options["add"] |
330 | | options["groups"] = options["g"] or options["groups"] |
331 | | options["printer"] = options["P"] or options["printer"] or defaults["printer"] |
332 | | options["softlimit"] = options["S"] or options["softlimit"] |
333 | | options["hardlimit"] = options["H"] or options["hardlimit"] |
334 | | options["reset"] = options["r"] or options["reset"] |
335 | | options["noquota"] = options["n"] or options["noquota"] |
336 | | options["delete"] = options["d"] or options["delete"] |
337 | | options["hardreset"] = options["R"] or options["hardreset"] |
338 | | options["used"] = options["U"] or options["used"] |
339 | | options["increase"] = options["I"] or options["increase"] |
340 | | options["list"] = options["L"] or options["list"] |
341 | | options["skipexisting"] = options["s"] or options["skipexisting"] |
342 | | |
343 | | if options["help"] : |
344 | | manager.display_usage_and_quit() |
345 | | elif options["version"] : |
346 | | manager.display_version_and_quit() |
347 | | elif (options["add"] and options["delete"]) \ |
348 | | or (options["noquota"] and (options["hardlimit"] or options["softlimit"])) \ |
349 | | or (options["groups"] and options["used"]) \ |
350 | | or (options["skipexisting"] and not options["add"]) : |
351 | | raise PyKotaCommandLineError, _("incompatible options, see help.") |
352 | | elif options["delete"] and not args : |
353 | | raise PyKotaCommandLineError, _("You have to pass user or group names on the command line") |
354 | | else : |
355 | | retcode = manager.main(args, options) |
356 | | except KeyboardInterrupt : |
357 | | logerr("\nInterrupted with Ctrl+C !\n") |
358 | | retcode = -3 |
359 | | except PyKotaCommandLineError, msg : |
360 | | logerr("%s : %s\n" % (sys.argv[0], msg)) |
361 | | retcode = -2 |
362 | | except SystemExit : |
363 | | pass |
364 | | except : |
365 | | try : |
366 | | manager.crashed("edpykota failed") |
367 | | except : |
368 | | crashed("edpykota failed") |
369 | | retcode = -1 |
370 | | |
371 | | try : |
372 | | manager.storage.close() |
373 | | except (TypeError, NameError, AttributeError) : |
374 | | pass |
375 | | |
376 | | sys.exit(retcode) |
| 234 | parser = PyKotaOptionParser(description=_("Manages PyKota print quota entries for users or users groups. A print quota entry is related to both an user and a printer, or to both a group and a printer, meaning that for example different users can have different page count limits on the same printer. If an user doesn't have a print quota entry on a particular printer, he won't be allowed to print to it."), |
| 235 | usage="edpykota [options] [usernames|groupnames]") |
| 236 | parser.add_option("-a", "--add", |
| 237 | action="store_const", |
| 238 | const="add", |
| 239 | dest="action", |
| 240 | help=_("Add new, or modify existing, users or groups print quota entries.")) |
| 241 | parser.add_option("-d", "--delete", |
| 242 | action="store_const", |
| 243 | const="delete", |
| 244 | dest="action", |
| 245 | help=_("Delete the specified users or groups print quota entries. When deleting users print quota entries, the matching jobs are also deleted from the printing history.")) |
| 246 | parser.add_option("-S", "--softlimit", |
| 247 | dest="softlimit", |
| 248 | help=_("Set the soft page count limit for the specified print quota entries. Users can print over this limit for a number of days specified in the 'gracedelay' directive in pykota.conf")) |
| 249 | parser.add_option("-H", "--hardlimit", |
| 250 | dest="hardlimit", |
| 251 | help=_("Set the hard page count limit for the specified print quota entries. Users are never allowed to print over this limit.")) |
| 252 | parser.add_option("-g", "--groups", |
| 253 | action="store_true", |
| 254 | dest="groups", |
| 255 | help=_("Manage groups print quota entries instead of users print quota entries.")) |
| 256 | parser.add_option("-I", "--increase", |
| 257 | dest="increase", |
| 258 | help=_("Increase the existing soft and hard page count limits for the specified print quota entries. You can decrease the values instead by prefixing this parameter with a negative sign.")) |
| 259 | parser.add_option("-L", "--list", |
| 260 | action="store_const", |
| 261 | const="list", |
| 262 | dest="action", |
| 263 | help=_("Display detailed informations about the specified users or groups print quota entries.")) |
| 264 | parser.add_option("-n", "--noquota", |
| 265 | dest="noquota", |
| 266 | action="store_true", |
| 267 | help=_("Set no limit for both soft and hard page counts for the specified users or groups print quota entries.")) |
| 268 | parser.add_option("-P", "--printer", |
| 269 | dest="printer", |
| 270 | default="*", |
| 271 | help=_("Specify a comma separated list of printers you want to manage print quota entries on. The default is '*', meaning all printers.")) |
| 272 | parser.add_option("-r", "--reset", |
| 273 | dest="reset", |
| 274 | action="store_true", |
| 275 | help=_("Reset the actual page counter for the specified users print quota entries (doesn't work for groups print quota entries). The life time page counter is left unchanged.")) |
| 276 | parser.add_option("-R", "--hardreset", |
| 277 | dest="hardreset", |
| 278 | action="store_true", |
| 279 | help=_("Reset the actual and life time page counters for the specified users print quota entries (doesn't work for groups print quota entries). This is a shortcut for --used 0.")) |
| 280 | parser.add_option("-s", "--skipexisting", |
| 281 | action="store_true", |
| 282 | dest="skipexisting", |
| 283 | help=_("If --add is used, ensure that existing users or groups print quota entries won't be modified.")) |
| 284 | parser.add_option("-U", "--used", |
| 285 | dest="used", |
| 286 | help=_("Set the values of both the actual and life time page counters for the specified users print quota entries (doesn't work for groups print quota entries). This can be useful when migrating from a different print quota software. The values can also be increased or decreased by prefixing this parameter with either a positive or negative sign.")) |
| 287 | |
| 288 | parser.add_example("--add john paul george ringo", |
| 289 | _("Would create print quota entries with no page count limits for these four users on all existing printers.")) |
| 290 | parser.add_example("--printer HP --softlimit 50 --hardlimit 60 jerome", |
| 291 | _("Would allow user 'jerome' to print up to 60 pages on printer 'HP'. This user would be warned when he would have reached 50 pages on this printer. Both the user and printer must have been created previously using the pkusers and pkprinters commands, respectively.")) |
| 292 | parser.add_example("--groups --softlimit 500 --hardlimit 600 support financial", |
| 293 | _("Would set soft and hard page count limits on any printer for groups 'support' and 'financial'.")) |
| 294 | parser.add_example('--reset --printer HP jerome "jo*"', |
| 295 | _("Would reset the actual page counter for users 'jerome' and all users whose name begins with 'jo' on printer 'HP'.")) |
| 296 | parser.add_example("--printer HPCOLOR --noquota jerome", |
| 297 | _("Would allow this user to print without any page limit on printer 'HPCOLOR'. Depending on how this user is limited, he may still be subject to being limited by the number of available credits in his account.")) |
| 298 | parser.add_example("--add --skipexisting", |
| 299 | _("Would create a print quota entry for each user on each printer for which none already existed. You'll most likely want to use this command at least once after initial setup.")) |
| 300 | run(parser, EdPyKota) |