config/pythonpath.py

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial