Changeset 1271 for pykota/trunk/pykota/accounter.py
- Timestamp:
- 01/12/04 00:22:42 (20 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/accounter.py
r1257 r1271 22 22 # 23 23 # $Log$ 24 # Revision 1.11 2004/01/11 23:22:42 jalet 25 # Major code refactoring, it's way cleaner, and now allows automated addition 26 # of printers on first print. 27 # 24 28 # Revision 1.10 2004/01/08 14:10:32 jalet 25 29 # Copyright year changed. … … 69 73 self.filter = kotafilter 70 74 self.arguments = arguments 75 self.isDelayed = 0 # Accounting is immediate by default 71 76 72 77 def getLastPageCounter(self) : … … 76 81 except : 77 82 return 0 78 79 def filterInput(self, inputfile) :80 """Transparent filter."""81 mustclose = 082 if inputfile is not None :83 if hasattr(inputfile, "read") :84 infile = inputfile85 else :86 infile = open(inputfile, "rb")87 mustclose = 188 else :89 infile = sys.stdin90 data = infile.read(256*1024)91 while data :92 sys.stdout.write(data)93 data = infile.read(256*1024)94 if mustclose :95 infile.close()96 83 97 def beginJob(self, printer, user) :84 def beginJob(self, userpquota) : 98 85 """Saves the computed job size.""" 99 86 # computes job's size … … 101 88 102 89 # get last job information for this printer 103 if not printer.LastJob.Exists :90 if not userpquota.Printer.LastJob.Exists : 104 91 # The printer hasn't been used yet, from PyKota's point of view 105 92 self.LastPageCounter = 0 … … 108 95 # Last lifetime page counter before actual job is 109 96 # last page counter + last job size 110 self.LastPageCounter = int( printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0)97 self.LastPageCounter = int(userpquota.Printer.LastJob.PrinterPageCounter or 0) + int(userpquota.Printer.LastJob.JobSize or 0) 111 98 112 def endJob(self, printer, user) :99 def endJob(self, userpquota) : 113 100 """Do nothing.""" 114 101 pass … … 121 108 return 0 122 109 123 def doAccounting(self, printer, user) :124 """Dele tgates the computation of the job size to an external command.110 def doAccounting(self, userpquota) : 111 """Delegates the computation of the job size to an external command. 125 112 126 113 The command must print the job size on its standard output and exit successfully. 127 114 """ 128 self.beginJob( printer, user)115 self.beginJob(userpquota) 129 116 130 117 # get the job size, which is real job size * number of copies. 118 # TODO : Double check with CUPS documentation : this is not always correct 131 119 jobsize = self.getJobSize() * self.filter.copies 132 120 133 121 # Is the current user allowed to print at all ? 134 userpquota = self.filter.storage.getUserPQuota(user, printer)135 122 action = self.filter.warnUserPQuota(userpquota) 136 123 … … 142 129 143 130 # adds the current job to history 144 jobprice = (float( printer.PricePerPage or 0.0) * jobsize) + float(printer.PricePerJob or 0.0)145 printer.addJobToHistory(self.filter.jobid, user, self.getLastPageCounter(), action, jobsize, jobprice, self.filter.preserveinputfile, self.filter.title, self.filter.copies, self.filter.options)146 self.endJob( printer, user)131 jobprice = (float(userpquota.Printer.PricePerPage or 0.0) * jobsize) + float(userpquota.Printer.PricePerJob or 0.0) 132 userpquota.Printer.addJobToHistory(self.filter.jobid, userpquota.User, self.getLastPageCounter(), action, jobsize, jobprice, self.filter.preserveinputfile, self.filter.title, self.filter.copies, self.filter.options) 133 self.endJob(userpquota) 147 134 return action 148 135