Bug 1508381 - remove now-unnecessary TASKCLUSTER_* variables r=tomprince
[gecko.git] / config / pythonpath.py
blobb02cd44243956c98d9a50b67493f8cbffaccc01d
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 """
6 Run a python script, adding extra directories to the python path.
7 """
10 def main(args):
11 def usage():
12 print >>sys.stderr, "pythonpath.py -I directory script.py [args...]"
13 sys.exit(150)
15 paths = []
17 while True:
18 try:
19 arg = args[0]
20 except IndexError:
21 usage()
23 if arg == '-I':
24 args.pop(0)
25 try:
26 path = args.pop(0)
27 except IndexError:
28 usage()
30 paths.append(os.path.abspath(path))
31 continue
33 if arg.startswith('-I'):
34 paths.append(os.path.abspath(args.pop(0)[2:]))
35 continue
37 break
39 script = args[0]
41 sys.path[0:0] = [os.path.abspath(os.path.dirname(script))] + paths
42 sys.argv = args
43 sys.argc = len(args)
45 frozenglobals['__name__'] = '__main__'
46 frozenglobals['__file__'] = script
48 execfile(script, frozenglobals)
51 # Freeze scope here ... why this makes things work I have no idea ...
52 frozenglobals = globals()
54 import sys
55 import os
57 if __name__ == '__main__':
58 main(sys.argv[1:])