36 | | |
37 | | __doc__ = N_("""repykota v%(__version__)s (c) %(__years__)s %(__author__)s |
38 | | |
39 | | Generates print quota reports. |
40 | | |
41 | | command line usage : |
42 | | |
43 | | repykota [options] |
44 | | |
45 | | options : |
46 | | |
47 | | -v | --version Prints repykota's version number then exits. |
48 | | -h | --help Prints this message then exits. |
49 | | |
50 | | -u | --users Generates a report on users quota, this is |
51 | | the default. |
52 | | |
53 | | -g | --groups Generates a report on group quota instead of users. |
54 | | |
55 | | -i | --ingroups g1[,g2...] Only lists users who are members of these |
56 | | groups. Reserved to PyKota Administrators. |
57 | | |
58 | | -P | --printer p Report quotas on this printer only. Actually p can |
59 | | use wildcards characters to select only |
60 | | some printers. The default value is *, meaning |
61 | | all printers. |
62 | | You can specify several names or wildcards, |
63 | | by separating them with commas. |
64 | | |
65 | | examples : |
66 | | |
67 | | $ repykota --printer lp |
68 | | |
69 | | This will print the quota status for all users who use the lp printer. |
70 | | |
71 | | $ repykota |
72 | | |
73 | | This will print the quota status for all users on all printers. |
74 | | |
75 | | $ repykota --printer "laser*,*pson" jerome "jo*" |
76 | | |
77 | | This will print the quota status for user jerome and all users |
78 | | whose name begins with "jo" on all printers which name begins |
79 | | with "laser" or ends with "pson". |
80 | | |
81 | | If launched by an user who is not a PyKota administrator, additionnal |
82 | | arguments representing users or groups names are ignored, and only the |
83 | | current user/group is reported. |
84 | | """) |
130 | | retcode = 0 |
131 | | try : |
132 | | defaults = { \ |
133 | | "printer" : "*", \ |
134 | | } |
135 | | short_options = "vhugi:P:" |
136 | | long_options = ["help", "version", "users", "groups", "ingroups=", "printer="] |
137 | | |
138 | | # Initializes the command line tool |
139 | | reportTool = RePyKota(doc=__doc__) |
140 | | reportTool.deferredInit() |
141 | | |
142 | | # parse and checks the command line |
143 | | (options, args) = reportTool.parseCommandline(sys.argv[1:], short_options, long_options, allownothing=1) |
144 | | |
145 | | # sets long options |
146 | | options["help"] = options["h"] or options["help"] |
147 | | options["version"] = options["v"] or options["version"] |
148 | | options["users"] = options["u"] or options["users"] |
149 | | options["groups"] = options["g"] or options["groups"] |
150 | | options["printer"] = options["P"] or options["printer"] or defaults["printer"] |
151 | | options["ingroups"] = options["i"] or options["ingroups"] |
152 | | |
153 | | if options["help"] : |
154 | | reportTool.display_usage_and_quit() |
155 | | elif options["version"] : |
156 | | reportTool.display_version_and_quit() |
157 | | elif (options["users"] or options["ingroups"]) and options["groups"] : |
158 | | raise PyKotaCommandLineError, _("incompatible options, see help.") |
159 | | else : |
160 | | retcode = reportTool.main(args, options) |
161 | | except KeyboardInterrupt : |
162 | | logerr("\nInterrupted with Ctrl+C !\n") |
163 | | retcode = -3 |
164 | | except PyKotaCommandLineError, msg : |
165 | | logerr("%s : %s\n" % (sys.argv[0], msg)) |
166 | | retcode = -2 |
167 | | except SystemExit : |
168 | | pass |
169 | | except : |
170 | | try : |
171 | | reportTool.crashed("repykota failed") |
172 | | except : |
173 | | crashed("repykota failed") |
174 | | retcode = -1 |
175 | | |
176 | | try : |
177 | | reportTool.storage.close() |
178 | | except (TypeError, NameError, AttributeError) : |
179 | | pass |
180 | | |
181 | | sys.exit(retcode) |
| 86 | parser = PyKotaOptionParser(description=_("Minimalist print accounting reports for PyKota. If not launched by a PyKota administrator, additionnal arguments representing users or groups names are ignored, limiting the scope of the reports to the current user."), |
| 87 | usage="repykota [options] [usernames|groupnames]") |
| 88 | parser.add_option("-g", "--groups", |
| 89 | action="store_true", |
| 90 | dest="groups", |
| 91 | help=_("Generate group print quota reports instead of user print quota reports.")) |
| 92 | parser.add_option("-i", "--ingroups", |
| 93 | dest="ingroups", |
| 94 | help=_("Only reports users who are members of the specified groups. This option is reserved to PyKota administrators.")) |
| 95 | parser.add_option("-P", "--printer", |
| 96 | dest="printer", |
| 97 | default="*", |
| 98 | help=_("Reports for this printer only. You can specify several printer names by separating them with commas. The default value is '%default', which means all printers.")) |
| 99 | |
| 100 | parser.add_example('', |
| 101 | _("This would generate a report for all users on all printers.")) |
| 102 | parser.add_example('--printer HP2100', |
| 103 | _("This would generate a report for all users who print to printer 'HP2100'.")) |
| 104 | parser.add_example('--printer "laser*,*pson" jerome "jo*"', |
| 105 | _("This would generate a report for all users named 'jerome' or whose name begins with 'jo', on all printers which name begins with 'laser' or ends with 'pson'.")) |
| 106 | |
| 107 | run(parser, RePyKota) |