Changeset 1239
- Timestamp:
- 12/27/03 16:43:36 (21 years ago)
- Location:
- pykota/trunk
- Files:
-
- 13 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/cgi-bin/printquota.cgi
r1235 r1239 1 #! /usr/bin/python 1 #! /usr/bin/python2.2 2 2 3 3 # PyKota Print Quota Reports generator … … 23 23 # 24 24 # $Log$ 25 # Revision 1.17 2003/12/27 15:43:36 uid67467 26 # Savannah is back online... 27 # 25 28 # Revision 1.16 2003/12/02 14:40:20 jalet 26 29 # Some code refactoring. … … 91 94 <head> 92 95 <title>PyKota Reports</title> 96 <link rel="stylesheet" type="text/css" href="pykota.css" /> 93 97 </head> 94 98 <body> … … 104 108 </td> 105 109 <td colspan="2"> 106 <h 2>PyKota Reports</h2>110 <h1>PyKota Reports</h1> 107 111 </td> 108 112 </tr> -
pykota/trunk/NEWS
r1235 r1239 22 22 PyKota NEWS : 23 23 24 - 1.16alpah16 : 24 - 1.16alpha17 : 25 26 - Added portugues translation. 27 28 - Major code refactoring in accounters. 29 30 - 1.16alpha16 : 25 31 26 32 - Code refactoring, and addition of a real HTML reporter, to -
pykota/trunk/po/en/pykota.po
r1192 r1239 21 21 # 22 22 # $Log$ 23 # Revision 1.37 2003/12/27 15:43:36 uid67467 24 # Savannah is back online... 25 # 23 26 # Revision 1.36 2003/11/18 23:43:11 jalet 24 27 # Mailto can be any external command now, as usual. … … 206 209 msgstr "" 207 210 208 msgid " ***Report for %s quota on printer %s"211 msgid "Report for %s quota on printer %s" 209 212 msgstr "" 210 213 -
pykota/trunk/po/es/pykota.po
r1238 r1239 21 21 # 22 22 # $Log$ 23 # Revision 1.5 2003/12/27 15:43:36 uid67467 24 # Savannah is back online... 25 # 23 26 # Revision 1.4 2003/12/03 18:51:09 jalet 24 27 # Fixed spanish translation … … 91 94 msgstr "Impresora %s no encontrada" 92 95 93 msgid " ***Report for %s quota on printer %s"94 msgstr " ***Reporte para la cuota %s en la impresora %s"96 msgid "Report for %s quota on printer %s" 97 msgstr "Reporte para la cuota %s en la impresora %s" 95 98 96 99 msgid "Error in page count value %i for user %s on printer %s" -
pykota/trunk/po/fr/pykota.po
r1192 r1239 21 21 # 22 22 # $Log$ 23 # Revision 1.36 2003/12/27 15:43:36 uid67467 24 # Savannah is back online... 25 # 23 26 # Revision 1.35 2003/11/18 23:43:12 jalet 24 27 # Mailto can be any external command now, as usual. … … 209 212 msgstr "Aucune imprimante ne correspond �s" 210 213 211 msgid " ***Report for %s quota on printer %s"212 msgstr " ***Rapport pour le quota %s sur l'imprimante %s"214 msgid "Report for %s quota on printer %s" 215 msgstr "Rapport pour le quota %s sur l'imprimante %s" 213 216 214 217 msgid "Error in page count value %i for user %s on printer %s" -
pykota/trunk/po/pykota.pot
r1192 r1239 21 21 # 22 22 # $Log$ 23 # Revision 1.37 2003/12/27 15:43:36 uid67467 24 # Savannah is back online... 25 # 23 26 # Revision 1.36 2003/11/18 23:43:11 jalet 24 27 # Mailto can be any external command now, as usual. … … 206 209 msgstr "" 207 210 208 msgid " ***Report for %s quota on printer %s"211 msgid "Report for %s quota on printer %s" 209 212 msgstr "" 210 213 -
pykota/trunk/pykota/accounter.py
r1219 r1239 22 22 # 23 23 # $Log$ 24 # Revision 1.8 2003/12/27 15:43:36 uid67467 25 # Savannah is back online... 26 # 24 27 # Revision 1.7 2003/11/25 23:46:40 jalet 25 28 # Don't try to verify if module name is valid, Python does this better than us. … … 89 92 infile.close() 90 93 91 def doAccounting(self, printer, user) : 92 """Does the real accounting.""" 93 raise PyKotaAccounterError, "Accounter not implemented !" 94 def beginJob(self, printer, user) : 95 """Saves the computed job size.""" 96 # computes job's size 97 self.JobSize = self.computeJobSize() 98 99 # get last job information for this printer 100 if not printer.LastJob.Exists : 101 # The printer hasn't been used yet, from PyKota's point of view 102 self.LastPageCounter = 0 103 else : 104 # get last job size and page counter from Quota Storage 105 # Last lifetime page counter before actual job is 106 # last page counter + last job size 107 self.LastPageCounter = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0) 108 109 def endJob(self, printer, user) : 110 """Do nothing.""" 111 pass 112 113 def getJobSize(self) : 114 """Returns the actual job size.""" 115 try : 116 return self.JobSize 117 except AttributeError : 118 return 0 119 120 def doAccounting(self, printer, user) : 121 """Deletgates the computation of the job size to an external command. 122 123 The command must print the job size on its standard output and exit successfully. 124 """ 125 self.beginJob(printer, user) 126 127 # get the job size, which is real job size * number of copies. 128 jobsize = self.getJobSize() * self.filter.copies 129 130 # Is the current user allowed to print at all ? 131 userpquota = self.filter.storage.getUserPQuota(user, printer) 132 action = self.filter.warnUserPQuota(userpquota) 133 134 # update the quota for the current user on this printer, if allowed to print 135 if action == "DENY" : 136 jobsize = 0 137 else : 138 userpquota.increasePagesUsage(jobsize) 139 140 # adds the current job to history 141 jobprice = (float(printer.PricePerPage or 0.0) * jobsize) + float(printer.PricePerJob or 0.0) 142 printer.addJobToHistory(self.filter.jobid, user, self.getLastPageCounter(), action, jobsize, jobprice, self.filter.preserveinputfile, self.filter.title, self.filter.copies, self.filter.options) 143 self.endJob(printer, user) 144 return action 94 145 95 146 def openAccounter(kotafilter) : -
pykota/trunk/pykota/accounters/external.py
r1203 r1239 22 22 # 23 23 # $Log$ 24 # Revision 1.11 2003/12/27 15:43:36 uid67467 25 # Savannah is back online... 26 # 24 27 # Revision 1.10 2003/11/23 19:01:36 jalet 25 28 # Job price added to history … … 63 66 64 67 class Accounter(AccounterBase) : 65 def beginJob(self, printer, user) :66 """Saves the computed job size."""67 # computes job's size68 self.JobSize = self.computeJobSize()69 70 # get last job information for this printer71 if not printer.LastJob.Exists :72 # The printer hasn't been used yet, from PyKota's point of view73 self.LastPageCounter = 074 else :75 # get last job size and page counter from Quota Storage76 # Last lifetime page counter before actual job is77 # last page counter + last job size78 self.LastPageCounter = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0)79 80 def endJob(self, printer, user) :81 """Do nothing."""82 pass83 84 def getJobSize(self) :85 """Returns the actual job size."""86 try :87 return self.JobSize88 except AttributeError :89 return 090 91 def doAccounting(self, printer, user) :92 """Deletgates the computation of the job size to an external command.93 94 The command must print the job size on its standard output and exit successfully.95 """96 self.beginJob(printer, user)97 98 # get the job size, which is real job size * number of copies.99 jobsize = self.getJobSize() * self.filter.copies100 101 # Is the current user allowed to print at all ?102 userpquota = self.filter.storage.getUserPQuota(user, printer)103 action = self.filter.warnUserPQuota(userpquota)104 105 # update the quota for the current user on this printer, if allowed to print106 if action == "DENY" :107 jobsize = 0108 else :109 userpquota.increasePagesUsage(jobsize)110 111 # adds the current job to history112 jobprice = (float(printer.PricePerPage or 0.0) * jobsize) + float(printer.PricePerJob or 0.0)113 printer.addJobToHistory(self.filter.jobid, user, self.getLastPageCounter(), action, jobsize, jobprice, self.filter.preserveinputfile, self.filter.title, self.filter.copies, self.filter.options)114 115 self.endJob(printer, user)116 117 return action118 119 68 def computeJobSize(self) : 120 69 """Feeds an external command with our datas to let it compute the job size, and return its value.""" … … 181 130 else : 182 131 infile.close() 183 184 132 return pagecount 185 133 -
pykota/trunk/pykota/accounters/querying.py
r1200 r1239 22 22 # 23 23 # $Log$ 24 # Revision 1.9 2003/12/27 15:43:36 uid67467 25 # Savannah is back online... 26 # 24 27 # Revision 1.8 2003/11/21 14:28:46 jalet 25 28 # More complete job history. … … 182 185 # adds the current job to history 183 186 printer.addJobToHistory(self.filter.jobid, user, counterbeforejob, action, filename=self.filter.preserveinputfile, title=self.filter.title, copies=self.filter.copies, options=self.filter.options) 184 185 187 return action 186 188 -
pykota/trunk/pykota/accounters/stupid.py
r1203 r1239 22 22 # 23 23 # $Log$ 24 # Revision 1.9 2003/12/27 15:43:36 uid67467 25 # Savannah is back online... 26 # 24 27 # Revision 1.8 2003/11/23 19:01:37 jalet 25 28 # Job price added to history … … 55 58 56 59 class Accounter(AccounterBase) : 57 def beginJob(self) :58 """Saves the computed job size."""59 self.JobSize = self.computeJobSize()60 61 # get last job information for this printer62 if not printer.LastJob.Exists :63 # The printer hasn't been used yet, from PyKota's point of view64 self.LastPageCounter = 065 else :66 # get last job size and page counter from Quota Storage67 # Last lifetime page counter before actual job is68 # last page counter + last job size69 self.LastPageCounter = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0)70 71 def endJob(self) :72 """Do nothing."""73 pass74 75 def getJobSize(self) :76 """Returns the actual job size."""77 try :78 return self.JobSize79 except AttributeError :80 return 081 82 def doAccounting(self, printer, user) :83 """Does print accounting by stupidly counting the 'showpage' postscript instructions in the document.84 85 This method is essentially unreliable, but shows how to create a simple accounter.86 """87 # first we log a message because using this accounting method is not recommended.88 self.filter.logger.log_message(_("Using the 'stupid' accounting method is unreliable."), "warn")89 90 # get the job size91 jobsize = self.computeJobSize() * self.filter.copies92 93 # get last job information for this printer94 if not printer.LastJob.Exists :95 # The printer hasn't been used yet, from PyKota's point of view96 counterbeforejob = 097 else :98 # get last job size and page counter from Quota Storage99 # Last lifetime page counter before actual job is100 # last page counter + last job size101 counterbeforejob = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0)102 103 # Is the current user allowed to print at all ?104 userpquota = self.filter.storage.getUserPQuota(user, printer)105 action = self.filter.warnUserPQuota(userpquota)106 107 # update the quota for the current user on this printer, if allowed to print108 if action == "DENY" :109 jobsize = 0110 else :111 userpquota.increasePagesUsage(jobsize)112 113 # adds the current job to history114 jobprice = (float(printer.PricePerPage or 0.0) * jobsize) + float(printer.PricePerJob or 0.0)115 printer.addJobToHistory(self.filter.jobid, user, counterbeforejob, action, jobsize, jobprice, self.filter.preserveinputfile, self.filter.title, self.filter.copies, self.filter.options)116 117 return action118 119 60 def computeJobSize(self) : 120 61 """Computes the job size and return its value. … … 122 63 THIS METHOD IS COMPLETELY UNRELIABLE BUT SERVES AS AN EXAMPLE. 123 64 """ 65 # first we log a message because using this accounting method is not recommended. 66 self.filter.logger.log_message(_("Using the 'stupid' accounting method is unreliable."), "warn") 67 124 68 temporary = None 125 69 if self.filter.inputfile is None : … … 146 90 else : 147 91 infile.close() 148 149 92 return pagecount 150 -
pykota/trunk/pykota/reporter.py
r1235 r1239 22 22 # 23 23 # $Log$ 24 # Revision 1.5 2003/12/27 15:43:36 uid67467 25 # Savannah is back online... 26 # 24 27 # Revision 1.4 2003/12/02 14:40:21 jalet 25 28 # Some code refactoring. … … 58 61 59 62 def getPrinterTitle(self, printer) : 60 return _(" ***Report for %s quota on printer %s") % ((self.isgroup and "group") or "user", printer.Name)63 return _("Report for %s quota on printer %s") % ((self.isgroup and "group") or "user", printer.Name) 61 64 62 65 def getPrinterGraceDelay(self, printer) : -
pykota/trunk/pykota/reporters/html.py
r1236 r1239 22 22 # 23 23 # $Log$ 24 # Revision 1.2 2003/12/27 15:43:36 uid67467 25 # Savannah is back online... 26 # 24 27 # Revision 1.1 2003/12/02 14:41:17 jalet 25 28 # And as always, I forgot most of the new files :-) … … 38 41 self.report = [] 39 42 for printer in self.printers : 40 self.report.append( "<h1>%s</h1>"% self.getPrinterTitle(printer))41 self.report.append( "<h2>%s</h2>"% self.getPrinterGraceDelay(printer))43 self.report.append('<h2 class="printername">%s</h2>' % self.getPrinterTitle(printer)) 44 self.report.append('<h3 class="printergracedelay">%s</h3>' % self.getPrinterGraceDelay(printer)) 42 45 (pjob, ppage) = self.getPrinterPrices(printer) 43 self.report.append( "<h3>%s</h3>"% pjob)44 self.report.append( "<h3>%s</h3>"% ppage)46 self.report.append('<h4 class="priceperjob">%s</h4>' % pjob) 47 self.report.append('<h4 class="priceperpage">%s</h4>' % ppage) 45 48 total = 0 46 49 totalmoney = 0.0 47 self.report.append('<table border="1">')50 self.report.append('<table class="pykotatable" border="1">') 48 51 headers = self.getReportHeader().split() 49 headers.insert(1, "LimitBy") 50 self.report.append('<tr bgcolor="gold">%s</tr>' % "".join(["<th>%s</th>" % h for h in headers])) 52 headers.insert(1, "LimitBy") 53 self.report.append('<tr class="pykotacolsheader">%s</tr>' % "".join(["<th>%s</th>" % h for h in headers])) 54 oddeven = 0 51 55 if self.isgroup : 52 56 for (group, grouppquota) in self.tool.storage.getPrinterGroupsAndQuotas(printer, self.ugnames) : 57 oddeven += 1 58 if oddeven % 1 : 59 oddevenclass = "odd" 60 else : 61 oddevenclass = "even" 53 62 (pages, money, name, reached, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid) = self.getQuota(group, grouppquota) 54 self.report.append( "<tr>%s</tr>" % "".join(["<td>%s</td>" % h for h in (name, reached, pagecounter, soft, hard, balance, datelimit or " ", lifepagecounter, lifetimepaid)]))63 self.report.append('<tr class="%s">%s</tr>' % (oddevenclass, "".join(["<td>%s</td>" % h for h in (name, reached, pagecounter, soft, hard, balance, datelimit or " ", lifepagecounter, lifetimepaid)]))) 55 64 total += pages 56 65 totalmoney += money … … 58 67 # default is user quota report 59 68 for (user, userpquota) in self.tool.storage.getPrinterUsersAndQuotas(printer, self.ugnames) : 69 oddeven += 1 70 if oddeven % 1 : 71 oddevenclass = "odd" 72 else : 73 oddevenclass = "even" 60 74 (pages, money, name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid) = self.getQuota(user, userpquota) 61 self.report.append( "<tr>%s</tr>" % "".join(["<td>%s</td>" % h for h in (name, reached, pagecounter, soft, hard, balance, datelimit or " ", lifepagecounter, lifetimepaid)]))75 self.report.append('<tr class="%s">%s</tr>' % (oddevenclass, "".join(["<td>%s</td>" % h for h in (name, reached, pagecounter, soft, hard, balance, datelimit or " ", lifepagecounter, lifetimepaid)]))) 62 76 total += pages 63 77 totalmoney += money 64 78 if total or totalmoney : 65 79 (tpage, tmoney) = self.getTotals(total, totalmoney) 66 self.report.append('<tr ><td colspan="7"> </td><td align="right">%s</td><td align="right">%s</td></tr>' % (tpage, tmoney))67 self.report.append('<tr ><td colspan="7"> </td><td align="right">%s</td></tr>' % self.getPrinterRealPageCounter(printer))80 self.report.append('<tr class="totals"><td colspan="7"> </td><td align="right">%s</td><td align="right">%s</td></tr>' % (tpage, tmoney)) 81 self.report.append('<tr class="realpagecounter"><td colspan="7"> </td><td align="right">%s</td></tr>' % self.getPrinterRealPageCounter(printer)) 68 82 self.report.append('</table>') 69 83 if self.isgroup : 70 self.report.append( "<p>%s</p>"% _("Totals may be inaccurate if some users are members of several groups."))84 self.report.append('<p class="warning">%s</p>' % _("Totals may be inaccurate if some users are members of several groups.")) 71 85 return "\n".join(self.report) 72 86 -
pykota/trunk/pykota/version.py
r1227 r1239 22 22 # 23 23 24 __version__ = "1.16alpha1 6_unofficial"24 __version__ = "1.16alpha17_unofficial" 25 25 26 26 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""