root / pykota / trunk / bin / warnpykota @ 729

Revision 729, 5.1 kB (checked in by jalet, 21 years ago)

warnpykota doesn't need any user/group name argument, mimicing the
warnquota disk quota tool.

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