Changeset 1562
- Timestamp:
- 06/22/04 11:31:18 (20 years ago)
- Location:
- pykota/trunk
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r1546 r1562 24 24 # 25 25 # $Log$ 26 # Revision 1.65 2004/06/22 09:31:17 jalet 27 # Always send some debug info to CUPS' back channel stream (stderr) as 28 # informationnal messages. 29 # 26 30 # Revision 1.64 2004/06/18 13:34:46 jalet 27 31 # Now all tracebacks include PyKota's version number … … 366 370 self.softwareJobSize = self.precomputeJobSize() 367 371 self.softwareJobPrice = userpquota.computeJobPrice(self.softwareJobSize) 368 self. logdebug("Precomputed job's size is %s pages, price is %s units" % (self.softwareJobSize, self.softwareJobPrice))372 self.sendBackChannelData("Precomputed job's size is %s pages, price is %s units" % (self.softwareJobSize, self.softwareJobPrice)) 369 373 os.environ["PYKOTAPRECOMPUTEDJOBSIZE"] = str(self.softwareJobSize) 370 374 os.environ["PYKOTAPRECOMPUTEDJOBPRICE"] = str(self.softwareJobPrice) … … 386 390 self.prehook(userpquota) 387 391 388 self. logdebug("Job accounting begins.")392 self.sendBackChannelData("Job accounting begins.") 389 393 self.accounter.beginJob(userpquota) 390 394 else : … … 407 411 # stops accounting. 408 412 self.accounter.endJob(userpquota) 409 self. logdebug("Job accounting ends.")413 self.sendBackChannelData("Job accounting ends.") 410 414 411 415 # retrieve the job size 412 416 if action == "DENY" : 413 417 jobsize = 0 414 self. logdebug("Job size forced to 0 because printing is denied.")418 self.sendBackChannelData("Job size forced to 0 because printing is denied.") 415 419 else : 416 420 jobsize = self.accounter.getJobSize() 417 self. logdebug("Job size : %i" % jobsize)421 self.sendBackChannelData("Job size : %i" % jobsize) 418 422 419 423 # update the quota for the current user on this printer 420 self. logdebug("Updating user %s's quota on printer %s" % (user.Name, printer.Name))424 self.sendBackChannelData("Updating user %s's quota on printer %s" % (user.Name, printer.Name)) 421 425 jobprice = userpquota.increasePagesUsage(jobsize) 422 426 423 427 # adds the current job to history 424 428 printer.addJobToHistory(self.jobid, user, self.accounter.getLastPageCounter(), action, jobsize, jobprice, self.preserveinputfile, self.title, self.copies, self.options, clienthost, self.jobSizeBytes) 425 self. logdebug("Job added to history.")429 self.sendBackChannelData("Job added to history.") 426 430 427 431 # exports some new environment variables … … 465 469 return "%s (%s)" % (fd, " | ".join(maskval)) 466 470 471 def sendBackChannelData(self, message) : 472 """Sends an informational message to CUPS via back channel stream (stderr).""" 473 sys.stderr.write("INFO: PyKota (PID %s) : %s\n" % (os.getpid(), message.strip())) 474 sys.stderr.flush() 475 467 476 def handleData(self) : 468 477 """Pass the job's data to the real backend.""" … … 471 480 472 481 # And launch it 473 self. logdebug("Starting real backend %s with args %s" % (realbackend, " ".join(['"%s"' % a for a in ([os.environ["DEVICE_URI"]] + sys.argv[1:])])))482 self.sendBackChannelData("Starting real backend %s with args %s" % (realbackend, " ".join(['"%s"' % a for a in ([os.environ["DEVICE_URI"]] + sys.argv[1:])]))) 474 483 subprocess = PyKotaPopen4([realbackend] + sys.argv[1:], bufsize=0, arg0=os.environ["DEVICE_URI"]) 475 484 … … 501 510 # job's data is in a file, no need to pass the data 502 511 # to the real backend 503 self. logdebug("Job's data is in %s" % self.preserveinputfile)512 self.sendBackChannelData("Job's data is in %s" % self.preserveinputfile) 504 513 infno = None 505 514 endinput = 1 506 515 507 self. logdebug("Entering streams polling loop...")516 self.sendBackChannelData("Entering streams polling loop...") 508 517 MEGABYTE = 1024*1024 509 518 killed = 0 … … 521 530 self.logdebug("Error while sending signal to pid %s : %s" % (subprocess.pid, msg)) 522 531 else : 523 self. logger.log_message(_("SIGTERM was sent to real backend %s (pid: %s)") % (realbackend, subprocess.pid), "info")532 self.sendBackChannelData(_("SIGTERM was sent to real backend %s (pid: %s)") % (realbackend, subprocess.pid)) 524 533 killed = 1 525 534 … … 531 540 availablefds = [] 532 541 if not availablefds : 533 self. logdebug("Nothing to do, sleeping a bit...")542 self.sendBackChannelData("Nothing to do, sleeping a bit...") 534 543 time.sleep(0.01) # give some time to the system 535 544 else : … … 548 557 indata = "" 549 558 else : 550 self. logdebug("No data to send to real backend yet, sleeping a bit...")559 self.sendBackChannelData("No data to send to real backend yet, sleeping a bit...") 551 560 time.sleep(0.01) 552 561 553 562 if endinput : 554 563 self.unregisterFileNo(pollster, tocfno) 555 self. logdebug("Closing real backend's stdin.")564 self.sendBackChannelData("Closing real backend's stdin.") 556 565 os.close(tocfno) 557 566 inputclosed = 1 … … 585 594 if not data : # If yes, then no more input data 586 595 self.unregisterFileNo(pollster, infno) 587 self. logdebug("Input data ends.")596 self.sendBackChannelData("Input data ends.") 588 597 endinput = 1 # this happens with real files. 589 598 else : … … 591 600 elif fd == fromcfno : 592 601 if not data : 593 self. logdebug("No back channel data to read from real backend yet, sleeping a bit...")602 self.sendBackChannelData("No back channel data to read from real backend yet, sleeping a bit...") 594 603 time.sleep(0.01) 595 604 else : … … 606 615 # Here we are in the case where the input file is stdin. 607 616 # which has no more data to be read. 608 self. logdebug("Input data ends.")617 self.sendBackChannelData("Input data ends.") 609 618 endinput = 1 610 619 elif fd == fromcfno : 611 620 # We are no more interested in this file descriptor 612 self. logdebug("Closing real backend's stdout+stderr.")621 self.sendBackChannelData("Closing real backend's stdout+stderr.") 613 622 os.close(fromcfno) 614 623 endoutput = 1 … … 618 627 619 628 if mask & select.POLLNVAL : 620 self. logdebug("File %s was closed. Unregistering from polling object." % fd)629 self.sendBackChannelData("File %s was closed. Unregistering from polling object." % fd) 621 630 self.unregisterFileNo(pollster, fd) 622 631 except IOError, msg : … … 625 634 # We must close the real backend's input stream 626 635 if killed and not inputclosed : 627 self. logdebug("Forcing close of real backend's stdin.")636 self.sendBackChannelData("Forcing close of real backend's stdin.") 628 637 os.close(tocfno) 629 638 630 self. logdebug("Exiting streams polling loop...")639 self.sendBackChannelData("Exiting streams polling loop...") 631 640 632 641 # Check exit code of original CUPS backend. … … 634 643 # we exited the loop before the real backend exited 635 644 # now we have to wait for it to finish and get its status 636 self. logdebug("Waiting for real backend to exit...")645 self.sendBackChannelData("Waiting for real backend to exit...") 637 646 try : 638 647 status = subprocess.wait() -
pykota/trunk/pykota/tool.py
r1560 r1562 22 22 # 23 23 # $Log$ 24 # Revision 1.106 2004/06/22 09:31:18 jalet 25 # Always send some debug info to CUPS' back channel stream (stderr) as 26 # informationnal messages. 27 # 24 28 # Revision 1.105 2004/06/21 08:17:38 jalet 25 29 # Added version number in subject message for directive crashrecipient. … … 918 922 # seekable and complexifies our task, so create 919 923 # a temporary file and use it instead 920 self.logdebug("Duplicating data stream from stdin to temporary file") 924 self.sendBackChannelData("Duplicating data stream from stdin to temporary file") 925 dummy = 0 921 926 MEGABYTE = 1024*1024 922 927 self.jobSizeBytes = 0 … … 927 932 break 928 933 self.jobSizeBytes += len(data) 934 if not (dummy % 10) : 935 self.sendBackChannelData("%s bytes read..." % self.jobSizeBytes) 936 dummy += 1 929 937 infile.write(data) 930 938 infile.flush() … … 933 941 else : 934 942 # real file, just open it 935 self. logdebug("Opening data stream %s" % self.preserveinputfile)943 self.sendBackChannelData("Opening data stream %s" % self.preserveinputfile) 936 944 self.jobSizeBytes = os.stat(self.preserveinputfile)[6] 937 945 return open(self.preserveinputfile, "rb") … … 939 947 def closeJobDataStream(self) : 940 948 """Closes the file which contains the job's datas.""" 941 self. logdebug("Closing data stream.")949 self.sendBackChannelData("Closing data stream.") 942 950 try : 943 951 self.jobdatastream.close()