feat: Add conda remove (uninstall)

This commit is contained in:
1ambda 2017-01-08 11:20:52 +09:00
parent e539c42a95
commit b1c4c9f460
2 changed files with 27 additions and 0 deletions

View file

@ -45,6 +45,7 @@ public class PythonCondaInterpreter extends Interpreter {
private Pattern activatePattern = Pattern.compile("activate\\s*(.*)");
private Pattern deactivatePattern = Pattern.compile("deactivate");
private Pattern installPattern = Pattern.compile("install\\s*(.*)");
private Pattern uninstallPattern = Pattern.compile("[uninstall|remove]\\s*(.*)");
private Pattern helpPattern = Pattern.compile("help");
private Pattern infoPattern = Pattern.compile("info");
@ -68,6 +69,7 @@ public class PythonCondaInterpreter extends Interpreter {
Matcher activateMatcher = activatePattern.matcher(st);
Matcher createMatcher = createPattern.matcher(st);
Matcher installMatcher = installPattern.matcher(st);
Matcher uninstallMatcher = uninstallPattern.matcher(st);
try {
if (st == null || listEnvPattern.matcher(st).matches()) {
@ -92,6 +94,9 @@ public class PythonCondaInterpreter extends Interpreter {
} else if (installMatcher.matches()) {
String result = runCondaInstall(getRestArgsFromMatcher(installMatcher));
return new InterpreterResult(Code.SUCCESS, Type.HTML, result);
} else if (uninstallMatcher.matches()) {
String result = runCondaUninstall(getRestArgsFromMatcher(uninstallMatcher));
return new InterpreterResult(Code.SUCCESS, Type.HTML, result);
} else if (helpPattern.matcher(st).matches()) {
runCondaHelp(out);
return new InterpreterResult(Code.SUCCESS);
@ -236,6 +241,24 @@ public class PythonCondaInterpreter extends Interpreter {
return wrapCondaBasicOutputStyle("Package Installation", sb.toString());
}
private String runCondaUninstall(List<String> restArgs)
throws IOException, InterruptedException {
restArgs.add(0, "conda");
restArgs.add(1, "uninstall");
restArgs.add(2, "--yes");
StringBuilder sb = new StringBuilder();
int exit = runCommand(sb, restArgs);
if (exit != 0) {
throw new RuntimeException("Failed to execute `" +
StringUtils.join(restArgs, " ") +
"` exited with " + exit);
}
return wrapCondaBasicOutputStyle("Package Uninstallation", sb.toString());
}
private String wrapCondaBasicOutputStyle(String title, String content) {
StringBuilder sb = new StringBuilder();
if (null != title && !title.isEmpty()) {

View file

@ -40,3 +40,7 @@ limitations under the License.
Install
<pre>%python.conda install [PACKAGE NAME]</pre>
</div>
<div>
Uninstall
<pre>%python.conda uninstall [PACKAGE NAME]</pre>
</div>