root / pykota / trunk / bin / warnpykota @ 890

Revision 890, 6.3 kB (checked in by jalet, 21 years ago)

Checks --groups option presence instead of --users because --users is the default.

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