root / pykota / trunk / bin / warnpykota @ 772

Revision 772, 5.3 kB (checked in by jalet, 21 years ago)

Internationalization begins...

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