1 | #! /usr/bin/env python |
---|
2 | |
---|
3 | # PyKota Print Quota Editor |
---|
4 | # |
---|
5 | # PyKota - Print Quotas for CUPS |
---|
6 | # |
---|
7 | # (c) 2003 Jerome Alet <alet@librelogiciel.com> |
---|
8 | # You're welcome to redistribute this software under the |
---|
9 | # terms of the GNU General Public Licence version 2.0 |
---|
10 | # or, at your option, any higher version. |
---|
11 | # |
---|
12 | # You can read the complete GNU GPL in the file COPYING |
---|
13 | # which should come along with this software, or visit |
---|
14 | # the Free Software Foundation's WEB site http://www.fsf.org |
---|
15 | # |
---|
16 | # $Id$ |
---|
17 | # |
---|
18 | # $Log$ |
---|
19 | # Revision 1.3 2003/02/06 10:47:21 jalet |
---|
20 | # Documentation string and command line options didn't match. |
---|
21 | # |
---|
22 | # Revision 1.2 2003/02/06 10:39:23 jalet |
---|
23 | # Preliminary edpykota work. |
---|
24 | # |
---|
25 | # Revision 1.1 2003/02/05 21:41:09 jalet |
---|
26 | # Skeletons added for all command line tools |
---|
27 | # |
---|
28 | # |
---|
29 | # |
---|
30 | |
---|
31 | import sys |
---|
32 | |
---|
33 | from pykota import version |
---|
34 | from pykota.tool import PyKotaTool, PyKotaToolError |
---|
35 | |
---|
36 | __doc__ = """edpykota v%s (C) 2003 C@LL - Conseil Internet & Logiciels Libres |
---|
37 | A Print Quota editor for PyKota. |
---|
38 | |
---|
39 | command line usage : |
---|
40 | |
---|
41 | edpykota [options] user1 user2 ... userN |
---|
42 | edpykota [options] group1 group2 ... groupN |
---|
43 | |
---|
44 | options : |
---|
45 | |
---|
46 | -v | --version Prints edpykota's version number then exits. |
---|
47 | -h | --help Prints this message then exits. |
---|
48 | |
---|
49 | -a | --add Adds users and/or printers if they don't |
---|
50 | exist on the Quota Storage Server. |
---|
51 | |
---|
52 | -u | --users Edit users print quotas, this is the default. |
---|
53 | |
---|
54 | -P | --printer p Edit quotas on printer p only. |
---|
55 | |
---|
56 | -g | --groups Edit groups print quotas instead of users. |
---|
57 | |
---|
58 | -p | --prototype u|g Uses user u or group g as a prototype to set |
---|
59 | print quotas |
---|
60 | |
---|
61 | -S | --softlimit sl Sets the quota soft limit to sl pages. |
---|
62 | |
---|
63 | -H | --hardlimit hl Sets the quota hard limit to hl pages. |
---|
64 | |
---|
65 | examples : |
---|
66 | |
---|
67 | $ edpykota -p jerome john paul george ringo |
---|
68 | |
---|
69 | This will set print quotas for the users john, paul, george and ringo |
---|
70 | to the same values than user jerome. User jerome must exist. |
---|
71 | |
---|
72 | $ edpykota --printer lp -S 50 -H 60 jerome |
---|
73 | |
---|
74 | This will set jerome's print quota on the lp printer to a soft limit |
---|
75 | of 50 pages, and a hard limit of 60 pages. If either user jerome or |
---|
76 | printer lp doesn't exist on the Quota Storage Server then nothing is done. |
---|
77 | |
---|
78 | $ edpykota --add --printer lp -S 50 -H 60 jerome |
---|
79 | |
---|
80 | Same as above, but if either user jerome or printer lp doesn't exist |
---|
81 | on the Quota Storage Server they are automatically added. |
---|
82 | WARNING : the CUPS PPD file for this printer must still be modified |
---|
83 | manually, as well as pykota's configuration file for a |
---|
84 | new printer to be managed successfully. |
---|
85 | |
---|
86 | $ edpykota -g -S 500 -H 550 financial support |
---|
87 | |
---|
88 | This will set print quota soft limit to 500 pages and hard limit |
---|
89 | to 550 pages for groups financial and support on all printers. |
---|
90 | |
---|
91 | This program is free software; you can redistribute it and/or modify |
---|
92 | it under the terms of the GNU General Public License as published by |
---|
93 | the Free Software Foundation; either version 2 of the License, or |
---|
94 | (at your option) any later version. |
---|
95 | |
---|
96 | This program is distributed in the hope that it will be useful, |
---|
97 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
98 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
99 | GNU General Public License for more details. |
---|
100 | |
---|
101 | You should have received a copy of the GNU General Public License |
---|
102 | along with this program; if not, write to the Free Software |
---|
103 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
---|
104 | |
---|
105 | Please e-mail bugs to: %s""" % (version.__version__, version.__author__) |
---|
106 | |
---|
107 | def main(arguments, options) : |
---|
108 | """Edit user or group quotas.""" |
---|
109 | pass |
---|
110 | |
---|
111 | if __name__ == "__main__" : |
---|
112 | try : |
---|
113 | tool = PyKotaTool(doc=__doc__) |
---|
114 | |
---|
115 | defaults = { \ |
---|
116 | "users" : 1, \ |
---|
117 | "groups" : 0, \ |
---|
118 | } |
---|
119 | short_options = "vhaugp:P:S:H:" |
---|
120 | long_options = ["help", "version", "add", "users", "groups", "prototype=", "printer=", "softlimit=", "hardlimit="] |
---|
121 | |
---|
122 | # Initializes the command line tool |
---|
123 | tool = PyKotaTool(doc=__doc__) |
---|
124 | |
---|
125 | # parse and checks the command line |
---|
126 | (options, args) = tool.parseCommandline(sys.argv[1:], short_options, long_options) |
---|
127 | |
---|
128 | # sets long options |
---|
129 | options["help"] = options["h"] or options["help"] |
---|
130 | options["version"] = options["v"] or options["version"] |
---|
131 | options["add"] = options["a"] or options["add"] |
---|
132 | options["users"] = options["u"] or options["users"] or defaults["users"] |
---|
133 | options["groups"] = options["g"] or options["groups"] or defaults["groups"] |
---|
134 | options["prototype"] = options["p"] or options["prototype"] |
---|
135 | options["printer"] = options["P"] or options["printer"] |
---|
136 | options["softlimit"] = options["S"] or options["softlimit"] |
---|
137 | options["hardlimit"] = options["H"] or options["hardlimit"] |
---|
138 | |
---|
139 | if options["help"] : |
---|
140 | tool.display_usage_and_quit() |
---|
141 | elif options["version"] : |
---|
142 | tool.display_version_and_quit() |
---|
143 | elif options["users"] and options["groups"] : |
---|
144 | raise PyKotaToolError, "edpykota: options --users and --groups are incompatible.\n" |
---|
145 | elif options["groups"] : # TODO : add support for group quotas |
---|
146 | raise PyKotaToolError, "edpykota: group quotas are currently not implemented, sorry.\n" |
---|
147 | else : |
---|
148 | apply(main, args, options) |
---|
149 | except PyKotaToolError, msg : |
---|
150 | sys.stderr.write("%s\n" % msg) |
---|
151 | sys.stderr.flush() |
---|
152 | sys.exit(-1) |
---|