@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; }
@Override protected Process createProcess() throws ExecutionException { if (PySdkUtil.isRemote(mySdk)) { PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance(); if (manager != null) { return createRemoteConsoleProcess( manager, myCommandLineArgumentsProvider.getArguments(), myCommandLineArgumentsProvider.getAdditionalEnvs()); } throw new PythonRemoteInterpreterManager.PyRemoteInterpreterExecutionException(); } else { myCommandLine = myCommandLineArgumentsProvider.getCommandLineString(); Map<String, String> envs = myCommandLineArgumentsProvider.getAdditionalEnvs(); if (envs != null) { EncodingEnvironmentUtil.fixDefaultEncodingIfMac(envs, getProject()); } final Process server = ProcessRunner.createProcess( getWorkingDir(), envs, myCommandLineArgumentsProvider.getArguments()); try { myPydevConsoleCommunication = new PydevConsoleCommunication(getProject(), myPorts[0], server, myPorts[1]); } catch (Exception e) { throw new ExecutionException(e.getMessage()); } return server; } }
@Override public void run(@NotNull Sdk sdk) { final PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance(); if (manager != null) { try { manager.runVagrant(myVagrantFolder, myMachineName); PythonSdkType.getInstance().setupSdkPaths(sdk); } catch (ExecutionException e) { throw new RuntimeException(e); } } }
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); } } }
@Override protected VirtualFile[] doAddItems() { Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myPanel)); try { String[] files = PythonRemoteInterpreterManager.getInstance() .chooseRemoteFiles( project, (PyRemoteSdkAdditionalDataBase) mySdk.getSdkAdditionalData(), false); final String sourcesLocalPath = PySdkUtil.getRemoteSourcesLocalPath(mySdk.getHomePath()); VirtualFile[] vFiles = new VirtualFile[files.length]; int i = 0; for (String file : files) { String localRoot = PyRemoteSourceItem.localPathForRemoteRoot(sourcesLocalPath, file); myNewMappings.add(new PathMappingSettings.PathMapping(localRoot, file)); myRemoteSdkData.getPathMappings().addMappingCheckUnique(localRoot, file); if (!new File(localRoot).exists()) { new File(localRoot).mkdirs(); } vFiles[i++] = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(localRoot)); } vFiles = adjustAddedFileSet(myPanel, vFiles); List<VirtualFile> added = new ArrayList<VirtualFile>(vFiles.length); for (VirtualFile vFile : vFiles) { if (addElement(vFile)) { added.add(vFile); } } return VfsUtilCore.toVirtualFileArray(added); } catch (Exception e) { LOG.error(e); } return new VirtualFile[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); } }