root / pykota / trunk / bin / warnpykota @ 822

Revision 791, 5.5 kB (checked in by jalet, 22 years ago)

Now repykota should output the recorded total page number for each printer too.

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