1 | #! /usr/bin/env python |
---|
2 | |
---|
3 | # PyKota Print Quota Warning sender |
---|
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.2 2003/02/06 22:54:33 jalet |
---|
20 | # warnpykota should be ok |
---|
21 | # |
---|
22 | # |
---|
23 | # |
---|
24 | |
---|
25 | import sys |
---|
26 | |
---|
27 | from pykota import version |
---|
28 | from pykota.tool import PyKotaTool, PyKotaToolError |
---|
29 | |
---|
30 | __doc__ = """warnpykota v%s (C) 2003 C@LL - Conseil Internet & Logiciels Libres |
---|
31 | send mail to users over print quota |
---|
32 | |
---|
33 | command line usage : |
---|
34 | |
---|
35 | warnpykota [options] user1 user2 ... userN |
---|
36 | warnpykota [options] group1 group2 ... groupN |
---|
37 | |
---|
38 | options : |
---|
39 | |
---|
40 | -v | --version Prints warnpykota's version number then exits. |
---|
41 | -h | --help Prints this message then exits. |
---|
42 | |
---|
43 | -u | --users Send mail to users over print quota, this is |
---|
44 | the default. |
---|
45 | |
---|
46 | -g | --groups Send mail to group administrators instead of users. |
---|
47 | |
---|
48 | -P | --printer p Verify quotas on this printer only. Actually p can |
---|
49 | use wildcards characters to select only |
---|
50 | some printers. The default value is *, meaning |
---|
51 | all printers. |
---|
52 | |
---|
53 | examples : |
---|
54 | |
---|
55 | $ warnpykota --printer lp |
---|
56 | |
---|
57 | This will warn all users of the lp printer who have exceeded their |
---|
58 | print quota. |
---|
59 | |
---|
60 | $ warnpykota |
---|
61 | |
---|
62 | This will warn all users who have exceeded their print quota on |
---|
63 | any printer. |
---|
64 | |
---|
65 | $ warnpykota --groups --printer "laserjet*" |
---|
66 | |
---|
67 | This will warn all group administrators of groups which have exceeded |
---|
68 | their print quota on any printer which name begins with "laserjet" |
---|
69 | |
---|
70 | This program is free software; you can redistribute it and/or modify |
---|
71 | it under the terms of the GNU General Public License as published by |
---|
72 | the Free Software Foundation; either version 2 of the License, or |
---|
73 | (at your option) any later version. |
---|
74 | |
---|
75 | This program is distributed in the hope that it will be useful, |
---|
76 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
77 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
78 | GNU General Public License for more details. |
---|
79 | |
---|
80 | You should have received a copy of the GNU General Public License |
---|
81 | along with this program; if not, write to the Free Software |
---|
82 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
---|
83 | |
---|
84 | Please e-mail bugs to: %s""" % (version.__version__, version.__author__) |
---|
85 | |
---|
86 | class WarnPyKota(PyKotaTool) : |
---|
87 | """A class for warnpykota.""" |
---|
88 | def main(self, names, options) : |
---|
89 | """Warn users or groups over print quota.""" |
---|
90 | printernames = self.storage.getMatchingPrinters(options["printer"]) |
---|
91 | if not printernames : |
---|
92 | raise PyKotaToolError, "There's no printer matching %s" % options["printer"] |
---|
93 | for printer in printernames : |
---|
94 | for name in names : |
---|
95 | if options["users"] : |
---|
96 | self.warnUserPQuota(name, printer) |
---|
97 | else : |
---|
98 | self.warnGroupPQuota(name, printer) |
---|
99 | |
---|
100 | if __name__ == "__main__" : |
---|
101 | try : |
---|
102 | defaults = { \ |
---|
103 | "users" : 1, \ |
---|
104 | "groups" : 0, \ |
---|
105 | "printer" : "*", \ |
---|
106 | } |
---|
107 | short_options = "vhugP:" |
---|
108 | long_options = ["help", "version", "users", "groups", "printer="] |
---|
109 | |
---|
110 | # Initializes the command line tool |
---|
111 | sender = WarnPyKota(doc=__doc__) |
---|
112 | |
---|
113 | # parse and checks the command line |
---|
114 | (options, args) = sender.parseCommandline(sys.argv[1:], short_options, long_options) |
---|
115 | |
---|
116 | # sets long options |
---|
117 | options["help"] = options["h"] or options["help"] |
---|
118 | options["version"] = options["v"] or options["version"] |
---|
119 | options["users"] = options["u"] or options["users"] or defaults["users"] |
---|
120 | options["groups"] = options["g"] or options["groups"] or defaults["groups"] |
---|
121 | options["printer"] = options["P"] or options["printer"] or defaults["printer"] |
---|
122 | |
---|
123 | if options["help"] : |
---|
124 | sender.display_usage_and_quit() |
---|
125 | elif options["version"] : |
---|
126 | sender.display_version_and_quit() |
---|
127 | elif options["users"] and options["groups"] : |
---|
128 | raise PyKotaToolError, "warnpykota: options --users and --groups are incompatible." |
---|
129 | elif options["groups"] : |
---|
130 | raise PyKotaToolError, "warnpykota: options --groups is currently not implemented." |
---|
131 | else : |
---|
132 | sys.exit(sender.main(args, options)) |
---|
133 | except PyKotaToolError, msg : |
---|
134 | sys.stderr.write("%s\n" % msg) |
---|
135 | sys.stderr.flush() |
---|
136 | sys.exit(-1) |
---|