use of com.jetbrains.python.remote.PyRemotePathMapper in project intellij-community by JetBrains.
the class PydevConsoleRunner method getPathMapper.
@Nullable
static PyRemotePathMapper getPathMapper(@NotNull Project project, Sdk sdk, PyConsoleOptions.PyConsoleSettings consoleSettings) {
if (PySdkUtil.isRemote(sdk)) {
PythonRemoteInterpreterManager instance = PythonRemoteInterpreterManager.getInstance();
if (instance != null) {
//noinspection ConstantConditions
PyRemotePathMapper remotePathMapper = instance.setupMappings(project, (PyRemoteSdkAdditionalDataBase) sdk.getSdkAdditionalData(), null);
PathMappingSettings mappingSettings = consoleSettings.getMappingSettings();
remotePathMapper.addAll(mappingSettings.getPathMappings(), PyRemotePathMapper.PyPathMappingType.USER_DEFINED);
return remotePathMapper;
}
}
return null;
}
use of com.jetbrains.python.remote.PyRemotePathMapper in project intellij-community by JetBrains.
the class PydevConsoleRunnerImpl method createRemoteConsoleProcess.
private RemoteProcess createRemoteConsoleProcess(PythonRemoteInterpreterManager manager, String[] command, Map<String, String> env, File workDirectory) throws ExecutionException {
PyRemoteSdkAdditionalDataBase data = (PyRemoteSdkAdditionalDataBase) mySdk.getSdkAdditionalData();
assert data != null;
GeneralCommandLine commandLine = new GeneralCommandLine();
commandLine.setWorkDirectory(workDirectory);
commandLine.withParameters(command);
commandLine.getEnvironment().putAll(env);
commandLine.getParametersList().set(0, PythonRemoteInterpreterManager.toSystemDependent(new File(data.getHelpersPath(), getRunnerFileFromHelpers()).getPath(), PySourcePosition.isWindowsPath(data.getInterpreterPath())));
commandLine.getParametersList().set(1, "0");
commandLine.getParametersList().set(2, "0");
try {
PyRemotePathMapper pathMapper = PydevConsoleRunner.getPathMapper(myProject, mySdk, myConsoleSettings);
assert pathMapper != null;
commandLine.putUserData(PyRemoteProcessStarter.OPEN_FOR_INCOMING_CONNECTION, true);
// we do not have an option to setup Docker container settings now for Python console so we should bind at least project
// directory to some path inside the Docker container
commandLine.putUserData(PythonRemoteInterpreterManager.ADDITIONAL_MAPPINGS, buildDockerPathMappings());
myRemoteProcessHandlerBase = PyRemoteProcessStarterManagerUtil.getManager(data).startRemoteProcess(myProject, commandLine, manager, data, pathMapper);
myCommandLine = myRemoteProcessHandlerBase.getCommandLine();
RemoteProcess remoteProcess = myRemoteProcessHandlerBase.getProcess();
Couple<Integer> remotePorts = getRemotePortsFromProcess(remoteProcess);
if (remoteProcess instanceof Tunnelable) {
Tunnelable tunnelableProcess = (Tunnelable) remoteProcess;
tunnelableProcess.addLocalTunnel(myPorts[0], remotePorts.first);
tunnelableProcess.addRemoteTunnel(remotePorts.second, "localhost", myPorts[1]);
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Using tunneled communication for Python console: port %d (=> %d) on IDE side, " + "port %d (=> %d) on pydevconsole.py side", myPorts[1], remotePorts.second, myPorts[0], remotePorts.first));
}
myPydevConsoleCommunication = new PydevRemoteConsoleCommunication(myProject, myPorts[0], remoteProcess, myPorts[1]);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Using direct communication for Python console: port %d on IDE side, port %d on pydevconsole.py side", remotePorts.second, remotePorts.first));
}
myPydevConsoleCommunication = new PydevRemoteConsoleCommunication(myProject, remotePorts.first, remoteProcess, remotePorts.second);
}
return remoteProcess;
} catch (Exception e) {
throw new ExecutionException(e.getMessage(), e);
}
}
use of com.jetbrains.python.remote.PyRemotePathMapper in project intellij-community by JetBrains.
the class PyRemotePackageManagerImpl method getPythonProcessOutput.
@NotNull
@Override
protected ProcessOutput getPythonProcessOutput(@NotNull String helperPath, @NotNull List<String> args, boolean askForSudo, boolean showProgress, @Nullable final String workingDir) throws ExecutionException {
final Sdk sdk = getSdk();
final String homePath = sdk.getHomePath();
if (homePath == null) {
throw new ExecutionException("Cannot find Python interpreter for SDK " + sdk.getName());
}
final SdkAdditionalData sdkData = sdk.getSdkAdditionalData();
if (sdkData instanceof PyRemoteSdkAdditionalDataBase) {
//remote interpreter
final PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();
RemoteSdkCredentials remoteSdkCredentials;
if (CaseCollector.useRemoteCredentials((PyRemoteSdkAdditionalDataBase) sdkData)) {
try {
remoteSdkCredentials = ((RemoteSdkAdditionalData) sdkData).getRemoteSdkCredentials(false);
} catch (InterruptedException e) {
LOG.error(e);
remoteSdkCredentials = null;
} catch (ExecutionException e) {
throw analyzeException(e, helperPath, args);
}
if (manager != null && remoteSdkCredentials != null) {
if (askForSudo) {
askForSudo = !manager.ensureCanWrite(null, remoteSdkCredentials, remoteSdkCredentials.getInterpreterPath());
}
} else {
throw new PyExecutionException(PythonRemoteInterpreterManager.WEB_DEPLOYMENT_PLUGIN_IS_DISABLED, helperPath, args);
}
}
if (manager != null) {
final List<String> cmdline = new ArrayList<>();
cmdline.add(homePath);
cmdline.add(RemoteFile.detectSystemByPath(homePath).createRemoteFile(helperPath).getPath());
cmdline.addAll(Collections2.transform(args, new Function<String, String>() {
@Override
public String apply(@Nullable String input) {
return quoteIfNeeded(input);
}
}));
ProcessOutput processOutput;
do {
final PyRemoteSdkAdditionalDataBase remoteSdkAdditionalData = (PyRemoteSdkAdditionalDataBase) sdkData;
final PyRemotePathMapper pathMapper = manager.setupMappings(null, remoteSdkAdditionalData, null);
try {
processOutput = PyRemoteProcessStarterManagerUtil.getManager(remoteSdkAdditionalData).executeRemoteProcess(null, ArrayUtil.toStringArray(cmdline), workingDir, manager, remoteSdkAdditionalData, pathMapper, askForSudo, true);
} catch (InterruptedException e) {
throw new ExecutionException(e);
}
if (askForSudo && processOutput.getStderr().contains("sudo: 3 incorrect password attempts")) {
continue;
}
break;
} while (true);
return processOutput;
} else {
throw new PyExecutionException(PythonRemoteInterpreterManager.WEB_DEPLOYMENT_PLUGIN_IS_DISABLED, helperPath, args);
}
} else {
throw new PyExecutionException("Invalid remote SDK", helperPath, args);
}
}
use of com.jetbrains.python.remote.PyRemotePathMapper in project intellij-community by JetBrains.
the class PyRemoteProcessStarter method doStartRemoteProcess.
protected PyRemoteProcessHandlerBase doStartRemoteProcess(@NotNull Sdk sdk, @NotNull final GeneralCommandLine commandLine, @NotNull final PythonRemoteInterpreterManager manager, @Nullable final Project project, @Nullable PyRemotePathMapper pathMapper) throws ExecutionException {
SdkAdditionalData data = sdk.getSdkAdditionalData();
assert data instanceof PyRemoteSdkAdditionalDataBase;
final PyRemoteSdkAdditionalDataBase pyRemoteSdkAdditionalDataBase = (PyRemoteSdkAdditionalDataBase) data;
final PyRemotePathMapper extendedPathMapper = manager.setupMappings(project, pyRemoteSdkAdditionalDataBase, pathMapper);
try {
return PyRemoteProcessStarterManagerUtil.getManager(pyRemoteSdkAdditionalDataBase).startRemoteProcess(project, commandLine, manager, pyRemoteSdkAdditionalDataBase, extendedPathMapper);
} catch (InterruptedException e) {
throw new ExecutionException(e);
}
}
Aggregations