Created
October 26, 2012 15:17
-
-
Save vkravets/3959365 to your computer and use it in GitHub Desktop.
Running jython via Nailgun server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JythonNailgun { | |
private static PythonIterpreter interpreter = null; | |
public static void nailMain (NGContext context) { | |
if (interpreter == null) { | |
interpreter = new PythonIterpreter(); | |
} else { | |
Py.setSystemState(new PySystemState()); | |
} | |
PySystemState systemState = interpreter.getSystemState(); | |
systemState.setCurrentWorkingDir(context.getWorkingDirectory()); | |
interpreter.setErr(context.err); | |
interpreter.setIn(context.in); | |
interpreter.setOut(context.out); | |
systemState.argv = new PyList(PyType.fromClass(String.class), Arrays.asList(context.getArgs())); | |
String pythonPath = System.getProperties().getProperty("python.path"); | |
if (pythonPath != null) { | |
String[] tokes = pythonPath.split(context.getPathSeparator()); | |
systemState.path = new PyList(PyType.fromClass(String.class), Arrays.asList(tokens)) | |
} | |
interpreter.execfile(context.getArgs()[0]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment