root / pykota / trunk / bin / repykota @ 823

Revision 814, 7.8 kB (checked in by jalet, 22 years ago)

Missing translation

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