Changeset 3413 for pykota/trunk/pykota/reporter.py
- Timestamp:
- 09/27/08 22:02:37 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/reporter.py
r3411 r3413 8 8 # the Free Software Foundation, either version 3 of the License, or 9 9 # (at your option) any later version. 10 # 10 # 11 11 # This program is distributed in the hope that it will be useful, 12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 # GNU General Public License for more details. 15 # 15 # 16 16 # You should have received a copy of the GNU General Public License 17 17 # along with this program. If not, see <http://www.gnu.org/licenses/>. … … 28 28 29 29 from pykota.errors import PyKotaReporterError 30 31 class BaseReporter : 30 31 class BaseReporter : 32 32 """Base class for all reports.""" 33 33 def __init__(self, tool, printers, ugnames, isgroup) : … … 37 37 self.ugnames = ugnames 38 38 self.isgroup = isgroup 39 40 def getPrinterTitle(self, printer) : 39 40 def getPrinterTitle(self, printer) : 41 41 """Returns the formatted title for a given printer.""" 42 42 return (_("Report for %s quota on printer %s") % ((self.isgroup and "group") or "user", printer.Name)) + (" (%s)" % printer.Description) 43 44 def getPrinterGraceDelay(self, printer) : 43 44 def getPrinterGraceDelay(self, printer) : 45 45 """Returns the formatted grace delay for a given printer.""" 46 46 return _("Pages grace time: %i days") % self.tool.config.getGraceDelay(printer.Name) 47 48 def getPrinterPrices(self, printer) : 47 48 def getPrinterPrices(self, printer) : 49 49 """Returns the formatted prices for a given printer.""" 50 50 return (_("Price per job: %.3f") % (printer.PricePerJob or 0.0), _("Price per page: %.3f") % (printer.PricePerPage or 0.0)) 51 52 def getReportHeader(self) : 51 52 def getReportHeader(self) : 53 53 """Returns the correct header depending on users vs users groups.""" 54 54 if self.isgroup : 55 55 return _("Group overcharge used soft hard balance grace total paid warn") 56 else : 56 else : 57 57 return _("User overcharge used soft hard balance grace total paid warn") 58 59 def getPrinterRealPageCounter(self, printer) : 58 59 def getPrinterRealPageCounter(self, printer) : 60 60 """Returns the formatted real page counter for a given printer.""" 61 61 msg = _("unknown") … … 63 63 try : 64 64 msg = "%9i" % printer.LastJob.PrinterPageCounter 65 except TypeError : 65 except TypeError : 66 66 pass 67 67 return _("Real : %s") % msg 68 69 def getTotals(self, total, totalmoney) : 68 69 def getTotals(self, total, totalmoney) : 70 70 """Returns the formatted totals.""" 71 71 return (_("Total : %9i") % (total or 0.0), ("%11s" % ("%7.2f" % (totalmoney or 0.0))[:11])) 72 72 73 73 def getQuota(self, entry, quota) : 74 74 """Prints the quota information.""" … … 79 79 if not hasattr(entry, "OverCharge") : 80 80 overcharge = _("N/A") # Not available for groups 81 else : 81 else : 82 82 overcharge = float(entry.OverCharge or 0.0) 83 if not hasattr(quota, "WarnCount") : 83 if not hasattr(quota, "WarnCount") : 84 84 warncount = _("N/A") # Not available for groups 85 else : 85 else : 86 86 warncount = int(quota.WarnCount or 0) 87 87 88 88 if (not entry.LimitBy) or (entry.LimitBy.lower() == "quota") : 89 if (quota.HardLimit is not None) and (pagecounter >= quota.HardLimit) : 89 if (quota.HardLimit is not None) and (pagecounter >= quota.HardLimit) : 90 90 datelimit = "DENY" 91 91 elif (quota.HardLimit is None) and (quota.SoftLimit is not None) and (pagecounter >= quota.SoftLimit) : … … 96 96 if now >= datelimit : 97 97 datelimit = "DENY" 98 else : 98 else : 99 99 datelimit = "" 100 100 reached = (((quota.SoftLimit is not None) and (pagecounter >= quota.SoftLimit) and "+") or "-") + "Q" … … 106 106 datelimit = "DENY" 107 107 reached = "+B" 108 else : 108 else : 109 109 # overcharging by a negative or nul factor means user is always allowed to print 110 110 # TODO : do something when printer prices are negative as well ! … … 117 117 datelimit = "WARNING" 118 118 reached = "?B" 119 else : 119 else : 120 120 datelimit = "" 121 121 reached = "-B" … … 130 130 reached = "NP" 131 131 datelimit = "DENY" 132 132 133 133 strbalance = ("%5.2f" % balance)[:10] 134 134 strlifetimepaid = ("%6.2f" % lifetimepaid)[:10] … … 139 139 strbalance, str(datelimit)[:10], lifepagecounter, \ 140 140 strlifetimepaid, strovercharge, strwarncount) 141 141 142 142 def openReporter(tool, reporttype, printers, ugnames, isgroup) : 143 143 """Returns a reporter instance of the proper reporter.""" 144 144 try : 145 reporterbackend = imp.load_source("reporterbackend", 145 reporterbackend = imp.load_source("reporterbackend", 146 146 os.path.join(os.path.dirname(__file__), 147 147 "reporters", … … 149 149 except ImportError : 150 150 raise PyKotaReporterError, _("Unsupported reporter backend %s") % reporttype 151 else : 151 else : 152 152 return reporterbackend.Reporter(tool, printers, ugnames, isgroup)