refactor: Activate, Deactivate

This commit is contained in:
1ambda 2017-01-08 13:36:21 +09:00
parent f9558890f3
commit 9c5dd8643f

View file

@ -82,15 +82,10 @@ public class PythonCondaInterpreter extends Interpreter {
String result = runCondaCreate(getRestArgsFromMatcher(createMatcher));
return new InterpreterResult(Code.SUCCESS, Type.HTML, result);
} else if (activateMatcher.matches()) {
String envName = activateMatcher.group(1);
changePythonEnvironment(envName);
restartPythonProcess();
return new InterpreterResult(Code.SUCCESS,
"\"" + envName + "\" activated");
String envName = activateMatcher.group(1).trim();
return runCondaActivate(envName);
} else if (deactivatePattern.matcher(st).matches()) {
changePythonEnvironment(null);
restartPythonProcess();
return new InterpreterResult(Code.SUCCESS, "Deactivated");
return runCondaDeactivate();
} else if (installMatcher.matches()) {
String result = runCondaInstall(getRestArgsFromMatcher(installMatcher));
return new InterpreterResult(Code.SUCCESS, Type.HTML, result);
@ -203,6 +198,27 @@ public class PythonCondaInterpreter extends Interpreter {
return wrapCondaTableOutputStyle("Environment List", getCondaEnvs());
}
private InterpreterResult runCondaActivate(String envName)
throws IOException, InterruptedException {
if (null == envName || envName.isEmpty()) {
return new InterpreterResult(Code.ERROR, "Env name should be specified");
}
changePythonEnvironment(envName);
restartPythonProcess();
return new InterpreterResult(Code.SUCCESS, "'" + envName + "' is activated");
}
private InterpreterResult runCondaDeactivate()
throws IOException, InterruptedException {
changePythonEnvironment(null);
restartPythonProcess();
return new InterpreterResult(Code.SUCCESS, "Deactivated");
}
private String runCondaList() throws IOException, InterruptedException {
List<String> commands = new ArrayList<String>();
commands.add("conda");