Changeset 1240 for pykota/trunk/bin/cupspykota
- Timestamp:
- 12/27/03 17:49:25 (20 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r1222 r1240 24 24 # 25 25 # $Log$ 26 # Revision 1.17 2003/12/27 16:49:25 uid67467 27 # Should be ok now. 28 # 29 # Revision 1.17 2003/12/06 08:54:29 jalet 30 # Code simplifications. 31 # Added many debugging messages. 32 # 26 33 # Revision 1.16 2003/11/26 20:43:29 jalet 27 34 # Inadvertantly introduced a bug, which is fixed. … … 84 91 import os 85 92 import popen2 86 import time87 93 import cStringIO 88 94 import shlex … … 187 193 if user.Exists : 188 194 # Is the current user allowed to print at all ? 195 thebackend.logdebug("Checking user %s's quota on printer %s" % (user.Name, printer.Name)) 189 196 action = thebackend.warnUserPQuota(thebackend.storage.getUserPQuota(user, printer)) 190 197 elif policy == "EXTERNAL" : … … 203 210 # pass the job untouched to the underlying layer 204 211 # and starts accounting at the same time 212 thebackend.logdebug("Job accounting begins.") 205 213 thebackend.accounter.beginJob(printer, user) 206 214 … … 222 230 223 231 # And launch it 232 thebackend.logdebug("Starting real backend %s with args %s" % (realbackend, " ".join([os.environ["DEVICE_URI"]] + sys.argv[1:]))) 224 233 subprocess = PyKotaPopen3([realbackend] + sys.argv[1:], capturestderr=1, bufsize=0, arg0=os.environ["DEVICE_URI"]) 225 234 … … 248 257 endinput = 0 249 258 status = -1 259 inputclosed = 0 260 thebackend.logdebug("Entering streams polling loop...") 250 261 while status == -1 : 251 262 # First check if original backend is still alive … … 263 274 availablefds = pollster.poll() 264 275 for (fd, mask) in availablefds : 276 # thebackend.logdebug("file: %i mask: %04x" % (fd, mask)) 265 277 if mask & select.POLLOUT : 266 278 # We can write … … 303 315 # standard output 304 316 if outdata : 305 try : 306 os.write(stdoutfno, outdata) 307 outdata = "" 308 except : 309 pass 310 try : 311 pollster.unregister(fromcfno) 312 except KeyError : 313 pass 314 else : 315 os.close(fromcfno) 317 os.write(stdoutfno, outdata) 318 outdata = "" 319 # We are no more interested in this file descriptor 320 pollster.unregister(fromcfno) 321 os.close(fromcfno) 322 thebackend.logdebug("Real backend's stdout ends.") 316 323 elif fd == cerrfno : 317 324 # Original CUPS backend has finished … … 319 326 if errdata : 320 327 # Try to write remaining info (normally "Ready to print.") 321 try : 322 os.write(stderrfno, errdata) 323 errdata = "" 324 except : 325 pass 328 os.write(stderrfno, errdata) 329 errdata = "" 326 330 # We are no more interested in this file descriptor 327 try : 328 pollster.unregister(cerrfno) 329 except KeyError : 330 pass 331 else : 332 os.close(cerrfno) 331 pollster.unregister(cerrfno) 332 os.close(cerrfno) 333 thebackend.logdebug("Real backend's stderr ends.") 333 334 334 if endinput :335 if endinput and not inputclosed : 335 336 # We deal with remaining input datas here 336 337 # because EOF can happen in two different … … 338 339 # code, nor making functions. 339 340 if indata : 340 try : 341 os.write(tocfno, indata) 342 indata = "" 343 except : 344 pass 345 # Again, we're not interested in this file descriptor 346 # anymore. 347 try : 348 pollster.unregister(tocfno) 349 except KeyError : 350 pass 351 else : 352 os.close(tocfno) 341 os.write(tocfno, indata) 342 indata = "" 343 # Again, we're not interested in this file descriptor anymore. 344 pollster.unregister(tocfno) 345 os.close(tocfno) 346 inputclosed = 1 347 thebackend.logdebug("Input data ends.") 353 348 354 349 # Input file was a real file, we have to close it. 355 350 if mustclose : 356 351 infile.close() 352 353 thebackend.logdebug("Exiting streams polling loop...") 357 354 358 355 # Check exit code of original CUPS backend. … … 365 362 # stops accounting. 366 363 thebackend.accounter.endJob(printer, user) 364 thebackend.logdebug("Job accounting ends.") 367 365 368 366 # retrieve the job size 369 367 jobsize = thebackend.accounter.getJobSize() 368 thebackend.logdebug("Job size : %i" % jobsize) 370 369 371 370 # update the quota for the current user on this printer … … 374 373 userquota = thebackend.storage.getUserPQuota(user, printer) 375 374 if userquota.Exists : 375 thebackend.logdebug("Updating user %s's quota on printer %s" % (user.Name, printer.Name)) 376 376 userquota.increasePagesUsage(jobsize) 377 377 378 378 # adds the current job to history 379 379 printer.addJobToHistory(thebackend.jobid, user, thebackend.accounter.getLastPageCounter(), action, jobsize, jobprice, thebackend.preserveinputfile, thebackend.title, thebackend.copies, thebackend.options) 380 thebackend.logdebug("Job added to history.") 380 381 381 382 return retcode # return (retcode or gotSigTerm) shouldn't be needed