Description: Make pypy_interact suitable for end-user use
 Hardcode our pypy-c-sandbox location in pypy_interact, and change it to think
 that it's called pypy-sandbox
Author: Stefano Rivera <stefanor@debian.org>
Forwarded: no
Last-Update: 2013-02-23

--- a/pypy/sandbox/pypy_interact.py
+++ b/pypy/sandbox/pypy_interact.py
@@ -3,7 +3,7 @@
 """Interacts with a PyPy subprocess translated with --sandbox.
 
 Usage:
-    pypy_interact.py [options] <executable> <args...>
+    pypy-sandbox [options] <args...>
 
 Options:
     --tmp=DIR     the real directory that corresponds to the virtual /tmp,
@@ -17,7 +17,7 @@
 Note that you can get readline-like behavior with a tool like 'ledit',
 provided you use enough -u options:
 
-    ledit python -u pypy_interact.py pypy-c-sandbox -u
+    ledit python -u /usr/bin/pypy-sandbox -u
 """
 
 import sys, os
@@ -110,10 +110,15 @@
         else:
             raise ValueError(option)
 
-    if len(arguments) < 1:
-        help()
-
-    sandproc = PyPySandboxedProc(arguments[0], extraoptions + arguments[1:],
+    sys_implementation = getattr(sys, 'implementation', sys)
+    multiarch_triple = getattr(sys_implementation, '_multiarch', None)
+    if not multiarch_triple:
+        from subprocess import check_output
+        multiarch_triple = check_output(('gcc', '--print-multiarch')).strip()
+
+    sandproc = PyPySandboxedProc('/usr/lib/pypy-sandbox/%s/pypy-c-sandbox'
+                                 % multiarch_triple,
+                                 extraoptions + arguments,
                                  tmpdir=tmpdir, debug=debug)
     if timeout is not None:
         sandproc.settimeout(timeout, interrupt_main=True)
