Search in sources :

Example 1 with PythonRemoteInterpreterManager

use of com.jetbrains.python.remote.PythonRemoteInterpreterManager 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;
}
Also used : PyRemotePathMapper(com.jetbrains.python.remote.PyRemotePathMapper) PathMappingSettings(com.intellij.util.PathMappingSettings) PythonRemoteInterpreterManager(com.jetbrains.python.remote.PythonRemoteInterpreterManager) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with PythonRemoteInterpreterManager

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

the class PydevConsoleRunnerImpl method createProcess.

private Process createProcess() throws ExecutionException {
    if (PySdkUtil.isRemote(mySdk)) {
        PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();
        if (manager != null) {
            UsageTrigger.trigger(CONSOLE_FEATURE + ".remote");
            return createRemoteConsoleProcess(manager, myGeneralCommandLine.getParametersList().getArray(), myGeneralCommandLine.getEnvironment(), myGeneralCommandLine.getWorkDirectory());
        }
        throw new PythonRemoteInterpreterManager.PyRemoteInterpreterExecutionException();
    } else {
        myCommandLine = myGeneralCommandLine.getCommandLineString();
        Map<String, String> envs = myGeneralCommandLine.getEnvironment();
        EncodingEnvironmentUtil.setLocaleEnvironmentIfMac(envs, myGeneralCommandLine.getCharset());
        UsageTrigger.trigger(CONSOLE_FEATURE + ".local");
        final Process server = myGeneralCommandLine.createProcess();
        try {
            myPydevConsoleCommunication = new PydevConsoleCommunication(myProject, myPorts[0], server, myPorts[1]);
        } catch (Exception e) {
            throw new ExecutionException(e.getMessage());
        }
        return server;
    }
}
Also used : RemoteProcess(com.intellij.remote.RemoteProcess) XDebugProcess(com.intellij.xdebugger.XDebugProcess) ExecutionException(com.intellij.execution.ExecutionException) PythonRemoteInterpreterManager(com.jetbrains.python.remote.PythonRemoteInterpreterManager) XmlRpcException(org.apache.xmlrpc.XmlRpcException) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException)

Example 3 with PythonRemoteInterpreterManager

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

the class PythonSdkDetailsDialog method editRemoteSdk.

private void editRemoteSdk(Sdk currentSdk) {
    PythonRemoteInterpreterManager remoteInterpreterManager = PythonRemoteInterpreterManager.getInstance();
    if (remoteInterpreterManager != null) {
        final SdkModificator modificator = myModificators.get(currentSdk);
        Set<Sdk> existingSdks = Sets.newHashSet(myProjectSdksModel.getSdks());
        existingSdks.remove(currentSdk);
        if (remoteInterpreterManager.editSdk(myProject, modificator, existingSdks)) {
            myModifiedModificators.add(modificator);
        }
    }
}
Also used : Sdk(com.intellij.openapi.projectRoots.Sdk) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator) PythonRemoteInterpreterManager(com.jetbrains.python.remote.PythonRemoteInterpreterManager)

Example 4 with PythonRemoteInterpreterManager

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

the class PyRemoteProcessStarter method startRemoteProcess.

public ProcessHandler startRemoteProcess(@NotNull Sdk sdk, @NotNull GeneralCommandLine commandLine, @Nullable Project project, @Nullable PyRemotePathMapper pathMapper) throws ExecutionException {
    PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();
    if (manager != null) {
        PyRemoteProcessHandlerBase processHandler;
        try {
            processHandler = doStartRemoteProcess(sdk, commandLine, manager, project, pathMapper);
        } catch (ExecutionException e) {
            final Application application = ApplicationManager.getApplication();
            if (application != null && (application.isUnitTestMode() || application.isHeadlessEnvironment())) {
                throw new RuntimeException(e);
            }
            throw new ExecutionException("Can't run remote python interpreter: " + e.getMessage(), e);
        }
        ProcessTerminatedListener.attach(processHandler);
        return processHandler;
    } else {
        throw new PythonRemoteInterpreterManager.PyRemoteInterpreterExecutionException();
    }
}
Also used : PyRemoteProcessHandlerBase(com.jetbrains.python.remote.PyRemoteProcessHandlerBase) ExecutionException(com.intellij.execution.ExecutionException) PythonRemoteInterpreterManager(com.jetbrains.python.remote.PythonRemoteInterpreterManager) Application(com.intellij.openapi.application.Application)

Example 5 with PythonRemoteInterpreterManager

use of com.jetbrains.python.remote.PythonRemoteInterpreterManager 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)

Aggregations

PythonRemoteInterpreterManager (com.jetbrains.python.remote.PythonRemoteInterpreterManager)10 ExecutionException (com.intellij.execution.ExecutionException)5 Sdk (com.intellij.openapi.projectRoots.Sdk)3 PyRemoteSdkAdditionalDataBase (com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase)3 Nullable (org.jetbrains.annotations.Nullable)3 RemoteProcess (com.intellij.remote.RemoteProcess)2 PyRemotePathMapper (com.jetbrains.python.remote.PyRemotePathMapper)2 IOException (java.io.IOException)2 NotNull (org.jetbrains.annotations.NotNull)2 Function (com.google.common.base.Function)1 ProcessOutput (com.intellij.execution.process.ProcessOutput)1 Notification (com.intellij.notification.Notification)1 NotificationListener (com.intellij.notification.NotificationListener)1 Application (com.intellij.openapi.application.Application)1 SdkAdditionalData (com.intellij.openapi.projectRoots.SdkAdditionalData)1 SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)1 RemoteSdkAdditionalData (com.intellij.remote.RemoteSdkAdditionalData)1 RemoteSdkCredentials (com.intellij.remote.RemoteSdkCredentials)1 PathMappingSettings (com.intellij.util.PathMappingSettings)1 XDebugProcess (com.intellij.xdebugger.XDebugProcess)1