コード例 #1
0
 @Override
 protected PyConsoleProcessHandler createProcessHandler(final Process process) {
   if (PySdkUtil.isRemote(mySdk)) {
     PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();
     if (manager != null) {
       PyRemoteSdkAdditionalDataBase data =
           (PyRemoteSdkAdditionalDataBase) mySdk.getSdkAdditionalData();
       assert data != null;
       myProcessHandler =
           manager.createConsoleProcessHandler(
               process,
               myRemoteCredentials,
               getConsoleView(),
               myPydevConsoleCommunication,
               myCommandLine,
               CharsetToolkit.UTF8_CHARSET,
               manager.setupMappings(getProject(), data, null));
     } else {
       LOG.error("Can't create remote console process handler");
     }
   } else {
     myProcessHandler =
         new PyConsoleProcessHandler(
             process,
             getConsoleView(),
             myPydevConsoleCommunication,
             myCommandLine,
             CharsetToolkit.UTF8_CHARSET);
   }
   return myProcessHandler;
 }
コード例 #2
0
  private Process createRemoteConsoleProcess(
      PythonRemoteInterpreterManager manager, String[] command, Map<String, String> env)
      throws ExecutionException {
    PyRemoteSdkAdditionalDataBase data =
        (PyRemoteSdkAdditionalDataBase) mySdk.getSdkAdditionalData();
    assert data != null;

    GeneralCommandLine commandLine = new GeneralCommandLine(command);

    commandLine.getEnvironment().putAll(env);

    commandLine
        .getParametersList()
        .set(
            1,
            PythonRemoteInterpreterManager.toSystemDependent(
                new File(data.getHelpersPath(), PYDEV_PYDEVCONSOLE_PY).getPath(),
                PySourcePosition.isWindowsPath(data.getInterpreterPath())));
    commandLine.getParametersList().set(2, "0");
    commandLine.getParametersList().set(3, "0");

    myCommandLine = commandLine.getCommandLineString();

    try {
      myRemoteCredentials = data.getRemoteSdkCredentials(true);
      PathMappingSettings mappings = manager.setupMappings(getProject(), data, null);

      RemoteSshProcess remoteProcess =
          manager.createRemoteProcess(
              getProject(), myRemoteCredentials, mappings, commandLine, true);

      Couple<Integer> remotePorts = getRemotePortsFromProcess(remoteProcess);

      remoteProcess.addLocalTunnel(myPorts[0], myRemoteCredentials.getHost(), remotePorts.first);
      remoteProcess.addRemoteTunnel(remotePorts.second, "localhost", myPorts[1]);

      myPydevConsoleCommunication =
          new PydevRemoteConsoleCommunication(getProject(), myPorts[0], remoteProcess, myPorts[1]);
      return remoteProcess;
    } catch (Exception e) {
      throw new ExecutionException(e.getMessage());
    }
  }
コード例 #3
0
  @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<String>();
        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);
    }
  }