From 3552c7d26c173941fe8c7d13514c2876f6ac6cf2 Mon Sep 17 00:00:00 2001 From: Maspuce Date: Sun, 27 Nov 2022 13:19:00 -0500 Subject: [PATCH] Added Systemd service support Added the use of a launch parameter "-service" that bypasses the main menu and disables user input. --- main.py | 12 +++++++----- ui/__init__.py | 27 ++++++++++++++++++--------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/main.py b/main.py index 5d40272f..7c13b9c6 100644 --- a/main.py +++ b/main.py @@ -2,18 +2,20 @@ from base import * config_dir = "" +service_mode = False if os.path.exists('./settings.json'): if os.path.getsize('./settings.json') > 0 and os.path.isfile('./settings.json'): config_dir = "." -if config_dir == "": - for i,arg in enumerate(sys.argv): - if arg == "--config-dir": - config_dir = sys.argv[i+1] +for i,arg in enumerate(sys.argv): + if config_dir == "" and arg == "--config-dir": + config_dir = sys.argv[i+1] + if arg == "-service": + service_mode = True if config_dir == "": config_dir = "." if __name__ == "__main__": - ui.run(config_dir) \ No newline at end of file + ui.run(config_dir, service_mode) \ No newline at end of file diff --git a/ui/__init__.py b/ui/__init__.py index aadcc956..faa68422 100644 --- a/ui/__init__.py +++ b/ui/__init__.py @@ -9,6 +9,7 @@ from settings import * config_dir = "" +service_mode = False class option: def __init__(self, name, cls, key): @@ -223,7 +224,7 @@ def setup(): if os.path.getsize(config_dir + '/settings.json') > 0 and os.path.isfile(config_dir + '/settings.json'): with open(config_dir + '/settings.json', 'r') as f: settings = json.loads(f.read()) - if settings['Show Menu on Startup'] == "false": + if settings['Show Menu on Startup'] == "false" or service_mode == True: return False load() return True @@ -311,9 +312,11 @@ def preflight(): return False return True -def run(cdir = ""): +def run(cdir = "", smode = False): global config_dir + global service_mode config_dir = cdir + service_mode = smode if setup(): options() else: @@ -343,7 +346,10 @@ def update(settings, version): def threaded(stop): ui_cls() - print("Type 'exit' to return to the main menu.") + if service_mode == True: + print("Running in service mode, user input not supported.") + else: + print("Type 'exit' to return to the main menu.") timeout = 5 regular_check = 1800 timeout_counter = 0 @@ -417,12 +423,15 @@ def download_script_run(): stop = False t = Thread(target=threaded, args=(lambda: stop,)) t.start() - while not stop: - text = input("") - if text == 'exit': - stop = True - else: - print("Type 'exit' to return to the main menu.") + if service_mode == True: + print("Running in service mode, user input not supported.") + else: + while not stop: + text = input("") + if text == 'exit': + stop = True + else: + print("Type 'exit' to return to the main menu.") print("Waiting for the download automation to stop ... ") while t.is_alive(): time.sleep(1)