Changeset 659
- Timestamp:
- 09/29/05 00:45:28 (19 years ago)
- Location:
- tea4cups/trunk
- Files:
-
- 5 modified
Legend:
- Unmodified
- Added
- Removed
-
tea4cups/trunk/NEWS
r653 r659 23 23 Tea4CUPS News : 24 24 25 * 3.03 : 26 27 - Added filters. 28 25 29 * 3.02 : 26 30 -
tea4cups/trunk/README
r645 r659 24 24 25 25 Tea4CUPS 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.26 modify print jobs' datas as they pass through it and to transparently 27 send them to any number of outputs : other CUPS backends, files or pipes. 28 28 29 29 This for example allows you to output the same print job on several … … 37 37 commands into the very last stage of CUPS' filtering chain. 38 38 39 Tea4CUPS provides two ways to launch commands : 39 Tea4CUPS 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. 40 46 41 47 - prehooks : these are guaranteed to be launched before the 42 48 print job is sent to the real printer. 43 49 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. 45 52 46 53 - posthooks : these are guaranteed to be launched after the 47 54 print job has been sent to the real printer, 48 55 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. 50 58 51 59 To help your own commands, Tea4CUPS makes available as part of the 52 60 environment several variables which can be used from the 53 commands you use :61 commands you use in pre and post hooks : 54 62 55 63 TEAPRINTERNAME : The print queue name. … … 70 78 posthooks, obviously. 71 79 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 75 82 NB : Tea4CUPS requires a version of Python >= 2.1 76 83 -
tea4cups/trunk/tea4cups
r655 r659 34 34 import ConfigParser 35 35 import signal 36 import popen2 36 37 from struct import pack, unpack 37 38 38 version = "3. 02_unofficial"39 version = "3.10_unofficial" 39 40 40 41 class TeeError(Exception): … … 623 624 else : 624 625 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 625 643 CHUNK = 64*1024 # read 64 Kb at a time 626 644 dummy = 0 … … 639 657 dummy += 1 640 658 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 641 667 if mustclose : 642 668 infile.close() 669 670 self.logDebug("%s bytes saved..." % sizeread) 643 671 self.JobSize = sizeread 644 672 self.JobMD5Sum = checksum.hexdigest() … … 672 700 if self.RealBackend : 673 701 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) 674 708 if not self.gotSigTerm : 675 709 os.environ["TEASTATUS"] = str(retcode) -
tea4cups/trunk/tea4cups.conf
r648 r659 24 24 [global] 25 25 26 26 27 # Should we log debugging information to CUPS' error_log file ? 27 28 # defaults to No if unset. 28 29 debug : yes 30 29 31 30 32 # In which directory will we create our files ? It must already exist ! … … 36 38 directory : /var/spool/cups/ 37 39 40 38 41 # Should Tea4CUPS keep the files it creates once all hooks have ended ? 39 42 # Defaults to No if unset, meaning that files are automatically deleted … … 44 47 # BEWARE : this may use huge amounts of disk space ! 45 48 # 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 46 72 47 73 # Should we serialize the launch of all hooks : launch one after … … 59 85 # serialize : yes 60 86 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 : 64 91 # 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?????) 79 106 # 80 107 # Your own commands will mostly be interested in TEADATAFILE which is … … 82 109 # job's datas. Don't rely on TEAINPUTFILE, use TEADATAFILE instead 83 110 # since the first one may be empty depending on your printer driver. 111 84 112 85 113 # Some prehooks and posthooks … … 121 149 #posthook_0 : cat $TEADATAFILE >~$TEAUSERNAME/savejobs/$TEAJOBID.prn 122 150 151 123 152 # An empty value deletes a value defined in the [global] section 124 153 # so this particular hook doesn't get executed on this printer. 125 154 #prehook_pdf : 126 155 156 127 157 # A reflector which produces 4 copies each time : 128 158 #posthook_4copies : lp -dotherprinter -n4 $CUPSDATAFILE 129 159 160 130 161 # A simple accounting mechanism 131 162 #prehook_accounting : echo $TEAPRINTERNAME $TEAJOBID $TEAUSERNAME $TEABILLING `pkpgcounter $TEADATAFILE` >/var/log/printaccounting.log 163 132 164 133 165 # Some additionnal hooks to forbid duplicate jobs : … … 143 175 #posthook_to_filter_duplicates : echo "$TEAJOBID : $TEAMD5SUM" >>/tmp/jobmd5sums 144 176 177 145 178 # A particular prehook can send datas to the posthook 146 179 # of the same name automatically through pipes : -
tea4cups/trunk/TODO
r654 r659 23 23 TODO, in no particular order : 24 24 25 - Add an 'onfail' directive, to launch some script whenever 26 the real backend failed. 27 28 - Add filters. 25 - Nothing yet ! 29 26 30 27 ============================================================