Changeset 659

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

Added filters.
Added the onfail directive to tea4cups.conf

Location:
tea4cups/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • tea4cups/trunk/NEWS

    r653 r659  
    2323Tea4CUPS News : 
    2424 
     25  * 3.03 : 
     26   
     27    - Added filters. 
     28     
    2529  * 3.02 : 
    2630   
  • tea4cups/trunk/README

    r645 r659  
    2424 
    2525Tea4CUPS behaves just like any other CUPS backend, but allows you to 
    26 transparently send print jobs' datas to any number of outputs : other 
    27 CUPS backends, files or pipes. 
     26modify print jobs' datas as they pass through it and to transparently  
     27send them to any number of outputs : other CUPS backends, files or pipes. 
    2828 
    2929This for example allows you to output the same print job on several 
     
    3737commands into the very last stage of CUPS' filtering chain. 
    3838 
    39 Tea4CUPS provides two ways to launch commands : 
     39Tea4CUPS provides three ways to launch commands : 
     40 
     41        - filters : A filter can modify the input datas before they 
     42                    are sent to the printer or made available to 
     43                    the pre and post hooks defined below. 
     44                    Currently a single filter can be defined 
     45                    per print queue. 
    4046 
    4147        - prehooks : these are guaranteed to be launched before the 
    4248                     print job is sent to the real printer. 
    4349                     Any prehook which exits -1 can cancel the 
    44                      print job. 
     50                     print job. Any number of prehooks can be 
     51                     defined for a particular print queue. 
    4552 
    4653        - posthooks : these are guaranteed to be launched after the 
    4754                      print job has been sent to the real printer, 
    4855                      unless the job was previously cancelled by a 
    49                       prehook. 
     56                      prehook. Any number of posthooks can be  
     57                      defined for a particular print queue. 
    5058 
    5159To help your own commands, Tea4CUPS makes available as part of the 
    5260environment several variables which can be used from the 
    53 commands you use : 
     61commands you use in pre and post hooks : 
    5462 
    5563        TEAPRINTERNAME : The print queue name. 
     
    7078                    posthooks, obviously. 
    7179 
    72 In the case you want to use both Tea4CUPS and PyKota, you MUST install 
    73 PyKota v1.22alpha2 or higher to avoid a race condition. 
    74  
     80        None of these environment variables is available to filters. 
     81   
    7582NB : Tea4CUPS requires a version of Python >= 2.1 
    7683 
  • 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) 
  • tea4cups/trunk/tea4cups.conf

    r648 r659  
    2424[global] 
    2525 
     26 
    2627# Should we log debugging information to CUPS' error_log file ? 
    2728# defaults to No if unset. 
    2829debug : yes 
     30 
    2931 
    3032# In which directory will we create our files ? It must already exist ! 
     
    3638directory : /var/spool/cups/ 
    3739 
     40 
    3841# Should Tea4CUPS keep the files it creates once all hooks have ended ? 
    3942# Defaults to No if unset, meaning that files are automatically deleted 
     
    4447# BEWARE : this may use huge amounts of disk space ! 
    4548# keepfiles : yes 
     49 
     50 
     51# Should we launch some command when the real CUPS backend fails ? 
     52# Can be set either in the [global] section or any print queue section. 
     53# The value defined in a print queue section takes precedence over the 
     54# value defined in the [global] section. 
     55# onfail : echo "Original Backend failed" | /usr/bin/mail -s Tea4CUPS root 
     56 
     57 
     58# Should we pass incoming datas through a filter command  
     59# BEFORE doing anything else ? 
     60# NB : obvisouly the filter command doesn't have any access to 
     61#      the environment variables defined below. 
     62# Can be set either in the [global] section or any print queue section. 
     63# The value defined in a print queue section takes precedence over the 
     64# value defined in the [global] section. 
     65#  
     66# The sample filter below can remove the print job creation date 
     67# from PostScript jobs, in order to more accurately detect duplicate 
     68# jobs (so the MD5SUM would be identical from launch to launch) 
     69# 
     70# filter : /bin/grep -v "%%CreationDate:" 
     71 
    4672 
    4773# Should we serialize the launch of all hooks : launch one after 
     
    5985# serialize : yes 
    6086 
    61 # When executing the contents of a prehook or posthook directive, 
    62 # tea4cups makes the following environment variables available to your 
    63 # own commands : 
     87 
     88# When executing the contents of a prehook or posthook directive, as 
     89# defined below, tea4cups makes the following environment variables  
     90# available to your own commands : 
    6491# 
    65 # TEAPRINTERNAME : The print queue name. 
    66 # TEADIRECTORY : Tea4CUPS output directory. 
    67 # TEADATAFILE : Full name of Tea4CUPS work file (in $TEADIRECTORY). 
    68 # TEAJOBSIZE : Job's size in bytes. 
    69 # TEAMD5SUM : MD5 sum of the job's datas. 
    70 # TEACLIENTHOST : Client's hostname or IP address. 
    71 # TEAJOBID : Job's Id. 
    72 # TEAUSERNAME : Name of the user who launched the print job. 
    73 # TEATITLE : Job's title. 
    74 # TEACOPIES : Number of copies requested. 
    75 # TEAOPTIONS : Options of the print job. 
    76 # TEAINPUTFILE : Job's data file or empty when job read from stdin. 
    77 # TEABILLING : Job's billing code (lp -o job-billing=SomeCode file.ps) 
    78 # TEACONTROLFILE : Job's IPP message file (usually /var/spool/cups/c?????) 
     92#      TEAPRINTERNAME : The print queue name. 
     93#      TEADIRECTORY : Tea4CUPS output directory. 
     94#      TEADATAFILE : Full name of Tea4CUPS work file (in $TEADIRECTORY). 
     95#      TEAJOBSIZE : Job's size in bytes. 
     96#      TEAMD5SUM : MD5 sum of the job's datas. 
     97#      TEACLIENTHOST : Client's hostname or IP address. 
     98#      TEAJOBID : Job's Id. 
     99#      TEAUSERNAME : Name of the user who launched the print job. 
     100#      TEATITLE : Job's title. 
     101#      TEACOPIES : Number of copies requested. 
     102#      TEAOPTIONS : Options of the print job. 
     103#      TEAINPUTFILE : Job's data file or empty when job read from stdin. 
     104#      TEABILLING : Job's billing code (lp -o job-billing=SomeCode file.ps) 
     105#      TEACONTROLFILE : Job's IPP message file (usually /var/spool/cups/c?????) 
    79106# 
    80107# Your own commands will mostly be interested in TEADATAFILE which is 
     
    82109# job's datas. Don't rely on TEAINPUTFILE, use TEADATAFILE instead 
    83110# since the first one may be empty depending on your printer driver. 
     111 
    84112 
    85113# Some prehooks and posthooks 
     
    121149#posthook_0 : cat $TEADATAFILE >~$TEAUSERNAME/savejobs/$TEAJOBID.prn 
    122150 
     151 
    123152# An empty value deletes a value defined in the [global] section 
    124153# so this particular hook doesn't get executed on this printer. 
    125154#prehook_pdf : 
    126155 
     156 
    127157# A reflector which produces 4 copies each time : 
    128158#posthook_4copies : lp -dotherprinter -n4 $CUPSDATAFILE 
    129159 
     160 
    130161# A simple accounting mechanism 
    131162#prehook_accounting : echo $TEAPRINTERNAME $TEAJOBID $TEAUSERNAME $TEABILLING `pkpgcounter $TEADATAFILE` >/var/log/printaccounting.log 
     163 
    132164 
    133165# Some additionnal hooks to forbid duplicate jobs : 
     
    143175#posthook_to_filter_duplicates : echo "$TEAJOBID : $TEAMD5SUM" >>/tmp/jobmd5sums 
    144176 
     177 
    145178# A particular prehook can send datas to the posthook 
    146179# of the same name automatically through pipes : 
  • tea4cups/trunk/TODO

    r654 r659  
    2323TODO, in no particular order : 
    2424         
    25         - Add an 'onfail' directive, to launch some script whenever 
    26           the real backend failed. 
    27            
    28         - Add filters.   
     25        - Nothing yet ! 
    2926         
    3027============================================================