diff --git a/backend/configure.py b/backend/configure.py index e027805..ee26cac 100755 --- a/backend/configure.py +++ b/backend/configure.py @@ -8,41 +8,32 @@ import dotenv from django.db import transaction, IntegrityError -class CmdCtx: +def yesno(prompt, default=False): + if not sys.stdin.isatty(): + return default + yes = {'yes', 'y', 'ye'} + no = {'no', 'n'} - def __init__(self, args): - self.args = args + if default: + yes.add('') + else: + no.add('') - def yesno(self, prompt, default=False): - if not sys.stdin.isatty() or self.args.noninteractive: - return default - elif self.args.yes: + hint = ' [Y/n] ' if default else ' [y/N] ' + + while True: + choice = input(prompt + hint).lower() + if choice in yes: return True - elif self.args.no: + elif choice in no: return False - yes = {'yes', 'y', 'ye'} - no = {'no', 'n'} - - if default: - yes.add('') else: - no.add('') - - hint = ' [Y/n] ' if default else ' [y/N] ' - - while True: - choice = input(prompt + hint).lower() - if choice in yes: - return True - elif choice in no: - return False - else: - print('Please respond with "yes" or "no"') + print('Please respond with "yes" or "no"') -def configure(ctx): +def configure(): if not os.path.exists('.env'): - if not ctx.yesno("the .env file does not exist, do you want to create it?", default=True): + if not yesno("the .env file does not exist, do you want to create it?", default=True): print('Aborting') exit(0) if not os.path.exists('.env.dist'): @@ -65,7 +56,7 @@ def configure(ctx): current_hosts = os.getenv('ALLOWED_HOSTS') print('Current ALLOWED_HOSTS: {}'.format(current_hosts)) - if ctx.yesno("Do you want to add ALLOWED_HOSTS?"): + if yesno("Do you want to add ALLOWED_HOSTS?"): hosts = input("Enter a comma-separated list of allowed hosts: ") joined_hosts = current_hosts + ',' + hosts if current_hosts else hosts dotenv.set_key('.env', 'ALLOWED_HOSTS', joined_hosts) @@ -76,21 +67,20 @@ def configure(ctx): django.setup() if not os.path.exists('db.sqlite3'): - if not ctx.yesno("No database found, do you want to create one?", default=True): + if not yesno("No database found, do you want to create one?", default=True): print('Aborting') exit(0) from django.core.management import call_command call_command('migrate') - if ctx.yesno("Do you want to create a superuser?"): + if yesno("Do you want to create a superuser?"): from django.core.management import call_command call_command('createsuperuser') call_command('collectstatic', '--no-input') - if ctx.yesno("Do you want to import all categories, properties and tags contained in this repository?", - default=True): + if yesno("Do you want to import all categories, properties and tags contained in this repository?", default=True): from hostadmin.serializers import CategorySerializer, PropertySerializer, TagSerializer from hostadmin.models import ImportedIdentifierSets from hashlib import sha256 @@ -206,7 +196,6 @@ def main(): parser = ArgumentParser(description='Toolshed Server Configuration') parser.add_argument('--yes', '-y', help='Answer yes to all questions', action='store_true') parser.add_argument('--no', '-n', help='Answer no to all questions', action='store_true') - parser.add_argument('--noninteractive', '-x', help="Run in noninteractive mode", action='store_true') parser.add_argument('cmd', help='Command', default='configure', nargs='?') args = parser.parse_args() @@ -214,10 +203,8 @@ def main(): print('Error: --yes and --no are mutually exclusive') exit(1) - ctx = CmdCtx(args) - if args.cmd == 'configure': - configure(ctx) + configure() elif args.cmd == 'reset': reset() elif args.cmd == 'testdata': diff --git a/frontend/src/components/BaseLayout.vue b/frontend/src/components/BaseLayout.vue index 21b3d75..6fb817c 100644 --- a/frontend/src/components/BaseLayout.vue +++ b/frontend/src/components/BaseLayout.vue @@ -6,6 +6,11 @@ +