root / pykota / trunk / bin / warnpykota @ 869

Revision 866, 5.6 kB (checked in by jalet, 22 years ago)

Clearer help.

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