config/pythonpath.py
author Marco Bonardo <mbonardo@mozilla.com>
Mon, 05 Oct 2009 12:12:46 +0200
changeset 33459 c2906e26f75af2ed5c218fe81d679f87fb22add2
parent 28231 6461b3507d98608fd398992b0306de679420fb4b
permissions -rw-r--r--
Bug 519186 - drag & drop in bookmarks menu does not correctly update the view, r=mano This is a regression from bug 498130.

"""
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})