@Override public List<String> getAllRepositories() { List<String> result = new ArrayList<String>(); result.add(PyPIPackageUtil.PYPI_URL); result.addAll(PyPackageService.getInstance().additionalRepositories); return result; }
@Override public void uninstallPackages(List<InstalledPackage> installedPackages, final Listener listener) { final String packageName = installedPackages.size() == 1 ? installedPackages.get(0).getName() : null; PyPackageManagerUI ui = new PyPackageManagerUI( myProject, mySdk, new PyPackageManagerUI.Listener() { @Override public void started() { listener.operationStarted(packageName); } @Override public void finished(final List<PyExternalProcessException> exceptions) { listener.operationFinished(packageName, toErrorDescription(exceptions)); } }); List<PyPackage> pyPackages = new ArrayList<PyPackage>(); for (InstalledPackage aPackage : installedPackages) { if (aPackage instanceof PyPackage) { pyPackages.add((PyPackage) aPackage); } } ui.uninstall(pyPackages); }
private static List<RepoPackage> versionMapToPackageList( Map<String, String> packageToVersionMap) { final boolean customRepoConfigured = !PyPackageService.getInstance().additionalRepositories.isEmpty(); String url = customRepoConfigured ? PyPIPackageUtil.PYPI_URL : ""; List<RepoPackage> packages = new ArrayList<RepoPackage>(); for (Map.Entry<String, String> entry : packageToVersionMap.entrySet()) { packages.add(new RepoPackage(entry.getKey(), url, entry.getValue())); } return packages; }
@Override public List<RepoPackage> getAllPackages() throws IOException { final Map<String, String> packageToVersionMap; try { packageToVersionMap = PyPIPackageUtil.INSTANCE.loadAndGetPackages(); } catch (IOException e) { throw new IOException( "Could not reach URL " + e.getMessage() + ". Please, check your internet connection."); } List<RepoPackage> packages = versionMapToPackageList(packageToVersionMap); packages.addAll(PyPIPackageUtil.INSTANCE.getAdditionalPackageNames()); return packages; }
@Override public void installPackage( final RepoPackage repoPackage, String version, boolean forceUpgrade, String extraOptions, final Listener listener, boolean installToUser) { final String packageName = repoPackage.getName(); final String repository = PyPIPackageUtil.PYPI_URL.equals(repoPackage.getRepoUrl()) ? null : repoPackage.getRepoUrl(); final List<String> extraArgs = new ArrayList<String>(); if (installToUser) { extraArgs.add(PyPackageManager.USE_USER_SITE); } if (extraOptions != null) { // TODO: Respect arguments quotation Collections.addAll(extraArgs, extraOptions.split(" +")); } if (!StringUtil.isEmptyOrSpaces(repository)) { extraArgs.add("--extra-index-url"); extraArgs.add(repository); } if (forceUpgrade) { extraArgs.add("-U"); } final PyRequirement req; if (version != null) { req = new PyRequirement(packageName, version); } else { req = new PyRequirement(packageName); } final PyPackageManagerUI ui = new PyPackageManagerUI( myProject, mySdk, new PyPackageManagerUI.Listener() { @Override public void started() { listener.operationStarted(packageName); } @Override public void finished(@Nullable List<PyExternalProcessException> exceptions) { listener.operationFinished(packageName, toErrorDescription(exceptions)); } }); ui.install(Collections.singletonList(req), extraArgs); }
private String toErrorDescription(List<PyExternalProcessException> exceptions) { String errorDescription = null; if (exceptions != null && exceptions.size() > 0) { errorDescription = PyPackageManagerUI.createDescription(exceptions, ""); } return errorDescription; }