[3489] | 1 | # -*- coding: utf-8 -*- |
---|
[1048] | 2 | # |
---|
[3260] | 3 | # PyKota : Print Quotas for CUPS |
---|
| 4 | # |
---|
[3561] | 5 | # (c) 2003-2013 Jerome Alet <alet@librelogiciel.com> |
---|
[3260] | 6 | # This program is free software: you can redistribute it and/or modify |
---|
[1048] | 7 | # it under the terms of the GNU General Public License as published by |
---|
[3260] | 8 | # the Free Software Foundation, either version 3 of the License, or |
---|
[1048] | 9 | # (at your option) any later version. |
---|
[3413] | 10 | # |
---|
[1048] | 11 | # This program is distributed in the hope that it will be useful, |
---|
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | # GNU General Public License for more details. |
---|
[3413] | 15 | # |
---|
[1048] | 16 | # You should have received a copy of the GNU General Public License |
---|
[3260] | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
[1048] | 18 | # |
---|
| 19 | # $Id$ |
---|
| 20 | # |
---|
[2054] | 21 | # |
---|
[1048] | 22 | |
---|
[3184] | 23 | """This module defines a class for plain text reporting.""" |
---|
| 24 | |
---|
[2830] | 25 | from pykota.reporter import BaseReporter |
---|
[3413] | 26 | |
---|
| 27 | class Reporter(BaseReporter) : |
---|
[1235] | 28 | """Text reporter.""" |
---|
[1048] | 29 | def generateReport(self) : |
---|
| 30 | """Produces a simple text report.""" |
---|
| 31 | self.report = [] |
---|
[1251] | 32 | if self.isgroup : |
---|
| 33 | prefix = "Group" |
---|
[3413] | 34 | else : |
---|
[1251] | 35 | prefix = "User" |
---|
[1048] | 36 | for printer in self.printers : |
---|
[1235] | 37 | self.report.append(self.getPrinterTitle(printer)) |
---|
| 38 | self.report.append(self.getPrinterGraceDelay(printer)) |
---|
| 39 | (pjob, ppage) = self.getPrinterPrices(printer) |
---|
| 40 | self.report.append(pjob) |
---|
| 41 | self.report.append(ppage) |
---|
[3413] | 42 | |
---|
[1048] | 43 | total = 0 |
---|
| 44 | totalmoney = 0.0 |
---|
[1251] | 45 | header = self.getReportHeader() |
---|
| 46 | self.report.append(header) |
---|
| 47 | self.report.append('-' * len(header)) |
---|
| 48 | for (entry, entrypquota) in getattr(self.tool.storage, "getPrinter%ssAndQuotas" % prefix)(printer, self.ugnames) : |
---|
[2054] | 49 | (pages, money, name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid, overcharge, warncount) = self.getQuota(entry, entrypquota) |
---|
| 50 | 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] | 51 | total += pages |
---|
| 52 | totalmoney += money |
---|
[3413] | 53 | |
---|
| 54 | if total or totalmoney : |
---|
[1235] | 55 | (tpage, tmoney) = self.getTotals(total, totalmoney) |
---|
[2054] | 56 | self.report.append((" " * 62) + tpage + tmoney) |
---|
| 57 | self.report.append((" " * 63) + self.getPrinterRealPageCounter(printer)) |
---|
[3413] | 58 | self.report.append("") |
---|
| 59 | if self.isgroup : |
---|
[1048] | 60 | self.report.append(_("Totals may be inaccurate if some users are members of several groups.")) |
---|
[3413] | 61 | return "\n".join(self.report) |
---|