Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sane environment by default #538

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions loris/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,28 @@

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')
config_file_path = path.join(data_directory, 'loris.conf')

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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this run_simple() code here isn't meant for production use. Not sure we should change the debug default to false in create_app() - it might look like this is an approved way to run loris in production.

@alexwlchan any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I would leave the default as debug=true. Clear sign that this is only for local testing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that it isn't documented, and it is not clear why some flags in the config file are being overwritten by the get_debug_config method. This function is my main concern. I do not think it is a problem to keep the debug as true if we honour the data from the config file, and not rewrite it.


run_simple('localhost', 5004, app, use_debugger=True, use_reloader=True)
# To debug ssl:
Expand Down