Filter Chain debugging [was: Filter Chain not working]
pipitas
k1pfeifle at gmx.net
Fri Oct 22 22:18:56 PDT 2004
alex at j2anywhere.com wrote:
> I have set up 2 cups filters in my PPD file. When I print only the first
> filter is executed.
That's by design.
While you *can* name several "cupsFilters" in the PPD, for each job
only one is executed (the first one matching the named MIME type).
The line "cupsFilter" means this to CUPS: "after you have exectued
that filter named here, the job is ready with filtering and should
now be sent straight to the backend."
> The first filter is the bash script show below:
>
> As I forward
>
> --------------------------------------------------
> *NickName: "Canon S400"
> *cupsVersion: 1.1
> *cupsManualCopies: True
> *cupsFilter: "*/* 0 prefilter"
> *cupsFilter: "application/pdf 0
> /System/Library/Printers/Libraries/PrintJobMgr/Contents/MacOS/PrintJobMgr"
>
> *% Paper Handling ===================
> *OpenUI *PageSize: PickOne
> *DefaultPageSize: na-letter
> --------------------------------------------------
> #!/bin/bash
> date >> /tmp/prefilter.log
> echo 0 $0 >> /tmp/prefilter.log
> echo 1 $1 >> /tmp/prefilter.log
> echo 2 $2 >> /tmp/prefilter.log
> echo 3 $3 >> /tmp/prefilter.log
> echo 4 $4 >> /tmp/prefilter.log
> echo 5 $5 >> /tmp/prefilter.log
> echo 6 $6 >> /tmp/prefilter.log
> cat $6
This looks pretty much like you don't do anything to the
printjob itself, but you are just curious to see how the
system works and write a log.
> --------------------------------------------------
> How can I call the second filter specified in the PPD file ?
You can't. After one of the filters named in the PPD matches,
no further filtering is done by CUPS.
> Thanks
> Alex
If you want to log what filters see as commandline parameters
and as environment variables you have to write a wrapper script
around your real filters.
If you just want to *see* what's going on, set "LogLevel debug2"
and grep for "envp" and "argv" in the error_log.
Cheers,
Kurt
P.S.: a very elegant way to get one single wrapper script
(call it "cups-proxy-filter.sh") around all your CUPS
filters is this:
===================================================================
1. In your homedirectory, write the cupsfilterproxy.sh:
===================================================================
------------- snip ----------------------
#!/bin/bash
# (c) Kurt Pfeifle <kpfeifle at danka.de>
# <pfeifle at kde.org>
# Script is GPL and free to use and modify
#
# Proxy filter for CUPS to harvest intermediate
# files from each step in the filtering chain
#
#
# log a lot of stuff which may be interesting for us
# so we learn how CUPS works.... ;-)
LOG=/tmp/cupsproxyfilter.log
echo "=======================================================" >> $LOG
date >> $LOG
echo "=======================================================" >> $LOG
echo "I am running under this user ID:" >> $LOG
id >> $LOG
echo "=======================================================" >> $LOG
env >> $LOG
echo 0 $0 >> $LOG
echo 1 $1 >> $LOG
echo 2 $2 >> $LOG
echo 3 $3 >> $LOG
echo 4 $4 >> $LOG
echo 5 $5 >> $LOG
echo 6 $6 >> $LOG
# create a directory to store the output of each single filter
# under a uniq name for later debugging purpose
[ -d /tmp/cups-filter-outputs ] || mkdir /tmp/cups-filter-outputs
# in case of wrong number of arguments: print usage hint
if test "$#" -eq "0"; then
echo "ERROR: `basename $0` job-id user title copies options [file]" 1>&2
exit 0
fi
if test "$#" -lt "5"; then
echo "ERROR: Number of arguments ($#) is wrong" 1>&2
echo "USAGE: `basename $0` job-id user title copies options [file]" 1>&2
exit 1
fi
if test "$#" -gt "6"; then
echo "ERROR: Number of arguments ($#) is wrong" 1>&2
echo "USAGE: `basename $0` job-id user title copies options [file]" 1>&2
exit 1
fi
if test "$#" -eq "5"; then
INPUT="-"
else
INPUT="$6"
fi
echo $0.bin "$@" >> $LOG
echo "$#" >> $LOG
echo `id` >> $LOG
exec $0.bin "$@" | tee /tmp/cups-filter-outputs/JobID-$1-$3-`basename $0`-output
------------- snip ----------------------
===================================================================
2. make a complete backup of your CUPS filter dir:
===================================================================
cd $HOME
su
cd `cups-config --serverbin`
cp -R filter filter.bak
===================================================================
3. put the cups-proxy-filter.sh into the CUPS filter dir:
===================================================================
cd $HOME
su
cp cups-proxy-filter.sh `cups-config --serverbin`/filter/
chmod a+x `cups-config --serverbin`/filter/cups-proxy-filter.sh
===================================================================
4. rename all filters:
===================================================================
su
cd `cups-config --serverbin`/filter/;
for i in *; do mv $i $i.bin; done
===================================================================
5. symlink the original filter names to point to your proxyfilter:
===================================================================
su
cd `cups-config --serverbin`/filter/;
for i in *.bin; do ln -s $i `echo $i|sed 's#.bin##'`; done
===================================================================
6. restart cups
===================================================================
You should now have all your original filternames renamed to a
"filtername.bin" schema, and all original filternames pointing as a
symlink to your proxy filter.
The proxy filter then itself calls the original "filtername.bin" to
do the job while at the same time logging stuff and branching off
a copy of each intermediate file in the filtering chain (where the
intermediate files are stored to "/tmp/cups-filter-outputs/", under
easily identifiable names.
Now you can explore the CUPS filtering system to your heart's content,
run filters on the commandline, print stuff and fill your harddisk
quickly with intermediate files from teh printing process ... ;-)
Hope this helps,
Kurt
More information about the cups-devel
mailing list