Examples of PythonInterpreter


Examples of org.python.util.PythonInterpreter

        putPythonProperty( PYTHON_HOME, props);
        putPythonProperty( PYTHON_PATH, props);
        PythonInterpreter.initialize( System.getProperties(), props, new String[0] );

        interpreter = new PythonInterpreter(null, new PySystemState());
        interpreter.setErr( new LogWriter( Level.SEVERE ) );
        interpreter.setOut( new LogWriter( Level.INFO ) );
//        PySystemState sys = Py.getSystemState();
//        sys.path.append(new PyString(rootPath));
        return true;
View Full Code Here

Examples of org.python.util.PythonInterpreter

   *
   * @throws Exception
   */
  private GameScript() throws Exception {
    conf = Configuration.getConfiguration();
    interpreter = new PythonInterpreter();
    interpreter.execfile(conf.get("python_script"));
  }
View Full Code Here

Examples of org.python.util.PythonInterpreter

        if (f.exists())
        {
            try
            {
                // We try to open the Py Interpreter
                PythonInterpreter interp = new PythonInterpreter();

                // Make sure the Py Interpreter use the right classloader
                // This is necessary for servlet engines generally has
                // their own classloader implementations and servlets aren't
                // loaded in the system classloader.  The python script will
                // load java package
                // org.apache.turbine.services.assemblerbroker.util.python;
                // the new classes to it as well.
                Py.getSystemState().setClassLoader(
                        this.getClass().getClassLoader());

                // We import the Python SYS module. Now we don't need to do this
                // explicitely in the script.  We always use the sys module to
                // do stuff like loading java package
                // org.apache.turbine.services.assemblerbroker.util.python;
                interp.exec("import sys");

                // Now we try to load the script file
                interp.execfile(confName);
                interp.execfile(fName.toString());

                try
                {
                    // We create an instance of the screen class from the
                    // python script
                    interp.exec("scr = " + name + "()");
                }
                catch (Throwable e)
                {
                    throw new Exception(
                        "\nCannot create an instance of the python class.\n"
                        + "You probably gave your class the wrong name.\n"
                        + "Your class should have the same name as your "
                        + "filename.\nFilenames should be all lowercase and "
                        + "classnames should start with a capital.\n"
                        + "Expected class name: " + name + "\n");
                }

                // Here we convert the python sceen instance to a java instance.
                assembler = (Assembler) interp.get("scr", Assembler.class);
            }
            catch (Exception e)
            {
                // We log the error here because this code is not widely tested
                // yet. After we tested the code on a range of platforms this
View Full Code Here

Examples of org.python.util.PythonInterpreter

        .getContextClassLoader();
    try {
      Thread.currentThread().setContextClassLoader(
          getClass().getClassLoader());

      interp = new PythonInterpreter();
      // interp.initialize(System.getProperties(), null, null);

    } finally {
      Thread.currentThread().setContextClassLoader(oldClassLoader);
    }
View Full Code Here

Examples of org.python.util.PythonInterpreter

    public RunnerFactory() {
        runnerClass = importRunnerClass();
    }

    private PyObject importRunnerClass() {
        PythonInterpreter interpreter = new PythonInterpreter();
        interpreter.exec("import robot; from robot.jarrunner import JarRunner");
        return interpreter.get("JarRunner");
    }
View Full Code Here

Examples of org.python.util.PythonInterpreter

                return;
            }
        }

        File classesDir = new File(basedir, "target/classes");
        PythonInterpreter interp = new PythonInterpreter();

        interp.exec(
        "import sys\n"+
        "sys.path.insert(0,\""+classesDir.getCanonicalPath()+"\")\n"+
        "sys.path.insert(0,\""+testDir.getCanonicalPath()+"\")\n"
        );

        try
        {
            interp.execfile(new File(testDir, "proton-test").getCanonicalPath());
        }
        catch (PyException e)
        {
            if( e.type.toString().equals("<type 'exceptions.SystemExit'>") && e.value.toString().equals("0") )
            {
View Full Code Here

Examples of org.python.util.PythonInterpreter

    return new CompiledPythonScript(scriptName, scriptCode);
  }

  public void check(String scriptCode) throws ScriptCompilerException
  {
    PythonInterpreter interpreter = new PythonInterpreter();
    interpreter.eval(scriptCode);
  }
View Full Code Here

Examples of org.python.util.PythonInterpreter

    @Override
    public Object execute(String methodName, Object... args)
      throws ScriptMethodNotFoundException, ScriptExecutionException
    {
      PythonInterpreter interpreter = new PythonInterpreter();
      interpreter.eval(script);
      interpreter.eval(methodName + "ReturnValue = " + methodName + "(" + StringTools.concatWithDelimiter(args, ",") +
              ")");
      return interpreter.get(methodName + "ReturnValue");
    }
View Full Code Here

Examples of org.python.util.PythonInterpreter

    @Override
    public void registerFunctions(String path, String namespace, PigContext pigContext)
    throws IOException{
        Interpreter.init(path);
        pigContext.scriptJars.add(getJarPath(PythonInterpreter.class));
        PythonInterpreter pi = Interpreter.interpreter;
        @SuppressWarnings("unchecked")
        List<PyTuple> locals = (List<PyTuple>) ((PyStringMap) pi.getLocals()).items();
        if(namespace == null) {
            namespace = "";
        }
        else {
            namespace = namespace + namespaceSeparator;
View Full Code Here

Examples of org.python.util.PythonInterpreter

            properties.setProperty("python.home", workDir.toString());
            properties.setProperty("python.packages.fakepath",
                    (String)avalonContext.get(Constants.CONTEXT_CLASSPATH));
            PythonInterpreter.initialize(System.getProperties(), properties, new String[]{});

            python = new PythonInterpreter();
            python.set("page", this);
            python.set("logger", getLogger());
            python.set("xspAttr", new AttributesImpl());
       
            if (getLogger().isDebugEnabled()) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.