-
-
Save Vanuan/3960023 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
package com.github.vanuan.jython.nailgun; | |
import java.util.Arrays; | |
import org.python.core.Py; | |
import org.python.core.PyList; | |
import org.python.core.PySystemState; | |
import org.python.core.PyType; | |
import org.python.util.PythonInterpreter; | |
import com.martiansoftware.nailgun.NGContext; | |
public class Wrapper { | |
private static PythonInterpreter interpreter = null; | |
public static void nailMain (NGContext context) { | |
if (interpreter == null) { | |
interpreter = new PythonInterpreter(); | |
} 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[] tokens = 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