root / pykota / trunk / bin / repykota @ 793

Revision 793, 7.3 kB (checked in by jalet, 22 years ago)

Translations.

  • 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 Reports generator
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.11  2003/02/10 12:12:34  jalet
20# Translations.
21#
22# Revision 1.10  2003/02/10 12:07:30  jalet
23# Now repykota should output the recorded total page number for each printer too.
24#
25# Revision 1.9  2003/02/09 13:40:29  jalet
26# typo
27#
28# Revision 1.8  2003/02/09 12:56:53  jalet
29# Internationalization begins...
30#
31# Revision 1.7  2003/02/08 23:17:20  jalet
32# repykota now outputs life time page counters and the total pages printed by
33# all users/groups on each printer.
34#
35# Revision 1.6  2003/02/07 23:39:16  jalet
36# Typos
37#
38# Revision 1.5  2003/02/07 08:38:36  jalet
39# Missing conversion.
40# empty line between two printers
41#
42# Revision 1.4  2003/02/07 08:34:15  jalet
43# Test wrt date limit was wrong
44#
45# Revision 1.3  2003/02/07 00:08:52  jalet
46# Typos
47#
48# Revision 1.2  2003/02/06 23:58:05  jalet
49# repykota should be ok
50#
51#
52#
53
54import sys
55
56from mx import DateTime
57
58from pykota import version
59from pykota.tool import PyKotaTool, PyKotaToolError
60
61__doc__ = """repykota v%s (C) 2003 C@LL - Conseil Internet & Logiciels Libres
62
63Generates print quota reports.
64
65command line usage :
66
67  repykota [options]
68
69options :
70
71  -v | --version       Prints repykota's version number then exits.
72  -h | --help          Prints this message then exits.
73 
74  -u | --users         Generates a report on users quota, this is
75                       the default.
76 
77  -g | --groups        Generates a report on group quota instead of users.
78 
79  -P | --printer p     Report quotas on this printer only. Actually p can
80                       use wildcards characters to select only
81                       some printers. The default value is *, meaning
82                       all printers.
83 
84examples :                             
85
86  $ repykota --printer lp
87 
88  This will print the quota status for all users who use the lp printer.
89
90  $ repykota
91 
92  This will print the quota status for all users on all printers.
93
94This program is free software; you can redistribute it and/or modify
95it under the terms of the GNU General Public License as published by
96the Free Software Foundation; either version 2 of the License, or
97(at your option) any later version.
98
99This program is distributed in the hope that it will be useful,
100but WITHOUT ANY WARRANTY; without even the implied warranty of
101MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
102GNU General Public License for more details.
103
104You should have received a copy of the GNU General Public License
105along with this program; if not, write to the Free Software
106Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
107
108Please e-mail bugs to: %s""" % (version.__version__, version.__author__)
109       
110class RePyKota(PyKotaTool) :       
111    """A class for repykota."""
112    def main(self, options) :
113        """Print Quota reports generator."""
114        printernames = self.storage.getMatchingPrinters(options["printer"])
115        if not printernames :
116            raise PyKotaToolError, _("There's no printer matching %s") % options["printer"]
117        for (printer, printerpagecounter) in printernames :
118            print _("*** Report for %s quota on printer %s") % ((options["users"] and "user") or "group", printer)
119            print _("Pages grace time: %idays") % self.config.getGraceDelay()
120            total = 0
121            if options["users"] :
122                print _("User             used     soft     hard   grace        total")
123                print "------------------------------------------------------------"
124                for name in self.storage.getPrinterUsers(printer) :
125                    quota = self.storage.getUserPQuota(name, printer)
126                    total += self.printQuota(name, quota)
127            else :
128                print _("Group            used     soft     hard   grace        total")
129                print "------------------------------------------------------------"
130                for name in self.storage.getPrinterGroups(printer) :
131                    quota = self.storage.getGroupPQuota(name, printer) 
132                    total += self.printQuota(name, quota)
133            if total :       
134                print (" " * 43) + (_("Total : %9i") % total)
135            print (" " * 44) + (_("Real : %9i") % printerpagecounter)
136            print       
137                       
138    def printQuota(self, name, quota) :
139        """Prints the quota information."""
140        if quota is not None :
141            lifepagecounter = quota["lifepagecounter"]
142            pagecounter = quota["pagecounter"]
143            softlimit = quota["softlimit"] or 0
144            hardlimit = quota["hardlimit"] or 0
145            datelimit = quota["datelimit"]
146            if datelimit is not None :
147                now = DateTime.now()
148                datelimit = DateTime.ISO.ParseDateTime(datelimit)
149                if now >= datelimit :
150                    datelimit = "DENY"
151            else :   
152                datelimit = ""
153            reached = ((pagecounter >= softlimit) and "+") or "-"
154            print "%-10.10s %c %8i %8i %8i %10s %9i" % (name, reached, pagecounter, softlimit, hardlimit, str(datelimit)[:10], lifepagecounter)
155            return lifepagecounter
156       
157                   
158if __name__ == "__main__" : 
159    try :
160        defaults = { \
161                     "users"  : 1, \
162                     "groups" : 0, \
163                     "printer" : "*", \
164                   }
165        short_options = "vhugP:"
166        long_options = ["help", "version", "users", "groups", "printer="]
167       
168        # Initializes the command line tool
169        reporter = RePyKota(doc=__doc__)
170       
171        # parse and checks the command line
172        (options, args) = reporter.parseCommandline(sys.argv[1:], short_options, long_options, allownothing=1)
173       
174        # sets long options
175        options["help"] = options["h"] or options["help"]
176        options["version"] = options["v"] or options["version"]
177        options["users"] = options["u"] or options["users"] or defaults["users"]
178        options["groups"] = options["g"] or options["groups"] or defaults["groups"]
179        options["printer"] = options["P"] or options["printer"] or defaults["printer"]
180       
181        if options["help"] :
182            reporter.display_usage_and_quit()
183        elif options["version"] :
184            reporter.display_version_and_quit()
185        elif options["users"] and options["groups"] :   
186            raise PyKotaToolError, _("repykota: options --users and --groups are incompatible.")
187        elif options["groups"] :   
188            raise PyKotaToolError, _("repykota: option --groups is currently not implemented.")
189        elif args :   
190            raise PyKotaToolError, _("repykota: unused arguments [%s]. Aborting.") % ", ".join(args)
191        else :
192            sys.exit(reporter.main(options))
193    except PyKotaToolError, msg :           
194        sys.stderr.write("%s\n" % msg)
195        sys.stderr.flush()
196        sys.exit(-1)
Note: See TracBrowser for help on using the browser.