From 35baba9e6d133fedebf32a0ee07da59a6ab2ed6e Mon Sep 17 00:00:00 2001 From: deajan Date: Sat, 25 Jan 2025 21:41:25 +0100 Subject: [PATCH] Change build_type detection --- bin/npbackup-cli | 6 +++--- bin/npbackup-gui | 4 +++- bin/npbackup-viewer | 2 ++ npbackup/__env__.py | 5 +++++ npbackup/__version__.py | 13 ++----------- npbackup/restic_wrapper/__init__.py | 11 ++++++++--- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/bin/npbackup-cli b/bin/npbackup-cli index 2fd2614..998b862 100644 --- a/bin/npbackup-cli +++ b/bin/npbackup-cli @@ -8,12 +8,12 @@ import sys sys.path.insert(0, os.path.normpath(os.path.join(os.path.dirname(__file__), ".."))) +import npbackup.__env__ +npbackup.__env__.BUILD_TYPE = "cli" from npbackup.__main__ import main - del sys.path[0] - if __name__ == "__main__": while "--run-as-cli" in sys.argv: # Drop --run-as-cli argument since cli doesn't know about it - sys.argv.pop(sys.argv.index("--run-as-cli")) + sys.argv.pop(sys.argv.index("--run-as-cli")) main() diff --git a/bin/npbackup-gui b/bin/npbackup-gui index cf70bb7..9fa483f 100644 --- a/bin/npbackup-gui +++ b/bin/npbackup-gui @@ -8,13 +8,15 @@ import sys sys.path.insert(0, os.path.normpath(os.path.join(os.path.dirname(__file__), ".."))) +import npbackup.__env__ +npbackup.__env__.BUILD_TYPE = "gui" from npbackup.gui.__main__ import main_gui from npbackup.__main__ import main del sys.path[0] if __name__ == "__main__": - while "--run-as-cli" in sys.argv: + if "--run-as-cli" in sys.argv: # Drop --run-as-cli argument since cli doesn't know about it sys.argv.pop(sys.argv.index("--run-as-cli")) main() diff --git a/bin/npbackup-viewer b/bin/npbackup-viewer index c0d6d62..10d8ae6 100644 --- a/bin/npbackup-viewer +++ b/bin/npbackup-viewer @@ -8,6 +8,8 @@ import sys sys.path.insert(0, os.path.normpath(os.path.join(os.path.dirname(__file__), ".."))) +import npbackup.__env__ +npbackup.__env__.BUILD_TYPE = "viewer" from npbackup.gui.__main__ import main_gui del sys.path[0] diff --git a/npbackup/__env__.py b/npbackup/__env__.py index d38ee8c..a7c226e 100644 --- a/npbackup/__env__.py +++ b/npbackup/__env__.py @@ -33,3 +33,8 @@ FAST_COMMANDS_TIMEOUT = 180 # # Wait x seconds before we actually do the upgrade so current program could quit before being erased UPGRADE_DEFER_TIME = 60 + + +def set_build_type(build_type: str) -> None: + global BUILD_TYPE + BUILD_TYPE = build_type diff --git a/npbackup/__version__.py b/npbackup/__version__.py index 1d59604..c03965d 100644 --- a/npbackup/__version__.py +++ b/npbackup/__version__.py @@ -17,6 +17,7 @@ import os import sys import psutil from ofunctions.platform import python_arch, get_os +import npbackup.__env__ from npbackup.configuration import IS_PRIV_BUILD from npbackup.core.nuitka_helper import IS_COMPILED @@ -25,16 +26,6 @@ from npbackup.core.nuitka_helper import IS_COMPILED # Since developpment currently follows Python 3.12, let's consider anything below 3.12 as legacy IS_LEGACY = True if sys.version_info[1] < 12 else False -executable = sys.argv[0] -if executable.startswith("npbackup-gui"): - build_type = "gui" -elif executable.startswith("npbackup-cli"): - build_type = "cli" -elif executable.startswith("npbackup-viewer"): - build_type = "viewer" -else: - build_type = "UnknownBuildType" - try: CURRENT_USER = psutil.Process().username() except Exception: @@ -42,7 +33,7 @@ except Exception: version_dict = { "name": __intname__, "version": __version__, - "build_type": build_type, + "build_type": npbackup.__env__.BUILD_TYPE, "audience": "private" if IS_PRIV_BUILD else "public", "os": get_os().lower(), "arch": python_arch() + ("-legacy" if IS_LEGACY else ""), diff --git a/npbackup/restic_wrapper/__init__.py b/npbackup/restic_wrapper/__init__.py index 9d706ac..e150e6b 100644 --- a/npbackup/restic_wrapper/__init__.py +++ b/npbackup/restic_wrapper/__init__.py @@ -23,8 +23,12 @@ from functools import wraps from command_runner import command_runner from ofunctions.misc import BytesConverter, fn_name from npbackup.__debug__ import _DEBUG -from npbackup.__version__ import build_type -from npbackup.__env__ import FAST_COMMANDS_TIMEOUT, CHECK_INTERVAL, HEARTBEAT_INTERVAL +from npbackup.__env__ import ( + FAST_COMMANDS_TIMEOUT, + CHECK_INTERVAL, + HEARTBEAT_INTERVAL, + BUILD_TYPE, +) from npbackup.path_helper import CURRENT_DIR from npbackup.restic_wrapper import schema @@ -857,7 +861,8 @@ class ResticRunner: cmd = "ls {}".format(snapshot) result, output = self.executor(cmd, method="monitor") if result: - if build_type in ["gui", "viewer"]: + # Don't show content when running in gui mode + if BUILD_TYPE in ["gui", "viewer"]: msg = ( f"Successfully listed snapshot {snapshot} content (not showed here)" )