Merge remote-tracking branch 'origin/master'

This commit is contained in:
Dmitry Jemerov
2012-03-02 19:59:12 +01:00
3 changed files with 68 additions and 60 deletions
@@ -104,9 +104,9 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
public static PydevConsoleRunner createAndRun(@NotNull final Project project,
@NotNull final Sdk sdk,
final PyConsoleType consoleType,
final String projectRoot,
final String workingDirectory,
final String... statements2execute) {
return createAndRun(project, sdk, consoleType, projectRoot, createDefaultEnvironmentVariables(sdk), statements2execute);
return createAndRun(project, sdk, consoleType, workingDirectory, createDefaultEnvironmentVariables(sdk), statements2execute);
}
public static Map<String, String> createDefaultEnvironmentVariables(Sdk sdk) {
@@ -133,10 +133,10 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
public static PydevConsoleRunner createAndRun(@NotNull final Project project,
@NotNull final Sdk sdk,
@NotNull final PyConsoleType consoleType,
@Nullable final String projectRoot,
@Nullable final String workingDirectory,
@NotNull final Map<String, String> environmentVariables,
final String... statements2execute) {
final PydevConsoleRunner consoleRunner = create(project, sdk, consoleType, projectRoot, environmentVariables);
final PydevConsoleRunner consoleRunner = create(project, sdk, consoleType, workingDirectory, environmentVariables);
if (consoleRunner == null) return null;
consoleRunner.run(statements2execute);
return consoleRunner;
@@ -160,14 +160,14 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
public static PydevConsoleRunner create(Project project,
Sdk sdk,
PyConsoleType consoleType,
String projectRoot) {
return create(project, sdk, consoleType, projectRoot, createDefaultEnvironmentVariables(sdk));
String workingDirectory) {
return create(project, sdk, consoleType, workingDirectory, createDefaultEnvironmentVariables(sdk));
}
private static PydevConsoleRunner create(@NotNull Project project,
@NotNull Sdk sdk,
@NotNull PyConsoleType consoleType,
@Nullable String projectRoot,
@Nullable String workingDirectory,
@NotNull final Map<String, String> environmentVariables) {
final int[] ports;
try {
@@ -203,7 +203,7 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
}
};
return new PydevConsoleRunner(project, sdk, consoleType, provider, projectRoot, ports);
return new PydevConsoleRunner(project, sdk, consoleType, provider, workingDirectory, ports);
}
@Override
@@ -220,54 +220,7 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();
if (manager != null) {
try {
PythonRemoteSdkAdditionalData data = (PythonRemoteSdkAdditionalData)mySdk.getSdkAdditionalData();
GeneralCommandLine commandLine = new GeneralCommandLine(myCommandLineArgumentsProvider.getArguments());
commandLine.getParametersList().set(1, PythonRemoteInterpreterManager.toSystemDependent(new File(data.getPyCharmHelpersPath(),
PYDEV_PYDEVCONSOLE_PY)
.getPath(),
PySourcePosition.isWindowsPath(
data.getInterpreterPath())));
commandLine.getParametersList().set(2, "0");
commandLine.getParametersList().set(3, "0");
myCommandLine = commandLine.getCommandLineString();
PyRemoteSshProcess remoteProcess =
manager.createRemoteProcess(getProject(), data, commandLine);
Scanner s = new Scanner(remoteProcess.getInputStream());
boolean received = false;
long started = System.currentTimeMillis();
while (!received && (System.currentTimeMillis() - started < 2000)) {
try {
int port = s.nextInt();
int port2 = s.nextInt();
received = true;
remoteProcess.addLocalTunnel(myPorts[0], data.getHost(), port);
remoteProcess.addRemoteTunnel(port2, "localhost", myPorts[1]);
}
catch (Exception e) {
try {
Thread.sleep(200);
}
catch (InterruptedException e1) {
}
}
}
if (!received) {
throw new ExecutionException("Couldn't get remote ports for console connection.");
}
try {
myPydevConsoleCommunication = new PydevConsoleCommunication(getProject(), myPorts[0], remoteProcess, myPorts[1]);
return remoteProcess;
}
catch (Exception e) {
throw new ExecutionException(e.getMessage());
}
return createRemoteConsoleProcess(manager);
}
catch (final PyRemoteInterpreterException e) {
throw new ExecutionException(e.getMessage(), e);
@@ -289,6 +242,58 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
}
}
private Process createRemoteConsoleProcess(PythonRemoteInterpreterManager manager)
throws PyRemoteInterpreterException, ExecutionException {
PythonRemoteSdkAdditionalData data = (PythonRemoteSdkAdditionalData)mySdk.getSdkAdditionalData();
GeneralCommandLine commandLine = new GeneralCommandLine(myCommandLineArgumentsProvider.getArguments());
commandLine.getParametersList().set(1, PythonRemoteInterpreterManager.toSystemDependent(new File(data.getPyCharmHelpersPath(),
PYDEV_PYDEVCONSOLE_PY)
.getPath(),
PySourcePosition.isWindowsPath(
data.getInterpreterPath())));
commandLine.getParametersList().set(2, "0");
commandLine.getParametersList().set(3, "0");
myCommandLine = commandLine.getCommandLineString();
PyRemoteSshProcess remoteProcess =
manager.createRemoteProcess(getProject(), data, commandLine);
Scanner s = new Scanner(remoteProcess.getInputStream());
boolean received = false;
long started = System.currentTimeMillis();
while (!received && (System.currentTimeMillis() - started < 2000)) {
try {
int port = s.nextInt();
int port2 = s.nextInt();
received = true;
remoteProcess.addLocalTunnel(myPorts[0], data.getHost(), port);
remoteProcess.addRemoteTunnel(port2, "localhost", myPorts[1]);
}
catch (Exception e) {
try {
Thread.sleep(200);
}
catch (InterruptedException e1) {
}
}
}
if (!received) {
throw new ExecutionException("Couldn't get remote ports for console connection.");
}
try {
myPydevConsoleCommunication = new PydevConsoleCommunication(getProject(), myPorts[0], remoteProcess, myPorts[1]);
return remoteProcess;
}
catch (Exception e) {
throw new ExecutionException(e.getMessage());
}
}
@Override
protected PyConsoleProcessHandler createProcessHandler(final Process process) {
myProcessHandler = new PyConsoleProcessHandler(process, getConsoleView(), myPydevConsoleCommunication, myCommandLine,
@@ -35,7 +35,6 @@ public class PythonRunConfiguration extends AbstractPythonRunConfiguration
public static final String SCRIPT_NAME = "SCRIPT_NAME";
public static final String PARAMETERS = "PARAMETERS";
public static final String MULTIPROCESS = "MULTIPROCESS";
private static final String REMOTE_DEBUG_RUN_CONFIGURATION = "REMOTE_DEBUG_RUN_CONFIGURATION";
private String myScriptName;
private String myScriptParameters;
private boolean myMultiprocessMode;
@@ -2,6 +2,7 @@ package com.jetbrains.python.sdk;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.containers.HashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -17,17 +18,19 @@ import java.util.Set;
*/
public class PythonEnvUtil {
public static final String PYTHONPATH = "PYTHONPATH";
public static final String PYTHONUNBUFFERED = "PYTHONUNBUFFERED";
public static final String PYTHONIOENCODING = "PYTHONIOENCODING";
private PythonEnvUtil() {
}
public static Map<String, String> setPythonUnbuffered(@NotNull Map<String, String> envs) {
envs.put("PYTHONUNBUFFERED", "1");
envs.put(PYTHONUNBUFFERED, "1");
return envs;
}
public static Map<String, String> setPythonIOEncoding(@NotNull Map<String, String> envs, @NotNull String encoding) {
envs.put("PYTHONIOENCODING", encoding);
envs.put(PYTHONIOENCODING, encoding);
return envs;
}
@@ -55,7 +58,8 @@ public class PythonEnvUtil {
*/
@NotNull
public static String appendToPathEnvVar(@Nullable String source, @NotNull String value) {
if (source != null) {
if (StringUtil.isEmpty(source)) {
assert source != null;
Set<String> vals = Sets.newHashSet(source.split(File.pathSeparator));
if (!vals.contains(value)) {
return value + File.pathSeparatorChar + source;