diff options
author | Bill Napier <napier@google.com> | 2010-09-30 10:21:32 -0700 |
---|---|---|
committer | Android Code Review <code-review@android.com> | 2010-09-30 10:21:32 -0700 |
commit | ad5d6730be32ab38be880513502fc2fea0512c1b (patch) | |
tree | f8813d882c39d5d2a34c494149c4e7185b2d8536 /monkeyrunner/src | |
parent | 067f5426f1fc60f3870ea0bc15f58e00b10d7015 (diff) | |
parent | 5026cf75831b905d5002709abbd4b5a592628dda (diff) | |
download | sdk-ad5d6730be32ab38be880513502fc2fea0512c1b.zip sdk-ad5d6730be32ab38be880513502fc2fea0512c1b.tar.gz sdk-ad5d6730be32ab38be880513502fc2fea0512c1b.tar.bz2 |
Merge "Add in support for the sys.executable variable."
Diffstat (limited to 'monkeyrunner/src')
-rw-r--r-- | monkeyrunner/src/com/android/monkeyrunner/MonkeyRunnerStarter.java | 9 | ||||
-rw-r--r-- | monkeyrunner/src/com/android/monkeyrunner/ScriptRunner.java | 36 |
2 files changed, 28 insertions, 17 deletions
diff --git a/monkeyrunner/src/com/android/monkeyrunner/MonkeyRunnerStarter.java b/monkeyrunner/src/com/android/monkeyrunner/MonkeyRunnerStarter.java index 1f539ba..763362e 100644 --- a/monkeyrunner/src/com/android/monkeyrunner/MonkeyRunnerStarter.java +++ b/monkeyrunner/src/com/android/monkeyrunner/MonkeyRunnerStarter.java @@ -79,13 +79,17 @@ public class MonkeyRunnerStarter { } private int run() { + // This system property gets set by the included starter script + String monkeyRunnerPath = System.getProperty("com.android.monkeyrunner.bindir") + + File.separator + "monkeyrunner"; + MonkeyRunner.setBackend(backend); Map<String, Predicate<PythonInterpreter>> plugins = handlePlugins(); if (options.getScriptFile() == null) { - ScriptRunner.console(); + ScriptRunner.console(monkeyRunnerPath); return 0; } else { - int error = ScriptRunner.run(options.getScriptFile().getAbsolutePath(), + int error = ScriptRunner.run(monkeyRunnerPath, options.getScriptFile().getAbsolutePath(), options.getArguments(), plugins); backend.shutdown(); MonkeyRunner.setBackend(null); @@ -194,6 +198,7 @@ public class MonkeyRunnerStarter { return; } + MonkeyRunnerStarter runner = new MonkeyRunnerStarter(options); int error = runner.run(); diff --git a/monkeyrunner/src/com/android/monkeyrunner/ScriptRunner.java b/monkeyrunner/src/com/android/monkeyrunner/ScriptRunner.java index c247a5f..b55be87 100644 --- a/monkeyrunner/src/com/android/monkeyrunner/ScriptRunner.java +++ b/monkeyrunner/src/com/android/monkeyrunner/ScriptRunner.java @@ -68,8 +68,9 @@ public class ScriptRunner { * @param plugins a list of plugins to load. * @return the error code from running the script. */ - public static int run(String scriptfilename, Collection<String> args, - Map<String, Predicate<PythonInterpreter>> plugins) { + public static int run(String executablePath, String scriptfilename, + Collection<String> args, Map<String, + Predicate<PythonInterpreter>> plugins) { // Add the current directory of the script to the python.path search path. File f = new File(scriptfilename); @@ -84,7 +85,7 @@ public class ScriptRunner { argv[x++] = arg; } - initPython(classpath, argv); + initPython(executablePath, classpath, argv); PythonInterpreter python = new PythonInterpreter(); @@ -119,18 +120,20 @@ public class ScriptRunner { return 0; } - public static void runString(String script) { - initPython(); + public static void runString(String executablePath, String script) { + initPython(executablePath); PythonInterpreter python = new PythonInterpreter(); python.exec(script); } - public static Map<String, PyObject> runStringAndGet(String script, String... names) { - return runStringAndGet(script, Arrays.asList(names)); + public static Map<String, PyObject> runStringAndGet(String executablePath, + String script, String... names) { + return runStringAndGet(executablePath, script, Arrays.asList(names)); } - public static Map<String, PyObject> runStringAndGet(String script, Collection<String> names) { - initPython(); + public static Map<String, PyObject> runStringAndGet(String executablePath, + String script, Collection<String> names) { + initPython(executablePath); final PythonInterpreter python = new PythonInterpreter(); python.exec(script); @@ -141,13 +144,13 @@ public class ScriptRunner { return builder.build(); } - private static void initPython() { + private static void initPython(String executablePath) { List<String> arg = Collections.emptyList(); - initPython(arg, new String[] {""}); + initPython(executablePath, arg, new String[] {""}); } - private static void initPython(Collection<String> pythonPath, - String[] argv) { + private static void initPython(String executablePath, + Collection<String> pythonPath, String[] argv) { Properties props = new Properties(); // Build up the python.path @@ -163,14 +166,17 @@ public class ScriptRunner { // Choose one of error,warning,message,comment,debug props.setProperty("python.verbose", "error"); + // This needs to be set for sys.executable to function properly + props.setProperty("python.executable", executablePath); + PythonInterpreter.initialize(System.getProperties(), props, argv); } /** * Start an interactive python interpreter. */ - public static void console() { - initPython(); + public static void console(String executablePath) { + initPython(executablePath); InteractiveConsole python = new JLineConsole(); python.interact(); } |