martinzink commented on code in PR #1681:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1681#discussion_r1414212713


##########
bootstrap/system_dependency.py:
##########
@@ -0,0 +1,168 @@
+from __future__ import annotations
+
+import os
+import platform
+import sys
+from typing import Dict
+
+import distro
+
+from minifi_option import MinifiOptions
+
+
+def _query_yes_no(question: str, no_confirm: bool) -> bool:
+    valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False}
+
+    if no_confirm:
+        return True
+    while True:
+        print("{} [y/n]".format(question))
+        choice = input().lower()
+        if choice in valid:
+            return valid[choice]
+        else:
+            print("Please respond with 'yes' or 'no' " "(or 'y' or 'n').")
+
+
+def _get_system_identifier():
+    platform_system = platform.system()
+    if platform_system == "Linux":
+        return distro.id()
+    return platform_system
+
+
+def _replace_wholewords(target: str, replace_dict: Dict[str]):
+    words = target.split()
+    output_string = ' '.join(replace_dict.get(word, word) for word in words)
+    return output_string
+
+
+def _run_command_with_confirm(command: str, no_confirm: bool) -> bool:
+    if _query_yes_no("Running {}".format(command), no_confirm):
+        return os.system(command) == 0
+
+
+def _install_with_brew(dependencies_str: str, no_confirm: bool):
+    replace_dict = {"patch": "",
+                    "jni": "maven"}
+    command = "brew install {}".format(
+        _replace_wholewords(dependencies_str, replace_dict))
+    assert _run_command_with_confirm(command, no_confirm)
+
+
+def _install_with_apt(dependencies_str: str, no_confirm: bool):
+    replace_dict = {"libarchive": "liblzma-dev",
+                    "lua": "liblua5.1-0-dev",
+                    "python": "libpython3-dev",
+                    "libusb": "libusb-1.0-0-dev libusb-dev",
+                    "libpng": "libpng-dev",
+                    "libpcap": "libpcap-dev",
+                    "jni": "openjdk-8-jdk openjdk-8-source maven"}
+
+    command = "sudo apt install -y {}".format(
+        _replace_wholewords(dependencies_str, replace_dict))
+    assert _run_command_with_confirm(command, no_confirm)
+
+
+def _install_with_dnf(dependencies_str: str, no_confirm: bool):
+    replace_dict = {"gpsd": "gpsd-devel",
+                    "libpcap": "libpcap-devel",
+                    "lua": "lua-devel",
+                    "python": "python-devel",
+                    "jni": "java-1.8.0-openjdk java-1.8.0-openjdk-devel maven",
+                    "libpng": "libpng-devel",
+                    "libusb": "libusb-devel"}
+
+    command = "sudo dnf --enablerepo=crb install -y epel-release {}".format(
+        _replace_wholewords(dependencies_str, replace_dict))
+    assert _run_command_with_confirm(command, no_confirm)
+
+
+def _install_with_pacman(dependencies_str: str, no_confirm: bool):
+    replace_dict = {"g++": "gcc",
+                    "jni": "jdk8-openjdk maven"}
+    command = "sudo pacman --noconfirm -S {}".format(
+        _replace_wholewords(dependencies_str, replace_dict))
+    assert _run_command_with_confirm(command, no_confirm)
+
+
+def _install_with_winget(dependencies_str: str, no_confirm: bool):
+    replace_dict = {"lua": "DEVCOM.Lua",
+                    "python": "python",
+                    "patch": "",
+                    "bison": "",
+                    "flex": ""}
+    command = "winget install --disable-interactivity 
--accept-package-agreements {}".format(
+        _replace_wholewords(dependencies_str, replace_dict))
+    assert _run_command_with_confirm(command, no_confirm)
+
+
+def _install(dependencies_str: str, no_confirm: bool):

Review Comment:
   Good idea, I've refactored the whole thing around this idea



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to