PythonCondaInterpreter extends Interpreter { public static Map<String, String> parseCondaCommonStdout(String out) throws IOException, InterruptedException { Map<String, String> kv = new LinkedHashMap<String, String>(); String[] lines = out.split("\n"); for (String s : lines) { if (s == null || s.isEmpty() || s.startsWith("#")) { continue; } Matcher match = PATTERN_OUTPUT_ENV_LIST.matcher(s); if (!match.matches()) { continue; } kv.put(match.group(1), match.group(2)); } return kv; } PythonCondaInterpreter(Properties property); @Override void open(); @Override void close(); @Override InterpreterResult interpret(String st, InterpreterContext context); String getCurrentCondaEnvName(); void setCurrentCondaEnvName(String currentCondaEnvName); static String runCondaCommandForTextOutput(String title, List<String> commands); static String wrapCondaBasicOutputStyle(String title, String content); static String wrapCondaTableOutputStyle(String title, Map<String, String> kv); static Map<String, String> parseCondaCommonStdout(String out); @Override void cancel(InterpreterContext context); @Override FormType getFormType(); @Override int getProgress(InterpreterContext context); @Override Scheduler getScheduler(); static String runCommand(List<String> commands); static String runCommand(String... command); static List<String> getRestArgsFromMatcher(Matcher m); static final String ZEPPELIN_PYTHON; static final String CONDA_PYTHON_PATH; static final String DEFAULT_ZEPPELIN_PYTHON; static final Pattern PATTERN_OUTPUT_ENV_LIST; static final Pattern PATTERN_COMMAND_ENV_LIST; static final Pattern PATTERN_COMMAND_ENV; static final Pattern PATTERN_COMMAND_LIST; static final Pattern PATTERN_COMMAND_CREATE; static final Pattern PATTERN_COMMAND_ACTIVATE; static final Pattern PATTERN_COMMAND_DEACTIVATE; static final Pattern PATTERN_COMMAND_INSTALL; static final Pattern PATTERN_COMMAND_UNINSTALL; static final Pattern PATTERN_COMMAND_HELP; static final Pattern PATTERN_COMMAND_INFO; }
@Test public void testParseCondaCommonStdout() throws IOException, InterruptedException { StringBuilder sb = new StringBuilder() .append("# comment1\n") .append("# comment2\n") .append("env1 /location1\n") .append("env2 /location2\n"); Map<String, String> locationPerEnv = PythonCondaInterpreter.parseCondaCommonStdout(sb.toString()); assertEquals("/location1", locationPerEnv.get("env1")); assertEquals("/location2", locationPerEnv.get("env2")); }