root / pykota / trunk / bin / warnpykota @ 873

Revision 873, 6.2 kB (checked in by jalet, 21 years ago)

GPL paragraphs were incorrectly (from memory) copied into the sources.
Two README files were added.
Upgrade script for PostgreSQL pre 1.01 schema was added.

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