root / pykota / trunk / bin / warnpykota @ 945

Revision 934, 6.4 kB (checked in by jalet, 22 years ago)

bad documentation string

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
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# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21#
22# $Id$
23#
24# $Log$
25# Revision 1.17  2003/04/17 13:32:17  jalet
26# bad documentation string
27#
28# Revision 1.16  2003/04/16 12:35:49  jalet
29# Groups quota work now !
30#
31# Revision 1.15  2003/04/10 21:47:20  jalet
32# Job history added. Upgrade script neutralized for now !
33#
34# Revision 1.14  2003/04/08 21:31:39  jalet
35# (anything or 0) = anything !!! Go back to school Jerome !
36#
37# Revision 1.13  2003/04/08 21:13:44  jalet
38# Prepare --groups option to work.
39#
40# Revision 1.12  2003/04/08 21:10:18  jalet
41# Checks --groups option presence instead of --users because --users is the default.
42#
43# Revision 1.11  2003/03/29 13:45:27  jalet
44# GPL paragraphs were incorrectly (from memory) copied into the sources.
45# Two README files were added.
46# Upgrade script for PostgreSQL pre 1.01 schema was added.
47#
48# Revision 1.10  2003/03/25 11:45:32  jalet
49# Clearer help.
50#
51# Revision 1.9  2003/03/09 23:39:14  jalet
52# Simplified translations.
53#
54# Revision 1.8  2003/02/10 12:07:30  jalet
55# Now repykota should output the recorded total page number for each printer too.
56#
57# Revision 1.7  2003/02/09 13:40:29  jalet
58# typo
59#
60# Revision 1.6  2003/02/09 12:56:53  jalet
61# Internationalization begins...
62#
63# Revision 1.5  2003/02/07 23:24:38  jalet
64# Empty line deleted
65#
66# Revision 1.4  2003/02/06 23:25:40  jalet
67# Cleaner docstring
68#
69# Revision 1.3  2003/02/06 23:20:02  jalet
70# warnpykota doesn't need any user/group name argument, mimicing the
71# warnquota disk quota tool.
72#
73# Revision 1.2  2003/02/06 22:54:33  jalet
74# warnpykota should be ok
75#
76#
77#
78
79import sys
80
81from pykota import version
82from pykota.tool import PyKotaTool, PyKotaToolError
83
84__doc__ = """warnpykota v%s (C) 2003 C@LL - Conseil Internet & Logiciels Libres
85
86Sends mail to users over print quota.
87
88command line usage :
89
90  warnpykota [options]
91
92options :
93
94  -v | --version       Prints warnpykota's version number then exits.
95  -h | --help          Prints this message then exits.
96 
97  -u | --users         Warns users over their print quota, this is the
98                       default.
99 
100  -g | --groups        Warns users whose groups quota are over limit.
101 
102  -P | --printer p     Verify quotas on this printer only. Actually p can
103                       use wildcards characters to select only
104                       some printers. The default value is *, meaning
105                       all printers.
106 
107examples :                             
108
109  $ warnpykota --printer lp
110 
111  This will warn all users of the lp printer who have exceeded their
112  print quota.
113
114  $ warnpykota
115 
116  This will warn all users  who have exceeded their print quota on
117  any printer.
118
119  $ warnpykota --groups --printer "laserjet*"
120 
121  This will warn all users of groups which have exceeded
122  their print quota on any printer which name begins with "laserjet"
123
124This program is free software; you can redistribute it and/or modify
125it under the terms of the GNU General Public License as published by
126the Free Software Foundation; either version 2 of the License, or
127(at your option) any later version.
128
129This program is distributed in the hope that it will be useful,
130but WITHOUT ANY WARRANTY; without even the implied warranty of
131MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
132GNU General Public License for more details.
133
134You should have received a copy of the GNU General Public License
135along with this program; if not, write to the Free Software
136Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
137
138Please e-mail bugs to: %s""" % (version.__version__, version.__author__)
139       
140class WarnPyKota(PyKotaTool) :       
141    """A class for warnpykota."""
142    def main(self, options) :
143        """Warn users or groups over print quota."""
144        printers = self.storage.getMatchingPrinters(options["printer"])
145        if not printers :
146            raise PyKotaToolError, _("There's no printer matching %s") % options["printer"]
147        for (printerid, printer) in printers :
148            if options["groups"] :
149                for (ident, name) in self.storage.getPrinterGroups(printerid) :
150                    self.warnGroupPQuota(name, printer)
151            else :
152                for (ident, name) in self.storage.getPrinterUsers(printerid) :
153                    self.warnUserPQuota(name, printer)
154                     
155if __name__ == "__main__" : 
156    try :
157        defaults = { \
158                     "printer" : "*", \
159                   }
160        short_options = "vhugP:"
161        long_options = ["help", "version", "users", "groups", "printer="]
162       
163        # Initializes the command line tool
164        sender = WarnPyKota(doc=__doc__)
165       
166        # parse and checks the command line
167        (options, args) = sender.parseCommandline(sys.argv[1:], short_options, long_options, allownothing=1)
168       
169        # sets long options
170        options["help"] = options["h"] or options["help"]
171        options["version"] = options["v"] or options["version"]
172        options["users"] = options["u"] or options["users"]
173        options["groups"] = options["g"] or options["groups"]
174        options["printer"] = options["P"] or options["printer"] or defaults["printer"]
175       
176        if options["help"] :
177            sender.display_usage_and_quit()
178        elif options["version"] :
179            sender.display_version_and_quit()
180        elif options["users"] and options["groups"] :   
181            raise PyKotaToolError, _("incompatible options, see help.")
182        elif args :   
183            raise PyKotaToolError, _("unused arguments [%s]. Aborting.") % ", ".join(args)
184        else :
185            sys.exit(sender.main(options))
186    except PyKotaToolError, msg :           
187        sys.stderr.write("%s\n" % msg)
188        sys.stderr.flush()
189        sys.exit(-1)
Note: See TracBrowser for help on using the browser.