[pypy-svn] r45829 - pypy/branch/pypy-more-rtti-inprogress/translator/sandbox
arigo at codespeak.net
arigo at codespeak.net
Fri Aug 17 20:13:18 CEST 2007
Author: arigo
Date: Fri Aug 17 20:13:17 2007
New Revision: 45829
Modified:
pypy/branch/pypy-more-rtti-inprogress/translator/sandbox/pypy_interact.py
Log:
Improve pypy_interact.py; added the --tmp=DIR option.
Modified: pypy/branch/pypy-more-rtti-inprogress/translator/sandbox/pypy_interact.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/sandbox/pypy_interact.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/sandbox/pypy_interact.py Fri Aug 17 20:13:17 2007
@@ -3,12 +3,15 @@
"""Interacts with a PyPy subprocess translated with --sandbox.
Usage:
- pypy_interact.py <executable> <args...>
+ pypy_interact.py [options] <executable> <args...>
+
+Options:
+ --tmp=DIR the real directory that corresponds to the virtual /tmp,
+ which is the virtual current dir (always read-only for now)
"""
import sys, os
import autopath
-from pypy.tool.udir import udir
from pypy.translator.sandbox.sandlib import SimpleIOSandboxedProc
from pypy.translator.sandbox.sandlib import VirtualizedSandboxedProc
@@ -16,10 +19,10 @@
debug = True
argv0 = '/opt/pypy-c'
virtual_cwd = '/tmp'
- virtual_env = {'PYTHONSTARTUP': ''}
+ virtual_env = {}
virtual_console_isatty = True
- def __init__(self, executable, arguments):
+ def __init__(self, executable, arguments, tmpdir):
super(PyPySandboxedProc, self).__init__([self.argv0] + arguments,
executable=executable)
pypydist = os.path.dirname(os.path.abspath(autopath.pypydir))
@@ -30,13 +33,36 @@
'/opt/lib-python': os.path.join(pypydist, 'lib-python'),
'/opt/pypy/lib': os.path.join(pypydist, 'pypy', 'lib'),
# can access the temporary usession directory as /tmp
- self.virtual_cwd: str(udir),
+ self.virtual_cwd: tmpdir,
}
if __name__ == '__main__':
- if len(sys.argv) < 2:
+ from getopt import getopt # and not gnu_getopt!
+ options, arguments = getopt(sys.argv[1:], 't:h', ['tmp=', 'help'])
+ tmpdir = None
+
+ def help():
print >> sys.stderr, __doc__
sys.exit(2)
- sandproc = PyPySandboxedProc(sys.argv[1], sys.argv[2:])
+
+ for option, value in options:
+ if option in ['-t', '--tmp']:
+ value = os.path.abspath(value)
+ if not os.path.isdir(value):
+ raise OSError("%r is not a directory" % (value,))
+ tmpdir = value
+ elif option in ['-h', '--help']:
+ help()
+ else:
+ raise ValueError(option)
+
+ if len(arguments) < 1:
+ help()
+
+ if tmpdir is None:
+ from pypy.tool.udir import udir
+ tmpdir = str(udir)
+
+ sandproc = PyPySandboxedProc(arguments[0], arguments[1:], tmpdir=tmpdir)
sandproc.interact()
More information about the Pypy-commit
mailing list