[1144] | 1 | # PyKota |
---|
| 2 | # -*- coding: ISO-8859-15 -*- |
---|
[1048] | 3 | |
---|
| 4 | # PyKota - Print Quotas for CUPS and LPRng |
---|
| 5 | # |
---|
| 6 | # (c) 2003 Jerome Alet <alet@librelogiciel.com> |
---|
| 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$ |
---|
[1235] | 24 | # Revision 1.6 2003/12/02 14:40:21 jalet |
---|
| 25 | # Some code refactoring. |
---|
| 26 | # New HTML reporter added, which is now used in the CGI script for web based |
---|
| 27 | # print quota reports. It will need some de-uglyfication though... |
---|
| 28 | # |
---|
[1144] | 29 | # Revision 1.5 2003/10/07 09:07:29 jalet |
---|
| 30 | # Character encoding added to please latest version of Python |
---|
| 31 | # |
---|
[1068] | 32 | # Revision 1.4 2003/07/07 11:49:24 jalet |
---|
| 33 | # Lots of small fixes with the help of PyChecker |
---|
| 34 | # |
---|
[1062] | 35 | # Revision 1.3 2003/07/05 07:46:50 jalet |
---|
| 36 | # The previous bug fix was incomplete. |
---|
| 37 | # |
---|
[1056] | 38 | # Revision 1.2 2003/07/02 09:29:12 jalet |
---|
| 39 | # Bug fixed when wanting a report and an user/group was limited by account balance |
---|
| 40 | # |
---|
[1048] | 41 | # Revision 1.1 2003/06/30 12:46:15 jalet |
---|
| 42 | # Extracted reporting code. |
---|
| 43 | # |
---|
| 44 | # |
---|
| 45 | # |
---|
| 46 | |
---|
| 47 | from mx import DateTime |
---|
| 48 | |
---|
| 49 | from pykota.reporter import BaseReporter, PyKotaReporterError |
---|
| 50 | |
---|
| 51 | class Reporter(BaseReporter) : |
---|
[1235] | 52 | """Text reporter.""" |
---|
[1048] | 53 | def generateReport(self) : |
---|
| 54 | """Produces a simple text report.""" |
---|
| 55 | self.report = [] |
---|
| 56 | for printer in self.printers : |
---|
[1235] | 57 | self.report.append(self.getPrinterTitle(printer)) |
---|
| 58 | self.report.append(self.getPrinterGraceDelay(printer)) |
---|
| 59 | (pjob, ppage) = self.getPrinterPrices(printer) |
---|
| 60 | self.report.append(pjob) |
---|
| 61 | self.report.append(ppage) |
---|
| 62 | |
---|
[1048] | 63 | total = 0 |
---|
| 64 | totalmoney = 0.0 |
---|
| 65 | if self.isgroup : |
---|
[1235] | 66 | header = self.getReportHeader() |
---|
| 67 | self.report.append(header) |
---|
| 68 | self.report.append('-' * len(header)) |
---|
[1048] | 69 | for (group, grouppquota) in self.tool.storage.getPrinterGroupsAndQuotas(printer, self.ugnames) : |
---|
[1235] | 70 | (pages, money, name, reached, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid) = self.getQuota(group, grouppquota) |
---|
| 71 | self.report.append("%-9.9s %s %7i %7s %7s %10s %-10.10s %8i %10s" % (name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid)) |
---|
[1048] | 72 | total += pages |
---|
| 73 | totalmoney += money |
---|
| 74 | else : |
---|
| 75 | # default is user quota report |
---|
[1235] | 76 | header = self.getReportHeader() |
---|
| 77 | self.report.append(header) |
---|
| 78 | self.report.append('-' * len(header)) |
---|
[1048] | 79 | for (user, userpquota) in self.tool.storage.getPrinterUsersAndQuotas(printer, self.ugnames) : |
---|
[1235] | 80 | (pages, money, name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid) = self.getQuota(user, userpquota) |
---|
| 81 | self.report.append("%-9.9s %s %7i %7s %7s %10s %-10.10s %8i %10s" % (name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid)) |
---|
[1048] | 82 | total += pages |
---|
| 83 | totalmoney += money |
---|
| 84 | if total or totalmoney : |
---|
[1235] | 85 | (tpage, tmoney) = self.getTotals(total, totalmoney) |
---|
| 86 | self.report.append((" " * 50) + tpage + tmoney) |
---|
| 87 | self.report.append((" " * 51) + self.getPrinterRealPageCounter(printer)) |
---|
[1048] | 88 | self.report.append("") |
---|
| 89 | if self.isgroup : |
---|
| 90 | self.report.append(_("Totals may be inaccurate if some users are members of several groups.")) |
---|
| 91 | return "\n".join(self.report) |
---|
| 92 | |
---|