java scriptrunner_ScriptRunner.java

ScriptRunner.java

上一篇 /

下一篇  2012-03-19 15:05:42

/ 个人分类:android

package com.android.monkeyrunner;

import org.python.core.Py;

import org.python.core.PyObject;

import org.python.util.PythonInterpreter;

import org.python.util.InteractiveConsole;

import java.io.File;

import java.io.IOException;

import java.io.FileInputStream;

import java.lang.RuntimeException;

import java.util.Properties;

/***

* Runs Jython based scripts.

*/

public class ScriptRunner {

/*** The "this" scope object for scripts. */

private final Object scope;

private final String variable;

/*** Private constructor. */

private ScriptRunner(Object scope, String variable) {

this.scope = scope;

this.variable = variable;

}

/*** Creates a new instance for the given scope object. */

public static ScriptRunner newInstance(Object scope, String variable) {

return new ScriptRunner(scope, variable);

}

/***

* Runs the specified Jython script. First runs the initialization script. to

* preload the appropriate client library version.

*/

public static void run(String scriptfilename) {

try {

initPython();

PythonInterpreter python = new PythonInterpreter();

python.execfile(scriptfilename);

} catch(Exception e) {

e.printStackTrace();

}

}

/*** Initialize the python interpreter. */

private static void initPython() {

Properties props = new Properties();

// Default is 'message' which displays sys-package-mgr bloat

// Choose one of error,warning,message,comment,debug

props.setProperty("python.verbose", "error");

props.setProperty("python.path", System.getProperty("java.class.path"));

PythonInterpreter.initialize(System.getProperties(), props, new String[] {""});

}

/***

* Create and run a console using a new python interpreter for the test

* associated with this instance.

*/

public void console() throws IOException {

initPython();

InteractiveConsole python = new InteractiveConsole();

initInterpreter(python, scope, variable);

python.interact();

}

/***

* Start an interactive python interpreter using the specified set of local

* variables. Use this to interrupt a running test script. with a prompt:

*

* @param locals

*/

public static void console(PyObject locals) {

initPython();

InteractiveConsole python = new InteractiveConsole(locals);

python.interact();

}

/***

* Initialize a python interpreter.

*

* @param python

* @param scope

* @throws IOException

*/

public static void initInterpreter(PythonInterpreter python, Object scope, String variable)

throws IOException {

// Store the current test case as the this variable

python.set(variable, scope);

}

}

TAG:

我来说两句

显示全部

d8a3dac35532145b347031a8fb402eba.gif

4d73fc83cb27b31041650c043e06fdc8.gif

5d06f4dc9b08a7e1fecdedaf9fe87c66.gif

659391f05d11818e0d3bd694a6d99ddc.gif

f27d7d9f67d98cc858fe74ff4d76554e.gif

b0d82b880d66765dd2a1af173b20f406.gif

e87f042c31e114675541bb49e0fbf138.gif

97a372eda248bf63679ecf2d47467589.gif

a14a392968e29ace4cb2ca390d53264e.gif

ff31a40db0d852c3704276b17a1dd158.gif

46298ad80746c3790e9535ce3396efec.gif

ef97f2303f935b723744c0c99db267f8.gif

46add61d58ae5b455d8994b1485357d3.gif

701ffdce43c5ac45c241dba6a7ae431d.gif

4ac0c1a50de5d21a8087006d0295547a.gif

e54bbadbdbb00b0b5cc4182352ca2352.gif

afb655844bdfda4cf47fef6d239f009d.gif

bf5c12b671f1179ba425de53370ebd3d.gif

865ad24093d248b0ec3b85ea66a6aaa7.gif

ab80f8b6419577f8a8ad7bb690794024.gif

内容

昵称

验证

ada834077f6a48ad60a11ec0354fde86.png

提交评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值