diff options
Diffstat (limited to 'uploader/__init__.py')
| -rw-r--r-- | uploader/__init__.py | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/uploader/__init__.py b/uploader/__init__.py index 0ba1f81..afaa78d 100644 --- a/uploader/__init__.py +++ b/uploader/__init__.py @@ -73,6 +73,28 @@ def setup_modules_logging(app_logger, modules): _logger.setLevel(loglevel) +def __setup_scratch_directory__(app: Flask) -> Flask: + app.config["SCRATCH_DIRECTORY"] = Path( + app.config["SCRATCH_DIRECTORY"]).absolute() + return app + +def __setup_upload_directory__(app: Flask) -> Flask: + if app.config.get("UPLOADS_DIRECTORY", "").strip() == "": + app.config["UPLOADS_DIRECTORY"] = app.config[ + "SCRATCH_DIRECTORY"].joinpath("uploads") + else: + app.config["UPLOADS_DIRECTORY"] = Path( + app.config["UPLOADS_DIRECTORY"].strip()).absolute() + + return app + + +def update_unspecified_defaults(app: Flask) -> Flask: + """Setup the defaults for necessary configurations that do not have values + specified for them.""" + return __setup_upload_directory__(__setup_scratch_directory__(app)) + + def create_app(config: Optional[dict] = None): """The application factory. @@ -100,6 +122,7 @@ def create_app(config: Optional[dict] = None): # Silently ignore secrets if the file does not exist. app.config.from_pyfile(secretsfile) app.config.update(config) # Override everything with passed in config + update_unspecified_defaults(app) ### END: Application configuration app.config["SESSION_CACHELIB"] = FileSystemCache( @@ -108,12 +131,8 @@ def create_app(config: Optional[dict] = None): default_timeout=int(app.config["SESSION_FILESYSTEM_CACHE_TIMEOUT"])) setup_logging(app) - setup_modules_logging(app.logger, ( - "uploader.base_routes", - "uploader.flask_extensions", - "uploader.publications.models", - "uploader.publications.datatables", - "uploader.phenotypes.models")) + setup_modules_logging( + app.logger, tuple(app.config.get("LOGGABLE_MODULES", []))) # setup jinja2 symbols app.add_template_global(user_logged_in) |
