Fix the PYTHONPATH bits of bug 436062 in a not-hacky way by using a script which can set up the path and then forward to the real script we're trying to run, r=ted

This commit is contained in:
Benjamin Smedberg
2009-04-15 09:06:09 -04:00
parent 9c39767d35
commit da7ab6a870
2 changed files with 43 additions and 2 deletions

40
config/pythonpath.py Normal file
View File

@@ -0,0 +1,40 @@
"""
Run a python script, adding extra directories to the python path.
"""
import sys, os
def usage():
print >>sys.stderr, "pythonpath.py -I directory script.py [args...]"
sys.exit(150)
paths = []
while True:
try:
arg = sys.argv[1]
except IndexError:
usage()
if arg == '-I':
del sys.argv[1]
try:
path = sys.argv.pop(1)
except IndexError:
usage()
paths.append(path)
continue
if arg.startswith('-I'):
path = sys.argv.pop(1)[2:]
paths.append(path)
continue
break
sys.argv.pop(0)
script = sys.argv[0]
sys.path[0:0] = [os.path.dirname(script)] + paths
execfile(script, {'__name__': '__main__'})