Added specific message when checking G-Python installation

This commit is contained in:
Alisson Nunes 2021-10-03 12:51:36 -03:00
parent 21583072df
commit 1c1d8b768a
2 changed files with 20 additions and 14 deletions

View File

@ -27,16 +27,16 @@ public class GPythonVersionUtils {
return maybeVersion.split(" ")[1]; return maybeVersion.split(" ")[1];
} }
public static boolean validInstallation() { public static boolean validInstallation() throws Exception {
// validates if user has all dependencies installed // validates if user has all dependencies installed
String pythonVersion = pythonVersion(); String pythonVersion = pythonVersion();
if (pythonVersion == null) { if (pythonVersion == null) {
return false; throw new Exception("Python is not installed.");
} }
ComparableVersion version = new ComparableVersion(pythonVersion); ComparableVersion version = new ComparableVersion(pythonVersion);
if (version.compareTo(new ComparableVersion(MIN_PYTHON_VERSION)) < 0) { if (version.compareTo(new ComparableVersion(MIN_PYTHON_VERSION)) < 0) {
return false; throw new Exception("Python version must be at least "+MIN_PYTHON_VERSION+", but only "+version+" was found.");
} }
List<String> allPackages = executeCommand("python", "-m", "pip", "list"); List<String> allPackages = executeCommand("python", "-m", "pip", "list");
@ -48,11 +48,15 @@ public class GPythonVersionUtils {
String gPython = getPackageVersion(allPackages, "g-python"); String gPython = getPackageVersion(allPackages, "g-python");
if (qtconsole == null || pyqt5 == null || jupyterConsole == null || gPython == null) { if (qtconsole == null || pyqt5 == null || jupyterConsole == null || gPython == null) {
return false; throw new Exception("One or more of these dependencies was not found: 'qtconsole', 'pyqt5', 'jupyter-console', 'g-python'.");
} }
ComparableVersion gVersion = new ComparableVersion(gPython); ComparableVersion gVersion = new ComparableVersion(gPython);
return gVersion.compareTo(new ComparableVersion(MIN_GPYTHON_VERSION)) >= 0; if (gVersion.compareTo(new ComparableVersion(MIN_GPYTHON_VERSION)) < 0) {
throw new Exception("G-Python version must be at least "+MIN_GPYTHON_VERSION+", but only "+gVersion+" was found.");
}
return true;
} }
// null if not found // null if not found

View File

@ -172,13 +172,22 @@ public class ExtraController extends SubForm implements SocksConfiguration {
cbx_gpython.setSelected(false); cbx_gpython.setSelected(false);
cbx_gpython.setDisable(true); cbx_gpython.setDisable(true);
}); });
if (!GPythonVersionUtils.validInstallation()) { try {
GPythonVersionUtils.validInstallation();
Platform.runLater(() -> {
cbx_gpython.setSelected(true);
cbx_gpython.setDisable(false);
parentController.extensionsController.updateGPythonStatus();
});
} catch (Exception e) {
Platform.runLater(() -> { Platform.runLater(() -> {
Alert alert = new Alert(Alert.AlertType.ERROR, "G-Python installation", ButtonType.OK); Alert alert = new Alert(Alert.AlertType.ERROR, "G-Python installation", ButtonType.OK);
alert.setTitle("G-Python installation"); alert.setTitle("G-Python installation");
FlowPane fp = new FlowPane(); FlowPane fp = new FlowPane();
Label lbl = new Label("Before using G-Python, install the right packages using pip!" + Label lbl = new Label("Something isn't right in the G-Python instalation:" +
System.lineSeparator() + System.lineSeparator() + "Error: "+ e.message +
System.lineSeparator() + System.lineSeparator() + "Before using G-Python, install the right packages using pip!" +
System.lineSeparator() + System.lineSeparator() + "More information here:"); System.lineSeparator() + System.lineSeparator() + "More information here:");
Hyperlink link = new Hyperlink(INFO_URL_GPYTHON); Hyperlink link = new Hyperlink(INFO_URL_GPYTHON);
fp.getChildren().addAll( lbl, link); fp.getChildren().addAll( lbl, link);
@ -194,13 +203,6 @@ public class ExtraController extends SubForm implements SocksConfiguration {
cbx_gpython.setDisable(false); cbx_gpython.setDisable(false);
}); });
} }
else {
Platform.runLater(() -> {
cbx_gpython.setSelected(true);
cbx_gpython.setDisable(false);
parentController.extensionsController.updateGPythonStatus();
});
}
}).start(); }).start();