config/pythonpath.py
author Benjamin Smedberg <benjamin@smedbergs.us>
Tue, 30 Jun 2009 13:21:26 -0400
changeset 35739 f5675fec1a8d6998c5d753aad794b3e3e951a5f7
parent 28231 6461b3507d98608fd398992b0306de679420fb4b
child 72669 4edf5956780be0ab7bc2268adea9c87034c265e7
permissions -rw-r--r--
Build fixes: * enable RTTI by default when building with GCC to work around the tr1/functional error * link with -lrt * Tell chromium that it's always using wide wchar on Linux

"""
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__', '__file__': script})