From 3bbb6af5f2482d21b8da7bf402f3a422dfdb0662 Mon Sep 17 00:00:00 2001 From: MrTyton Date: Tue, 16 Jul 2024 15:24:01 -0400 Subject: [PATCH] Add environment variable and synchroize verbosity across processes --- Dockerfile | 2 +- root/app/ff_logging.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index fd09052..d2d13f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -80,4 +80,4 @@ VOLUME /config WORKDIR /config #ENTRYPOINT ["/init"] -CMD python -u /app/fanficdownload.py --config="/config/config.toml" --verbose=${VERBOSE} +CMD sh -c 'if [ "$VERBOSE" = "true" ]; then python -u /app/fanficdownload.py --config="/config/config.toml" --verbose; else python -u /app/fanficdownload.py --config="/config/config.toml"; fi' \ No newline at end of file diff --git a/root/app/ff_logging.py b/root/app/ff_logging.py index 8339690..21226e3 100644 --- a/root/app/ff_logging.py +++ b/root/app/ff_logging.py @@ -1,4 +1,6 @@ +import ctypes import datetime +from multiprocessing import Value class bcolors: @@ -27,7 +29,8 @@ class bcolors: "UNDERLINE": bcolors.UNDERLINE, } -verbose = False +# Initialize a shared variable for the verbose flag +verbose = Value(ctypes.c_bool, False) def set_verbose(value: bool) -> None: @@ -37,8 +40,7 @@ def set_verbose(value: bool) -> None: Args: value (bool): The value to set the verbose flag to. """ - global verbose - verbose = value + verbose.value = value def log(msg: str, color: str = None) -> None: