def func_with_context(name, config, environment, system_folders, *args, **kwargs): # select configuration if none supplied if config: ctx = ServerContext.from_external_config_file( config, environment, system_folders) else: if name: name, environment = (name, environment) else: try: name, environment = select_configuration_questionaire( "server", system_folders) except Exception: error("No configurations could be found!") exit(1) # raise error if config could not be found if not ServerContext.config_exists(name, environment, system_folders): scope = "system" if system_folders else "user" error( f"Configuration {Fore.RED}{name}{Style.RESET_ALL} with " f"{Fore.RED}{environment}{Style.RESET_ALL} does not exist " f"in the {Fore.RED}{scope}{Style.RESET_ALL} folders!") exit(1) # create server context, and initialize db ServerContext.LOGGING_ENABLED = False ctx = ServerContext(name, environment=environment, system_folders=system_folders) return func(ctx, *args, **kwargs)
def cli_server_new(name, environment, system_folders): """Create new configuration.""" if not name: name = q.text("Please enter a configuration-name:").ask() name_new = name.replace(" ", "-") if name != name_new: info(f"Replaced spaces from configuration name: {name}") name = name_new # Check that we can write in this folder if not check_config_write_permissions(system_folders): error("Your user does not have write access to all folders. Exiting") exit(1) # check that this config does not exist try: if ServerContext.config_exists(name, environment, system_folders): error(f"Configuration {Fore.RED}{name}{Style.RESET_ALL} with " f"environment {Fore.RED}{environment}{Style.RESET_ALL} " f"already exists!") exit(1) except Exception as e: print(e) exit(1) # create config in ctx location cfg_file = configuration_wizard(name, environment, system_folders) info(f"New configuration created: {Fore.GREEN}{cfg_file}{Style.RESET_ALL}") # info(f"root user created.") info(f"You can start the server by " f"{Fore.GREEN}vserver start{Style.RESET_ALL}.")
def func_with_context(name, config, environment, system_folders, *args, **kwargs): # select configuration if none supplied if config: ctx = ServerContext.from_external_config_file( config, environment, system_folders ) else: if name: name, environment = (name, environment) else: try: name, environment = select_configuration_questionaire( system_folders ) except Exception: error("No configurations could be found!") exit() # raise error if config could not be found if not ServerContext.config_exists( name, environment, system_folders ): scope = "system" if system_folders else "user" error( f"Configuration {Fore.RED}{name}{Style.RESET_ALL} with " f"{Fore.RED}{environment}{Style.RESET_ALL} does not exist " f"in the {Fore.RED}{scope}{Style.RESET_ALL} folders!" ) exit(1) # create server context, and initialize db ctx = ServerContext( name, environment=environment, system_folders=system_folders ) # initialize database (singleton) allow_drop_all = ctx.config["allow_drop_all"] Database().connect(URI=ctx.get_database_uri(), allow_drop_all=allow_drop_all) return func(ctx, *args, **kwargs)