From 63b8a49993afcdd2a0dafc6aa23bf37e96e813cc Mon Sep 17 00:00:00 2001 From: krateng Date: Sat, 4 Nov 2023 13:47:31 +0100 Subject: [PATCH] Add output for EOFError, fix GH-273 --- maloja/setup.py | 88 ++++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/maloja/setup.py b/maloja/setup.py index 59c7c7e..4aa75dd 100644 --- a/maloja/setup.py +++ b/maloja/setup.py @@ -37,46 +37,52 @@ def setup(): copy_initial_local_files() SKIP = malojaconfig["SKIP_SETUP"] - print("Various external services can be used to display images. If not enough of them are set up, only local images will be used.") - for k in ext_apikeys: - keyname = malojaconfig.get_setting_info(k)['name'] - key = malojaconfig[k] - if key is False: - print(f"\tCurrently not using a {col['red'](keyname)} for image display.") - elif key is None or key == "ASK": - promptmsg = f"\tPlease enter your {col['gold'](keyname)}. If you do not want to use one at this moment, simply leave this empty and press Enter." - key = prompt(promptmsg,types=(str,),default=False,skip=SKIP) - malojaconfig[k] = key - else: - print(f"\t{col['lawngreen'](keyname)} found.") + try: - - # OWN API KEY - from .apis import apikeystore - if len(apikeystore) == 0: - answer = ask("Do you want to set up a key to enable scrobbling? Your scrobble extension needs that key so that only you can scrobble tracks to your database.",default=True,skip=SKIP) - if answer: - key = apikeystore.generate_key('default') - print("Your API Key: " + col["yellow"](key)) - - # PASSWORD - forcepassword = malojaconfig["FORCE_PASSWORD"] - # this is mainly meant for docker, supply password via environment variable - - if forcepassword is not None: - # user has specified to force the pw, nothing else matters - auth.defaultuser.setpw(forcepassword) - print("Password has been set.") - elif auth.defaultuser.checkpw("admin"): - # if the actual pw is admin, it means we've never set this up properly (eg first start after update) - while True: - newpw = prompt("Please set a password for web backend access. Leave this empty to generate a random password.",skip=SKIP,secret=True) - if newpw is None: - newpw = randomstring(32) - print("Generated password:",col["yellow"](newpw)) - break + print("Various external services can be used to display images. If not enough of them are set up, only local images will be used.") + for k in ext_apikeys: + keyname = malojaconfig.get_setting_info(k)['name'] + key = malojaconfig[k] + if key is False: + print(f"\tCurrently not using a {col['red'](keyname)} for image display.") + elif key is None or key == "ASK": + promptmsg = f"\tPlease enter your {col['gold'](keyname)}. If you do not want to use one at this moment, simply leave this empty and press Enter." + key = prompt(promptmsg,types=(str,),default=False,skip=SKIP) + malojaconfig[k] = key else: - newpw_repeat = prompt("Please type again to confirm.",skip=SKIP,secret=True) - if newpw != newpw_repeat: print("Passwords do not match!") - else: break - auth.defaultuser.setpw(newpw) + print(f"\t{col['lawngreen'](keyname)} found.") + + + # OWN API KEY + from .apis import apikeystore + if len(apikeystore) == 0: + answer = ask("Do you want to set up a key to enable scrobbling? Your scrobble extension needs that key so that only you can scrobble tracks to your database.",default=True,skip=SKIP) + if answer: + key = apikeystore.generate_key('default') + print("Your API Key: " + col["yellow"](key)) + + # PASSWORD + forcepassword = malojaconfig["FORCE_PASSWORD"] + # this is mainly meant for docker, supply password via environment variable + + if forcepassword is not None: + # user has specified to force the pw, nothing else matters + auth.defaultuser.setpw(forcepassword) + print("Password has been set.") + elif auth.defaultuser.checkpw("admin"): + # if the actual pw is admin, it means we've never set this up properly (eg first start after update) + while True: + newpw = prompt("Please set a password for web backend access. Leave this empty to generate a random password.",skip=SKIP,secret=True) + if newpw is None: + newpw = randomstring(32) + print("Generated password:",col["yellow"](newpw)) + break + else: + newpw_repeat = prompt("Please type again to confirm.",skip=SKIP,secret=True) + if newpw != newpw_repeat: print("Passwords do not match!") + else: break + auth.defaultuser.setpw(newpw) + + except EOFError: + print("No user input possible. If you are running inside a container, set the environment variable",col['yellow']("MALOJA_SKIP_SETUP=yes")) + raise SystemExit