root / pykota / trunk / bin / repykota @ 842

Revision 842, 7.8 kB (checked in by jalet, 21 years ago)

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