Added Jython library and added Scripts class for executing Jython scripts

This commit is contained in:
Waverunner
2014-12-17 13:08:30 -05:00
parent 38c0923684
commit 2f7add2fa7
3 changed files with 62 additions and 0 deletions

View File

@@ -4,5 +4,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry combineaccessrules="false" kind="src" path="/Engine3"/>
<classpathentry kind="lib" path="lib/jdbc-postgresql.jar"/>
<classpathentry kind="lib" path="lib/jython-standalone-2.5.4-rc1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

Binary file not shown.

View File

@@ -0,0 +1,61 @@
package resources.utilities;
import java.io.File;
import org.python.core.Py;
import org.python.util.PythonInterpreter;
public final class Scripts {
private static final String SCRIPTS_PATH = "scripts/";
// TODO: Variable arguments?
public static void execute(String script, String method) {
if (!scriptExists(script))
return;
PythonInterpreter interp = new PythonInterpreter();
interp.execfile(SCRIPTS_PATH + script);
interp.get(method).__call__();
}
public static void execute(String script, String method, Object arg1) {
if (!scriptExists(script))
return;
PythonInterpreter interp = new PythonInterpreter();
interp.execfile(SCRIPTS_PATH + script);
interp.get(method).__call__(Py.java2py(arg1));
}
public static void execute(String script, String method, Object arg1, Object arg2) {
if (!scriptExists(script))
return;
PythonInterpreter interp = new PythonInterpreter();
interp.execfile(SCRIPTS_PATH + script);
interp.get(method).__call__(Py.java2py(arg1), Py.java2py(arg2));
}
public static void execute(String script, String method, Object arg1, Object arg2, Object arg3) {
if (!scriptExists(script))
return;
PythonInterpreter interp = new PythonInterpreter();
interp.execfile(SCRIPTS_PATH + script);
interp.get(method).__call__(Py.java2py(arg1), Py.java2py(arg2), Py.java2py(arg3));
}
public static void execute(String script, String method, Object arg1, Object arg2, Object arg3, Object arg4) {
if (!scriptExists(script))
return;
PythonInterpreter interp = new PythonInterpreter();
interp.execfile(SCRIPTS_PATH + script);
interp.get(method).__call__(Py.java2py(arg1), Py.java2py(arg2), Py.java2py(arg3), Py.java2py(arg4));
}
private static boolean scriptExists(String file) {
return new File(file).exists();
}
}