Search in sources :

Example 1 with RemoteSdkCredentials

use of com.intellij.remote.RemoteSdkCredentials 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 2 with RemoteSdkCredentials

use of com.intellij.remote.RemoteSdkCredentials in project intellij-community by JetBrains.

the class PyRemotePackageManagerImpl method getHelperPath.

@Nullable
@Override
protected String getHelperPath(String helper) throws ExecutionException {
    final Sdk sdk = getSdk();
    final SdkAdditionalData sdkData = sdk.getSdkAdditionalData();
    if (sdkData instanceof PyRemoteSdkAdditionalDataBase) {
        final PyRemoteSdkAdditionalDataBase remoteSdkData = (PyRemoteSdkAdditionalDataBase) sdkData;
        try {
            String helpersPath;
            if (CaseCollector.useRemoteCredentials(remoteSdkData)) {
                final RemoteSdkCredentials remoteSdkCredentials = remoteSdkData.getRemoteSdkCredentials(false);
                helpersPath = remoteSdkCredentials.getHelpersPath();
            } else {
                helpersPath = remoteSdkData.getHelpersPath();
            }
            if (!StringUtil.isEmpty(helpersPath)) {
                return new RemoteFile(helpersPath, helper).getPath();
            } else {
                return null;
            }
        } catch (InterruptedException e) {
            LOG.error(e);
        } catch (ExecutionException e) {
            throw analyzeException(e, helper, Collections.<String>emptyList());
        }
    }
    return null;
}
Also used : PyRemoteSdkAdditionalDataBase(com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException) RemoteFile(com.intellij.remote.RemoteFile) RemoteSdkAdditionalData(com.intellij.remote.RemoteSdkAdditionalData) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData) RemoteSdkCredentials(com.intellij.remote.RemoteSdkCredentials) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ExecutionException (com.intellij.execution.ExecutionException)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 SdkAdditionalData (com.intellij.openapi.projectRoots.SdkAdditionalData)2 RemoteSdkAdditionalData (com.intellij.remote.RemoteSdkAdditionalData)2 RemoteSdkCredentials (com.intellij.remote.RemoteSdkCredentials)2 PyRemoteSdkAdditionalDataBase (com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase)2 Nullable (org.jetbrains.annotations.Nullable)2 Function (com.google.common.base.Function)1 ProcessOutput (com.intellij.execution.process.ProcessOutput)1 RemoteFile (com.intellij.remote.RemoteFile)1 PyRemotePathMapper (com.jetbrains.python.remote.PyRemotePathMapper)1 PythonRemoteInterpreterManager (com.jetbrains.python.remote.PythonRemoteInterpreterManager)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1