[1144] | 1 | # PyKota |
---|
| 2 | # -*- coding: ISO-8859-15 -*- |
---|
[1048] | 3 | |
---|
| 4 | # PyKota - Print Quotas for CUPS and LPRng |
---|
| 5 | # |
---|
[1257] | 6 | # (c) 2003-2004 Jerome Alet <alet@librelogiciel.com> |
---|
[1048] | 7 | # This program is free software; you can redistribute it and/or modify |
---|
| 8 | # it under the terms of the GNU General Public License as published by |
---|
| 9 | # the Free Software Foundation; either version 2 of the License, or |
---|
| 10 | # (at your option) any later version. |
---|
| 11 | # |
---|
| 12 | # This program is distributed in the hope that it will be useful, |
---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | # GNU General Public License for more details. |
---|
| 16 | # |
---|
| 17 | # You should have received a copy of the GNU General Public License |
---|
| 18 | # along with this program; if not, write to the Free Software |
---|
| 19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
---|
| 20 | # |
---|
| 21 | # $Id$ |
---|
| 22 | # |
---|
| 23 | # $Log$ |
---|
[2054] | 24 | # Revision 1.10 2005/02/13 22:02:29 jalet |
---|
| 25 | # Big database structure changes. Upgrade script is now included as well as |
---|
| 26 | # the new LDAP schema. |
---|
| 27 | # Introduction of the -o | --overcharge command line option to edpykota. |
---|
| 28 | # The output of repykota is more complete, but doesn't fit in 80 columns anymore. |
---|
| 29 | # Introduction of the new 'maxdenybanners' directive. |
---|
| 30 | # |
---|
[1257] | 31 | # Revision 1.9 2004/01/08 14:10:33 jalet |
---|
| 32 | # Copyright year changed. |
---|
| 33 | # |
---|
[1251] | 34 | # Revision 1.8 2004/01/06 15:51:46 jalet |
---|
| 35 | # Code factorization |
---|
| 36 | # |
---|
[1240] | 37 | # Revision 1.7 2003/12/27 16:49:25 uid67467 |
---|
| 38 | # Should be ok now. |
---|
| 39 | # |
---|
[1235] | 40 | # Revision 1.6 2003/12/02 14:40:21 jalet |
---|
| 41 | # Some code refactoring. |
---|
| 42 | # New HTML reporter added, which is now used in the CGI script for web based |
---|
| 43 | # print quota reports. It will need some de-uglyfication though... |
---|
| 44 | # |
---|
[1144] | 45 | # Revision 1.5 2003/10/07 09:07:29 jalet |
---|
| 46 | # Character encoding added to please latest version of Python |
---|
| 47 | # |
---|
[1068] | 48 | # Revision 1.4 2003/07/07 11:49:24 jalet |
---|
| 49 | # Lots of small fixes with the help of PyChecker |
---|
| 50 | # |
---|
[1062] | 51 | # Revision 1.3 2003/07/05 07:46:50 jalet |
---|
| 52 | # The previous bug fix was incomplete. |
---|
| 53 | # |
---|
[1056] | 54 | # Revision 1.2 2003/07/02 09:29:12 jalet |
---|
| 55 | # Bug fixed when wanting a report and an user/group was limited by account balance |
---|
| 56 | # |
---|
[1048] | 57 | # Revision 1.1 2003/06/30 12:46:15 jalet |
---|
| 58 | # Extracted reporting code. |
---|
| 59 | # |
---|
| 60 | # |
---|
| 61 | # |
---|
| 62 | |
---|
| 63 | from pykota.reporter import BaseReporter, PyKotaReporterError |
---|
| 64 | |
---|
| 65 | class Reporter(BaseReporter) : |
---|
[1235] | 66 | """Text reporter.""" |
---|
[1048] | 67 | def generateReport(self) : |
---|
| 68 | """Produces a simple text report.""" |
---|
| 69 | self.report = [] |
---|
[1251] | 70 | if self.isgroup : |
---|
| 71 | prefix = "Group" |
---|
| 72 | else : |
---|
| 73 | prefix = "User" |
---|
[1048] | 74 | for printer in self.printers : |
---|
[1235] | 75 | self.report.append(self.getPrinterTitle(printer)) |
---|
| 76 | self.report.append(self.getPrinterGraceDelay(printer)) |
---|
| 77 | (pjob, ppage) = self.getPrinterPrices(printer) |
---|
| 78 | self.report.append(pjob) |
---|
| 79 | self.report.append(ppage) |
---|
| 80 | |
---|
[1048] | 81 | total = 0 |
---|
| 82 | totalmoney = 0.0 |
---|
[1251] | 83 | header = self.getReportHeader() |
---|
| 84 | self.report.append(header) |
---|
| 85 | self.report.append('-' * len(header)) |
---|
| 86 | for (entry, entrypquota) in getattr(self.tool.storage, "getPrinter%ssAndQuotas" % prefix)(printer, self.ugnames) : |
---|
[2054] | 87 | (pages, money, name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid, overcharge, warncount) = self.getQuota(entry, entrypquota) |
---|
| 88 | self.report.append("%-15.15s %s %5s %7i %7s %7s %10s %-10.10s %8i %10s %4s" % (name, reached, overcharge, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid, warncount)) |
---|
[1251] | 89 | total += pages |
---|
| 90 | totalmoney += money |
---|
| 91 | |
---|
[1048] | 92 | if total or totalmoney : |
---|
[1235] | 93 | (tpage, tmoney) = self.getTotals(total, totalmoney) |
---|
[2054] | 94 | self.report.append((" " * 62) + tpage + tmoney) |
---|
| 95 | self.report.append((" " * 63) + self.getPrinterRealPageCounter(printer)) |
---|
[1048] | 96 | self.report.append("") |
---|
| 97 | if self.isgroup : |
---|
| 98 | self.report.append(_("Totals may be inaccurate if some users are members of several groups.")) |
---|
| 99 | return "\n".join(self.report) |
---|
| 100 | |
---|