Back to index

enigmail  1.4.3
pythonpath.py
Go to the documentation of this file.
00001 """
00002 Run a python script, adding extra directories to the python path.
00003 """
00004 
00005 
00006 def main(args):
00007     def usage():
00008         print >>sys.stderr, "pythonpath.py -I directory script.py [args...]"
00009         sys.exit(150)
00010 
00011     paths = []
00012 
00013     while True:
00014         try:
00015             arg = args[0]
00016         except IndexError:
00017             usage()
00018 
00019         if arg == '-I':
00020             args.pop(0)
00021             try:
00022                 path = args.pop(0)
00023             except IndexError:
00024                 usage()
00025 
00026             paths.append(os.path.abspath(path))
00027             continue
00028 
00029         if arg.startswith('-I'):
00030             paths.append(os.path.abspath(args.pop(0)[2:]))
00031             continue
00032 
00033         break
00034 
00035     script = args[0]
00036 
00037     sys.path[0:0] = [os.path.abspath(os.path.dirname(script))] + paths
00038     sys.argv = args
00039     sys.argc = len(args)
00040 
00041     frozenglobals['__name__'] = '__main__'
00042     frozenglobals['__file__'] = script
00043 
00044     execfile(script, frozenglobals)
00045 
00046 # Freeze scope here ... why this makes things work I have no idea ...
00047 frozenglobals = globals()
00048 
00049 import sys, os
00050 
00051 if __name__ == '__main__':
00052     main(sys.argv[1:])