Show
Ignore:
Timestamp:
09/29/05 00:45:28 (19 years ago)
Author:
jerome
Message:

Added filters.
Added the onfail directive to tea4cups.conf

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • tea4cups/trunk/tea4cups

    r655 r659  
    3434import ConfigParser 
    3535import signal 
     36import popen2 
    3637from struct import pack, unpack 
    3738 
    38 version = "3.02_unofficial" 
     39version = "3.10_unofficial" 
    3940 
    4041class TeeError(Exception): 
     
    623624        else : 
    624625            infile = sys.stdin 
     626             
     627        filtercommand = self.getPrintQueueOption(self.PrinterName, "filter", \ 
     628                                                 ignore=1) 
     629        if filtercommand :                                                  
     630            self.logDebug("Data stream will be filtered through [%s]" % filtercommand) 
     631            filteroutput = "%s.filteroutput" % self.DataFile 
     632            outf = open(filteroutput, "wb") 
     633            filterstatus = self.stdioRedirSystem(filtercommand, infile.fileno(), outf.fileno()) 
     634            outf.close() 
     635            self.logDebug("Filter's output status : %s" % repr(filterstatus)) 
     636            if mustclose : 
     637                infile.close() 
     638            infile = open(filteroutput, "rb") 
     639            mustclose = 1 
     640        else :     
     641            self.logDebug("Data stream will be used as-is (no filter defined)") 
     642             
    625643        CHUNK = 64*1024         # read 64 Kb at a time 
    626644        dummy = 0 
     
    639657            dummy += 1 
    640658        outfile.close() 
     659         
     660        if filtercommand : 
     661            self.logDebug("Removing filter's output file %s" % filteroutput) 
     662            try : 
     663                os.remove(filteroutput) 
     664            except :     
     665                pass 
     666                 
    641667        if mustclose : 
    642668            infile.close() 
     669             
     670        self.logDebug("%s bytes saved..." % sizeread) 
    643671        self.JobSize = sizeread 
    644672        self.JobMD5Sum = checksum.hexdigest() 
     
    672700            if self.RealBackend : 
    673701                retcode = self.runOriginalBackend() 
     702                if retcode : 
     703                    onfail = self.getPrintQueueOption(self.PrinterName, \ 
     704                                                      "onfail", ignore=1) 
     705                    if onfail : 
     706                        self.logDebug("Launching onfail script %s" % onfail) 
     707                        os.system(onfail) 
    674708            if not self.gotSigTerm : 
    675709                os.environ["TEASTATUS"] = str(retcode)