>> Hello there,
>>
>> I'm running an acconting script written in Python via the ifhp-filter
>>option:
>>
>> accounting=/usr/local/libexec/filters/accounting_script.py
>>
>> Python needs some Environment-Variables to work correct.
>> (LD_LIBRARY_PATH and PYTHONPATH).
>> I was able to set LD_LIBRARY_PATH to what I wanted modifying /etc/lpd.conf
>> and therein filter_ld_path correctly.
>> But it seems as if there is no possibility to set a completely new
>> environment-variable
>> here. I used to fix similar problems with the apache server modifying
>> httpd.conf
>> and using the setenv directive.
>> Is there a possibility to set new environment variables for the
>> environment, the
>> filters of LPRng are running in?
>>
>> Thanks for any tip
>>
>> Peter
>>
>> ---------------------------------------------------------------------
>Ummm.... I hate to say this, but the short answer is no.
>
>The problem here is that there are alternatives to adding this functionality,
>namely a shell script wrapper.
>
>#!/bin/sh
>PYTHONPATH=/....
>LD_LIBRARY_PATH=/....
>exec /what_you_want xxx "$@"
>
>If you don't like shell scripts, may I recommend:
>
>#include <stdlib.h>
>int main( int argc, char **argv ){
> setenv("PYTHONPATH","/...")
> setenv("LD_LIBRARY_PATH","/...")
> execv("/bin/python", argv );
> return(0);
>}
>
>Sorry about that...
>
>Patrick
>
>-----------------------------------------------------------------------------
Don't apologize - you did a great job!
Maybe it's a hint for future improvements.
I solved my problem using a shell script wrapper - as you suggested.
For those who might run into the same problem and who are
Python-programmers I supply my
pure Python shell script wrapper solution. It does accounting using a MySQL
database.
The wrapper script:
--------------------------------------------------------------------------------
----------
#! /usr/local/bin/python
# wrapping script in order to set correct environment for the 'real' script
# transfers sub-process's exit code back to calling process
import os # import the modules to use
import sys
os.environ['PYTHONPATH'] = '/usr/local/lib/python' # update the
environment for the child
os.environ['LD_LIBRARY_PATH'] = '/usr/local/lib/mysql' # another env. var
for the child
cmd_str = '/usr/local/libexec/filters/account.py' # the base command
for a in sys.argv[1:] : # add the supplied
arguments
cmd_str = cmd_str + ' ' + a
raw_exit_code = os.system(cmd_str) # execute child and
fetch exit code
exit_code = raw_exit_code % 255 # for some reason
childs exit code is in high-byte
sys.exit(exit_code) # pass it to the
calling program (filter)
--------------------------------------------------------------------------------
-----------
The script that is called (account.py), doing database accounting
(snipplet) and logging
--------------------------------------------------------------------------------
-----------
#! /usr/local/bin/python
# MySQL DB Interface for printing system
# exits 0 if printing is allowed for user
# exits 1 if account is negative and printing is not allowed
import os
import sys
import string
import time
import MySQLdb # this needs the following environment variables
set correctly
# LD_LIBRARY_PATH
# PYTHONPATH
logfilename = '/var/log/account_log'
def log() :
t = time.localtime(time.time())
time_str = `t[0]` + '-' + `t[1]` + '-' + `t[2]` + ' ' + `t[3]` +
':' + `t[4]` + ':' + `t[5]`
logfile = open (logfilename, 'a')
logfile.write (time_str)
for i in sys.argv :
logfile.write (' ')
logfile.write (i)
logfile.write ('\n')
connection = MySQLdb.connect (db='whichever', user='whoever',
passwd='whatever')
pr_cursor = connection.cursor()
query = "whatever database command has to be used"
pr_cursor.execute(query)
pr_cursor.close()
connection.close()
log()
# include any code that calculates the correct exit_code
# depending on database query
sys.exit(exit_code)
--------------------------------------------------------------------------------
-----------
- thanks for the tip and the fast answer!
Peter
---------------------------------------------------------------------
Peter Breuer, http://www.psych.uni-goettingen.de/home/breuer
Georg-Elias-Mueller-Inst. f. Psychologie, Gosslerstr. 14, 37073 Goettingen,
Germany
Tel: (+49)551-39-3588, Fax: (+49)551-39-3662
-----------------------------------------------------------------------------
If you need help, send email to [EMAIL PROTECTED] (or lprng-requests
or lprng-digest-requests) with the word 'help' in the body. For the impatient,
to subscribe to a list with name LIST, send mail to [EMAIL PROTECTED]
with: | example:
subscribe LIST <mailaddr> | subscribe lprng-digest [EMAIL PROTECTED]
unsubscribe LIST <mailaddr> | unsubscribe lprng [EMAIL PROTECTED]
If you have major problems, send email to [EMAIL PROTECTED] with the word
LPRNGLIST in the SUBJECT line.
-----------------------------------------------------------------------------