Show
Ignore:
Timestamp:
06/22/04 11:31:18 (20 years ago)
Author:
jalet
Message:

Always send some debug info to CUPS' back channel stream (stderr) as
informationnal messages.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r1546 r1562  
    2424# 
    2525# $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# 
    2630# Revision 1.64  2004/06/18 13:34:46  jalet 
    2731# Now all tracebacks include PyKota's version number 
     
    366370                self.softwareJobSize = self.precomputeJobSize() 
    367371                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)) 
    369373            os.environ["PYKOTAPRECOMPUTEDJOBSIZE"] = str(self.softwareJobSize) 
    370374            os.environ["PYKOTAPRECOMPUTEDJOBPRICE"] = str(self.softwareJobPrice) 
     
    386390            self.prehook(userpquota) 
    387391             
    388             self.logdebug("Job accounting begins.") 
     392            self.sendBackChannelData("Job accounting begins.") 
    389393            self.accounter.beginJob(userpquota) 
    390394        else :     
     
    407411            # stops accounting.  
    408412            self.accounter.endJob(userpquota) 
    409             self.logdebug("Job accounting ends.") 
     413            self.sendBackChannelData("Job accounting ends.") 
    410414                 
    411415            # retrieve the job size     
    412416            if action == "DENY" : 
    413417                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.") 
    415419            else :     
    416420                jobsize = self.accounter.getJobSize() 
    417             self.logdebug("Job size : %i" % jobsize) 
     421            self.sendBackChannelData("Job size : %i" % jobsize) 
    418422             
    419423            # 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)) 
    421425            jobprice = userpquota.increasePagesUsage(jobsize) 
    422426             
    423427            # adds the current job to history     
    424428            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.") 
    426430             
    427431            # exports some new environment variables 
     
    465469        return "%s (%s)" % (fd, " | ".join(maskval)) 
    466470         
     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         
    467476    def handleData(self) :                     
    468477        """Pass the job's data to the real backend.""" 
     
    471480         
    472481        # 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:])]))) 
    474483        subprocess = PyKotaPopen4([realbackend] + sys.argv[1:], bufsize=0, arg0=os.environ["DEVICE_URI"]) 
    475484         
     
    501510            # job's data is in a file, no need to pass the data 
    502511            # 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) 
    504513            infno = None 
    505514            endinput = 1 
    506515         
    507         self.logdebug("Entering streams polling loop...") 
     516        self.sendBackChannelData("Entering streams polling loop...") 
    508517        MEGABYTE = 1024*1024 
    509518        killed = 0 
     
    521530                    self.logdebug("Error while sending signal to pid %s : %s" % (subprocess.pid, msg)) 
    522531                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)) 
    524533                    killed = 1 
    525534             
     
    531540                availablefds = [] 
    532541            if not availablefds : 
    533                 self.logdebug("Nothing to do, sleeping a bit...") 
     542                self.sendBackChannelData("Nothing to do, sleeping a bit...") 
    534543                time.sleep(0.01) # give some time to the system 
    535544            else : 
     
    548557                                        indata = "" 
    549558                                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...") 
    551560                                    time.sleep(0.01) 
    552561                                     
    553562                                if endinput :     
    554563                                    self.unregisterFileNo(pollster, tocfno)         
    555                                     self.logdebug("Closing real backend's stdin.") 
     564                                    self.sendBackChannelData("Closing real backend's stdin.") 
    556565                                    os.close(tocfno) 
    557566                                    inputclosed = 1 
     
    585594                                    if not data :    # If yes, then no more input data 
    586595                                        self.unregisterFileNo(pollster, infno) 
    587                                         self.logdebug("Input data ends.") 
     596                                        self.sendBackChannelData("Input data ends.") 
    588597                                        endinput = 1 # this happens with real files. 
    589598                                    else :     
     
    591600                                elif fd == fromcfno : 
    592601                                    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...") 
    594603                                        time.sleep(0.01) 
    595604                                    else : 
     
    606615                                # Here we are in the case where the input file is stdin. 
    607616                                # which has no more data to be read. 
    608                                 self.logdebug("Input data ends.") 
     617                                self.sendBackChannelData("Input data ends.") 
    609618                                endinput = 1 
    610619                            elif fd == fromcfno :     
    611620                                # 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.") 
    613622                                os.close(fromcfno) 
    614623                                endoutput = 1 
     
    618627                                 
    619628                        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) 
    621630                            self.unregisterFileNo(pollster, fd) 
    622631                    except IOError, msg :             
     
    625634        # We must close the real backend's input stream 
    626635        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.") 
    628637            os.close(tocfno) 
    629638         
    630         self.logdebug("Exiting streams polling loop...") 
     639        self.sendBackChannelData("Exiting streams polling loop...") 
    631640         
    632641        # Check exit code of original CUPS backend.     
     
    634643            # we exited the loop before the real backend exited 
    635644            # 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...") 
    637646            try : 
    638647                status = subprocess.wait()