The pykota filter
Last modified on $Date$
To account for pages or eventually ink usage, you must plug your accounting
system somewhere into the printing system you use, be it either CUPS
or LPRng. One way to do this without having
to modify the printing system itself, is by using a filter.
A filter is a computer program which takes data in one format as its input, and outputs the
same data but transformed into another format. CUPS already
contains many filters. For example there's one filter named pstops which accepts
PostScript data as its input, and, as its name implies, outputs PostScript data too, but after having
eventually rearranged the pages to fit several pages on a single sheet of paper, or other manipulations
like that.
The pstops filter described above is also in charge of doing basic page
accounting, but PyKota currently doesn't use this facility since it may
prove to be unreliable depending on the drivers used or if a paper jam occur for example.
LPRng can also use filters, one often used in combination with
LPRng is magicfilter which can convert
different input formats to native printers languages like PostScript or ESC/P2.
So to do its own accounting, PyKota has its own filter, named pykota,
which you have to plug into the different set of filters used by your printing system of choice. The procedure to
install the pykota filter is described in the
chapter.
Currently with a CUPS backend, the pykota filter is used at the very last stage of the print mechanism,
just before the final data is sent to the printer, but it may eventually be used earlier with some
modifications to CUPS's filtering configuration. This is not tested yet, but this
may be the solution to use PyKota with printers which really needs to have
a specific filter like magicfilter or cupsomatic,
i.e. non-postscript printers. This is a limitation in CUPS which doesn't really
allow to specify multiple print filters for different purposes. This problem will be solved in CUPS
version 1.2 and higher.
When used with an LPRng backend, the accounting filter is not defined the same way
input filters are, so the problem described above doesn't exist, and PyKota
may work with non-postscript printers, provided they can report their page counter and you know how to do
this.
When you submit a print job, pykota is automatically launched by your printing system,
so it has to detect which system you are using (CUPS or LPRng)
and behave like if it was specifically designed for your printing system. Fortunately there's not a lot
of differences, the more important one is the exit codes used to tell the printing environment if a job
has to be accepted or rejected.
pykota then asks the printer for its internal page counter, read from the Quota DataBase the internal
page counter for this printer when the previous job was launched, computes the difference, and report it as the
previous job's size in the Quota DataBase. It then updates the last user's print quota and account balance, and
warn him if he is over quota or his account balance below 0. Finally it checks if the user who launched the
current job is below or above his print quota, and either allow or deny the job's datas to pass to the underlying
layer (the printer itself).
If a problem occurs, it is logged either to the filter's standard output or to the system logger, depending on
your preferences in PyKota's configuration file. Also if a print quota is reached
you may choose if the administrator, the user, both or noone will receive an email message explaining
the situation and proposing a solution.