Search in sources :

Example 1 with PyRemoteSdkAdditionalDataBase

use of com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase 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);
    }
}
Also used : PyRemotePathMapper(com.jetbrains.python.remote.PyRemotePathMapper) Tunnelable(com.intellij.remote.Tunnelable) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) PyRemoteSdkAdditionalDataBase(com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase) RemoteProcess(com.intellij.remote.RemoteProcess) ExecutionException(com.intellij.execution.ExecutionException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) File(java.io.File) PsiFile(com.intellij.psi.PsiFile) XmlRpcException(org.apache.xmlrpc.XmlRpcException) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException)

Example 2 with PyRemoteSdkAdditionalDataBase

use of com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase in project intellij-community by JetBrains.

the class PythonSdkType method getVersionString.

@Nullable
@Override
public String getVersionString(@NotNull Sdk sdk) {
    if (isRemote(sdk)) {
        final PyRemoteSdkAdditionalDataBase data = (PyRemoteSdkAdditionalDataBase) sdk.getSdkAdditionalData();
        assert data != null;
        String versionString = data.getVersionString();
        if (StringUtil.isEmpty(versionString)) {
            final PythonRemoteInterpreterManager remoteInterpreterManager = PythonRemoteInterpreterManager.getInstance();
            if (remoteInterpreterManager != null) {
                try {
                    versionString = remoteInterpreterManager.getInterpreterVersion(null, data);
                } catch (Exception e) {
                    LOG.warn("Couldn't get interpreter version:" + e.getMessage(), e);
                    versionString = "undefined";
                }
            }
            data.setVersionString(versionString);
        }
        return versionString;
    } else {
        return getVersionString(sdk.getHomePath());
    }
}
Also used : PyRemoteSdkAdditionalDataBase(com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase) PythonRemoteInterpreterManager(com.jetbrains.python.remote.PythonRemoteInterpreterManager) ExecutionException(com.intellij.execution.ExecutionException) IOException(java.io.IOException) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with PyRemoteSdkAdditionalDataBase

use of com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase in project intellij-community by JetBrains.

the class PyRemoteLibrariesNode method create.

@Nullable
public static PyRemoteLibrariesNode create(@NotNull Project project, @NotNull Sdk sdk, ViewSettings settings) {
    if (sdk.getSdkAdditionalData() instanceof PyRemoteSdkAdditionalDataBase) {
        VirtualFile remoteLibrary = PySdkUtil.findAnyRemoteLibrary(sdk);
        if (remoteLibrary != null && remoteLibrary.getFileType() instanceof ArchiveFileType) {
            remoteLibrary = JarFileSystem.getInstance().getLocalVirtualFileFor(remoteLibrary);
        }
        if (remoteLibrary != null) {
            final VirtualFile remoteLibraries = remoteLibrary.getParent();
            final PsiDirectory remoteLibrariesDirectory = PsiManager.getInstance(project).findDirectory(remoteLibraries);
            return new PyRemoteLibrariesNode(sdk, project, remoteLibrariesDirectory, settings);
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArchiveFileType(com.intellij.ide.highlighter.ArchiveFileType) PyRemoteSdkAdditionalDataBase(com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with PyRemoteSdkAdditionalDataBase

use of com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase 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);
    }
}
Also used : ArrayList(java.util.ArrayList) PyRemoteSdkAdditionalDataBase(com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase) PythonRemoteInterpreterManager(com.jetbrains.python.remote.PythonRemoteInterpreterManager) PyRemotePathMapper(com.jetbrains.python.remote.PyRemotePathMapper) Function(com.google.common.base.Function) ProcessOutput(com.intellij.execution.process.ProcessOutput) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable) RemoteSdkAdditionalData(com.intellij.remote.RemoteSdkAdditionalData) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData) RemoteSdkCredentials(com.intellij.remote.RemoteSdkCredentials) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with PyRemoteSdkAdditionalDataBase

use of com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase in project intellij-community by JetBrains.

the class PythonSdkUpdater method getRemoteSdkMappedPaths.

/**
   * Returns local paths for a remote SDK that have been mapped to remote paths during the skeleton refresh step.
   *
   * Returns all the existing paths except those manually excluded by the user.
   */
@NotNull
private static List<VirtualFile> getRemoteSdkMappedPaths(@NotNull Sdk sdk, @Nullable Project project) {
    final SdkAdditionalData additionalData = sdk.getSdkAdditionalData();
    if (additionalData instanceof PyRemoteSdkAdditionalDataBase) {
        final PyRemoteSdkAdditionalDataBase remoteSdkData = (PyRemoteSdkAdditionalDataBase) additionalData;
        final List<String> paths = Lists.newArrayList();
        for (PathMappingSettings.PathMapping mapping : remoteSdkData.getPathMappings().getPathMappings()) {
            paths.add(mapping.getLocalRoot());
        }
        return filterRootPaths(sdk, paths, project);
    }
    return Collections.emptyList();
}
Also used : PathMappingSettings(com.intellij.util.PathMappingSettings) PyRemoteSdkAdditionalDataBase(com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PyRemoteSdkAdditionalDataBase (com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase)8 ExecutionException (com.intellij.execution.ExecutionException)5 SdkAdditionalData (com.intellij.openapi.projectRoots.SdkAdditionalData)4 Nullable (org.jetbrains.annotations.Nullable)4 PyRemotePathMapper (com.jetbrains.python.remote.PyRemotePathMapper)3 PythonRemoteInterpreterManager (com.jetbrains.python.remote.PythonRemoteInterpreterManager)3 Sdk (com.intellij.openapi.projectRoots.Sdk)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 RemoteProcess (com.intellij.remote.RemoteProcess)2 RemoteSdkAdditionalData (com.intellij.remote.RemoteSdkAdditionalData)2 RemoteSdkCredentials (com.intellij.remote.RemoteSdkCredentials)2 IOException (java.io.IOException)2 NotNull (org.jetbrains.annotations.NotNull)2 Function (com.google.common.base.Function)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 ProcessOutput (com.intellij.execution.process.ProcessOutput)1 ArchiveFileType (com.intellij.ide.highlighter.ArchiveFileType)1 PsiFile (com.intellij.psi.PsiFile)1 RemoteFile (com.intellij.remote.RemoteFile)1 Tunnelable (com.intellij.remote.Tunnelable)1