Thread: [Pydev-cvs] org.python.pydev/src/org/python/pydev/runners SimpleRunner.java, 1.22, 1.23 SimplePytho
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-05-12 11:33:55
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/runners In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv318/src/org/python/pydev/runners Modified Files: SimpleRunner.java SimplePythonRunner.java Log Message: Patch from Felix Schwarz [PATCH] Allow to configure an interpreter even if the workspace path name contains spaces Index: SimpleRunner.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/runners/SimpleRunner.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** SimpleRunner.java 13 Apr 2008 16:55:23 -0000 1.22 --- SimpleRunner.java 12 May 2008 11:34:00 -0000 1.23 *************** *** 304,320 **** } ! /** ! * This is the method that actually does the running (all others are just 'shortcuts' to this one). ! * ! * @param executionString this is the string that will be executed ! * @param workingDir this is the directory where the execution will happen ! * @param project this is the project that is related to the run (it is used to get the environment for the shell we are going to ! * execute with the correct pythonpath environment variable). ! * @param monitor this is the monitor used to communicate the progress to the user ! * ! * @return the string that is the output of the process (stdout) and the stderr (o2) ! */ ! public Tuple<String,String> runAndGetOutput(String executionString, File workingDir, IProject project, IProgressMonitor monitor) { ! monitor.setTaskName("Executing: "+executionString); monitor.worked(5); Process process = null; --- 304,311 ---- } ! ! public Tuple<String, String> runAndGetOutput(String[] arguments, File workingDir, IProject project, IProgressMonitor monitor) { ! String executionString = getCommandLineAsString(arguments); ! monitor.setTaskName("Executing: "+executionString); monitor.worked(5); Process process = null; *************** *** 328,337 **** } } ! process = Runtime.getRuntime().exec(executionString, envp, workingDir); } catch (Exception e) { throw new RuntimeException(e); } ! if (process != null) { try { --- 319,339 ---- } } ! process = Runtime.getRuntime().exec(arguments, envp, workingDir); } catch (Exception e) { throw new RuntimeException(e); } ! return getProcessOutput(process, executionString, monitor); ! } ! ! /** ! * @param process process from where the output should be gotten ! * @param executionString string to execute (only for errors) ! * @param monitor monitor for giving progress ! * @return a tuple with the output of stdout and stderr ! */ ! private Tuple<String, String> getProcessOutput(Process process, ! String executionString, IProgressMonitor monitor) { ! if (process != null) { try { *************** *** 377,380 **** --- 379,416 ---- } return new Tuple<String, String>("","Error creating process - got null process("+ executionString + ")"); //no output + } + + + /** + * This is the method that actually does the running (all others are just 'shortcuts' to this one). + * + * @param executionString this is the string that will be executed + * @param workingDir this is the directory where the execution will happen + * @param project this is the project that is related to the run (it is used to get the environment for the shell we are going to + * execute with the correct pythonpath environment variable). + * @param monitor this is the monitor used to communicate the progress to the user + * + * @return the string that is the output of the process (stdout) and the stderr (o2) + */ + public Tuple<String,String> runAndGetOutput(String executionString, File workingDir, IProject project, IProgressMonitor monitor) { + monitor.setTaskName("Executing: "+executionString); + monitor.worked(5); + Process process = null; + + try { + monitor.setTaskName("Making pythonpath environment..."+executionString); + String[] envp = getEnvironment(PythonNature.getPythonNature(project), null); //should get the environment for the default interpreter and the given project + monitor.setTaskName("Making exec..."+executionString); + if(workingDir != null){ + if(!workingDir.isDirectory()){ + throw new RuntimeException(StringUtils.format("Working dir must be an existing directory (received: %s)", workingDir)); + } + } + process = Runtime.getRuntime().exec(executionString, envp, workingDir); + } catch (Exception e) { + throw new RuntimeException(e); + } + + return getProcessOutput(process, executionString, monitor); } Index: SimplePythonRunner.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/runners/SimplePythonRunner.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** SimplePythonRunner.java 26 Jun 2006 23:40:46 -0000 1.9 --- SimplePythonRunner.java 12 May 2008 11:34:00 -0000 1.10 *************** *** 52,61 **** */ public static String makeExecutableCommandStr(String script, String[] args) { ! String[] s = new String[]{ ! PydevPlugin.getPythonInterpreterManager().getDefaultInterpreter() , ! "-u" , ! script , ! }; ! return getCommandLineAsString(s, args); } --- 52,57 ---- */ public static String makeExecutableCommandStr(String script, String[] args) { ! String interpreter = PydevPlugin.getPythonInterpreterManager().getDefaultInterpreter(); ! String[] s = preparePythonCallParameters(interpreter, script, args); return getCommandLineAsString(s, args); } *************** *** 73,77 **** * @return the stdout of the run (if any) */ ! public Tuple<String,String> runAndGetOutputWithInterpreter(String interpreter, String script, String[] args, File workingDir, IProject project, IProgressMonitor monitor) { monitor.setTaskName("Mounting executable string..."); monitor.worked(5); --- 69,73 ---- * @return the stdout of the run (if any) */ ! public Tuple<String,String> runAndGetOutputWithInterpreter(String interpreter, String script, String[] args, File workingDir, IProject project, IProgressMonitor monitor) { monitor.setTaskName("Mounting executable string..."); monitor.worked(5); *************** *** 82,95 **** } ! String[] s = new String[]{ ! interpreter, ! "-u" , ! script , ! }; ! monitor.worked(1); ! return runAndGetOutput(getCommandLineAsString(s,args), workingDir, project, monitor); } --- 78,106 ---- } ! String[] s = preparePythonCallParameters(interpreter, script, args); monitor.worked(1); ! return runAndGetOutput(s, workingDir, project, monitor); } + /** + * Creates array with what should be passed to Runtime.exec to run python. + * + * @param interpreter interpreter that should do the run + * @param script python script to execute + * @param args additional arguments to pass to python + * @return the created array + */ + private static String[] preparePythonCallParameters(String interpreter, String script, String[] args) { + if (args == null) { + args = new String[0]; + } + + String[] s = new String[3 + args.length]; + s[0] = interpreter; + s[1] = "-u"; + s[2] = script; + System.arraycopy(args, 0, s, 3, args.length); + return s; + } |