Show
Ignore:
Timestamp:
12/27/03 17:49:25 (20 years ago)
Author:
uid67467
Message:

Should be ok now.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r1222 r1240  
    2424# 
    2525# $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# 
    2633# Revision 1.16  2003/11/26 20:43:29  jalet 
    2734# Inadvertantly introduced a bug, which is fixed. 
     
    8491import os 
    8592import popen2 
    86 import time 
    8793import cStringIO 
    8894import shlex 
     
    187193        if user.Exists : 
    188194            # Is the current user allowed to print at all ? 
     195            thebackend.logdebug("Checking user %s's quota on printer %s" % (user.Name, printer.Name)) 
    189196            action = thebackend.warnUserPQuota(thebackend.storage.getUserPQuota(user, printer)) 
    190197        elif policy == "EXTERNAL" :                 
     
    203210        # pass the job untouched to the underlying layer 
    204211        # and starts accounting at the same time 
     212        thebackend.logdebug("Job accounting begins.") 
    205213        thebackend.accounter.beginJob(printer, user) 
    206214         
     
    222230         
    223231        # And launch it 
     232        thebackend.logdebug("Starting real backend %s with args %s" % (realbackend, " ".join([os.environ["DEVICE_URI"]] + sys.argv[1:]))) 
    224233        subprocess = PyKotaPopen3([realbackend] + sys.argv[1:], capturestderr=1, bufsize=0, arg0=os.environ["DEVICE_URI"]) 
    225234         
     
    248257        endinput = 0 
    249258        status = -1 
     259        inputclosed = 0 
     260        thebackend.logdebug("Entering streams polling loop...") 
    250261        while status == -1 : 
    251262            # First check if original backend is still alive 
     
    263274            availablefds = pollster.poll() 
    264275            for (fd, mask) in availablefds : 
     276                # thebackend.logdebug("file: %i    mask: %04x" % (fd, mask)) 
    265277                if mask & select.POLLOUT : 
    266278                    # We can write 
     
    303315                        # standard output 
    304316                        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.") 
    316323                    elif fd == cerrfno :     
    317324                        # Original CUPS backend has finished  
     
    319326                        if errdata :                 
    320327                            # 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 = "" 
    326330                        # 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.") 
    333334                         
    334             if endinput :             
     335            if endinput and not inputclosed :             
    335336                # We deal with remaining input datas here 
    336337                # because EOF can happen in two different 
     
    338339                # code, nor making functions. 
    339340                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.") 
    353348                 
    354349        # Input file was a real file, we have to close it.     
    355350        if mustclose : 
    356351            infile.close() 
     352             
     353        thebackend.logdebug("Exiting streams polling loop...") 
    357354             
    358355        # Check exit code of original CUPS backend.     
     
    365362    # stops accounting.  
    366363    thebackend.accounter.endJob(printer, user) 
     364    thebackend.logdebug("Job accounting ends.") 
    367365         
    368366    # retrieve the job size     
    369367    jobsize = thebackend.accounter.getJobSize() 
     368    thebackend.logdebug("Job size : %i" % jobsize) 
    370369     
    371370    # update the quota for the current user on this printer  
     
    374373        userquota = thebackend.storage.getUserPQuota(user, printer) 
    375374        if userquota.Exists : 
     375            thebackend.logdebug("Updating user %s's quota on printer %s" % (user.Name, printer.Name)) 
    376376            userquota.increasePagesUsage(jobsize) 
    377377     
    378378    # adds the current job to history     
    379379    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.") 
    380381     
    381382    return retcode # return (retcode or gotSigTerm) shouldn't be needed