From e152e0da42f3308480aa2a726f78de6083f62327 Mon Sep 17 00:00:00 2001 From: Alberto Simoes Date: Mon, 7 Jun 2021 20:15:24 +0200 Subject: [PATCH 1/2] Use sane environment by default - by default, the repository has debug enabled, meaning the get_debug_config is called overwriting the user config. That is not nice. Changed by default to false. In the future this can be a configuration flag? - when no config file is set, and debug is false, no configuration is loaded. This causes a lot of errors (namely key not founds). Given the repo includes a config file, added code to load it by default - when using the default config file, warn the user about that Some details can be made better, but for now, it is working perfectly on my docker environment. I am happy to provide further changes on this branch if you like. --- loris/webapp.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/loris/webapp.py b/loris/webapp.py index 264057d1..65c85d53 100755 --- a/loris/webapp.py +++ b/loris/webapp.py @@ -40,8 +40,7 @@ getcontext().prec = 25 # Decimal precision. This should be plenty. - -def get_debug_config(debug_jp2_transformer): +def get_default_config(): # change a few things, read the config and set up logging project_dp = path.dirname(path.dirname(path.realpath(__file__))) data_directory = path.join(project_dp, 'loris', 'data') @@ -49,8 +48,20 @@ def get_debug_config(debug_jp2_transformer): config = read_config(config_file_path) - config['logging']['log_to'] = 'console' - config['logging']['log_level'] = 'DEBUG' + if "logging" not in config: + config['logging'] = get_default_logging() + + return config + +def get_default_logging(): + return { + 'format': '%(asctime)s (%(name)s) [%(levelname)s]: %(message)s', + 'log_to': 'console', + 'log_level': 'DEBUG', + } + +def get_debug_config(debug_jp2_transformer): + config = get_default_config() # override some stuff to look at relative or tmp directories. config['loris.Loris']['www_dp'] = path.join(data_directory, 'www') @@ -96,7 +107,13 @@ def create_app(debug=False, debug_jp2_transformer='kdu', config_file_path=''): def read_config(config_file_path): - config = ConfigObj(config_file_path, unrepr=True, interpolation='template') + if len(config_file_path) > 0: + config = ConfigObj(config_file_path, unrepr=True, interpolation='template') + else: + config = get_default_config() + tmp_logger = configure_logging(config['logging']) + tmp_logger.info("No config file path defined. Using default config") + # add the OS environment variables as the DEFAULT section to support # interpolating their values into other keys # make a copy of the os.environ dictionary so that the config object can't @@ -781,7 +798,7 @@ def _make_image(self, image_request, image_info): sys.path.append(path.join(project_dp)) # to find any local resolvers - app = create_app(debug=True) # or 'opj' + app = create_app(debug=False) # or 'opj' run_simple('localhost', 5004, app, use_debugger=True, use_reloader=True) # To debug ssl: From 056d4b1118a0bb9acca5c98d9dcd27f8934dac32 Mon Sep 17 00:00:00 2001 From: Alberto Simoes Date: Tue, 8 Jun 2021 15:49:11 +0200 Subject: [PATCH 2/2] Workaround for data_directory --- loris/webapp.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/loris/webapp.py b/loris/webapp.py index 65c85d53..6ce0cdbe 100755 --- a/loris/webapp.py +++ b/loris/webapp.py @@ -47,6 +47,7 @@ def get_default_config(): config_file_path = path.join(data_directory, 'loris.conf') config = read_config(config_file_path) + config['data_directory'] = data_directory if "logging" not in config: config['logging'] = get_default_logging() @@ -64,7 +65,7 @@ def get_debug_config(debug_jp2_transformer): config = get_default_config() # override some stuff to look at relative or tmp directories. - config['loris.Loris']['www_dp'] = path.join(data_directory, 'www') + config['loris.Loris']['www_dp'] = path.join(config['data_directory'], 'www') config['loris.Loris']['tmp_dp'] = '/tmp/loris/tmp' config['loris.Loris']['enable_caching'] = True config['img.ImageCache']['cache_dp'] = '/tmp/loris/cache/img'