Skip to content

Commit

Permalink
Added Systemd service support
Browse files Browse the repository at this point in the history
Added the use of a launch parameter "-service" that bypasses the main menu and disables user input.
  • Loading branch information
maspuce committed Nov 27, 2022
1 parent 059bd19 commit 3552c7d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
12 changes: 7 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
ui.run(config_dir, service_mode)
27 changes: 18 additions & 9 deletions ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from settings import *

config_dir = ""
service_mode = False

class option:
def __init__(self, name, cls, key):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 3552c7d

Please sign in to comment.