root / pykota / trunk / bin / warnpykota @ 895

Revision 895, 6.4 kB (checked in by jalet, 21 years ago)

(anything or 0) = anything !!! Go back to school Jerome !

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