170 | | MAXTRIES = 12 # maximum number of tries to get the printer's internal page counter |
171 | | TIMETOSLEEP = 10 # number of seconds to sleep between two tries to get the printer's internal page counter |
172 | | requester = openRequester(thebackend.config, thebackend.printername) |
173 | | def getPPC(requester, backend) : |
174 | | for i in range(MAXTRIES) : |
175 | | try : |
176 | | counterbeforejob = requester.getPrinterPageCounter(backend.printerhostname) |
177 | | except PyKotaRequesterError, msg : |
178 | | # can't get actual page counter, assume printer is off or warming up |
179 | | # log the message anyway. |
180 | | backend.logger.log_message("%s" % msg, "warn") |
181 | | counterbeforejob = None |
182 | | else : |
183 | | # printer answered, it is on so we can exit the loop |
184 | | break |
185 | | time.sleep(TIMETOSLEEP) |
186 | | return counterbeforejob |
187 | | |
195 | | # but get printer page counter before and after |
196 | | # print job is submitted to the hardware. |
197 | | |
198 | | # get page counter before job |
199 | | before = getPPC(requester, thebackend) |
200 | | |
201 | | # executes backend |
202 | | # TODO : use correct original backend. |
| 180 | # and starts accounting at the same time |
| 181 | thebackend.accounter.beginJob(printer, user) |
| 182 | |
| 183 | # executes original backend |
| 184 | #mustclose = 0 |
| 185 | #if thebackend.inputfile is not None : |
| 186 | # if hasattr(thebackend.inputfile, "read") : |
| 187 | # infile = thebackend.inputfile |
| 188 | # else : |
| 189 | # infile = open(thebackend.inputfile, "rb") |
| 190 | # mustclose = 1 |
| 191 | #else : |
| 192 | # infile = sys.stdin |
| 193 | |
206 | | # get page counter after job |
207 | | after = getPPC(requester, thebackend) |
208 | | |
209 | | # Computes the last job size as the difference between internal page |
210 | | # counter in the printer and last page counter taken from the Quota |
211 | | # Storage database for this particular printer |
212 | | try : |
213 | | jobsize = (after - before) |
214 | | except : |
215 | | jobsize = 0 |
216 | | |
| 197 | # stops accounting. |
| 198 | thebackend.accounter.endJob(printer, user) |
| 199 | |
| 200 | # retrieve the job size |
| 201 | jobsize = thebackend.accounter.getJobSize() |
| 202 | |
255 | | (devicetype, device, name, fullname) = arguments |
256 | | if name.startswith('"') and name.endswith('"') : |
257 | | name = name[1:-1] |
258 | | if fullname.startswith('"') and fullname.endswith('"') : |
259 | | fullname = fullname[1:-1] |
260 | | print '%s cupspykota:%s "PyKota+%s" "PyKota managed %s"' % (devicetype, device, name, fullname) |
| 243 | try : |
| 244 | (devicetype, device, name, fullname) = arguments |
| 245 | except ValueError : |
| 246 | pass # ignore this 'bizarre' device |
| 247 | else : |
| 248 | if name.startswith('"') and name.endswith('"') : |
| 249 | name = name[1:-1] |
| 250 | if fullname.startswith('"') and fullname.endswith('"') : |
| 251 | fullname = fullname[1:-1] |
| 252 | print '%s cupspykota:%s "PyKota+%s" "PyKota managed %s"' % (devicetype, device, name, fullname) |