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

Move default configuration template generation out of settings.py #18

Open
dmsimard opened this issue Apr 23, 2019 · 0 comments
Open

Move default configuration template generation out of settings.py #18

dmsimard opened this issue Apr 23, 2019 · 0 comments
Labels
cli Related to the CLI enhancement

Comments

@dmsimard
Copy link
Contributor

The configuration template is currently created out of settings.py:

ara/ara/server/settings.py

Lines 202 to 234 in d56c68f

# TODO: Split this out to a CLI command (django-admin command ?)
# Ensure default base configuration/data directory exists
if not os.path.isdir(BASE_DIR):
logger.info(f"Creating data & configuration directory: {BASE_DIR}")
os.makedirs(BASE_DIR, mode=0o700)
if not os.path.exists(DEFAULT_SETTINGS) and "ARA_SETTINGS" not in os.environ:
SETTINGS = dict(
BASE_DIR=BASE_DIR,
ALLOWED_HOSTS=ALLOWED_HOSTS,
CORS_ORIGIN_WHITELIST=CORS_ORIGIN_WHITELIST,
CORS_ORIGIN_ALLOW_ALL=CORS_ORIGIN_ALLOW_ALL,
SECRET_KEY=SECRET_KEY,
DATABASES=DATABASES,
DEBUG=DEBUG,
LOG_LEVEL=LOG_LEVEL,
LOGGING=LOGGING,
READ_LOGIN_REQUIRED=READ_LOGIN_REQUIRED,
WRITE_LOGIN_REQUIRED=WRITE_LOGIN_REQUIRED,
)
with open(DEFAULT_SETTINGS, "w+") as settings_file:
comment = f"""
---
# This is a default settings template generated by ARA.
# To use a settings file such as this one, you need to export the
# ARA_SETTINGS environment variable like so:
# $ export ARA_SETTINGS="{DEFAULT_SETTINGS}"
"""
logger.info(f"Writing default settings to {DEFAULT_SETTINGS}")
settings_file.write(textwrap.dedent(comment))
yaml.dump({"default": SETTINGS}, settings_file, default_flow_style=False)

This feature is useful but would be better suited as a CLI command so, amongst other things, it doesn't run every time settings.py is loaded.

@dmsimard dmsimard added enhancement cli Related to the CLI labels Apr 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Related to the CLI enhancement
Projects
None yet
Development

No branches or pull requests

1 participant