Merge mozilla-b2g34 to 2.1s. a=merge
[gecko.git] / config / pythonpath.py
blob03180661481e9657091213f61b120f21099670de
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)
50 # Freeze scope here ... why this makes things work I have no idea ...
51 frozenglobals = globals()
53 import sys, os
55 if __name__ == '__main__':
56 main(sys.argv[1:])