Commit 6dbc76e4 authored by Guillaume Mella's avatar Guillaume Mella
Browse files

Merge branch 'release/2020_04_17_b2'

parents 74f257b4 0d3c4567
Pipeline #41794 passed with stage
in 2 minutes and 43 seconds
......@@ -4,7 +4,7 @@ import os
from datetime import datetime
from pyramid.config import Configurator
from setuptools_scm import get_version
from obsportal.tools.envvars import update_settings_with_envvars
from obsportal.tools.settings import update_settings_with_envvars
def main(global_config, **settings):
......
"""Pyramid bootstrap environment. """
from alembic import context
from pyramid.paster import get_appsettings, setup_logging
from pyramid.paster import setup_logging
from sqlalchemy import engine_from_config
from obsportal.models.meta import Base
from obsportal.tools.envvars import update_settings_with_envvars
from obsportal.tools.settings import load_settings
config = context.config
setup_logging(config.config_file_name)
settings = get_appsettings(config.config_file_name)
settings = update_settings_with_envvars(settings)
settings = load_settings(config.config_file_name)
target_metadata = Base.metadata
......
......@@ -12,7 +12,7 @@ from sqlalchemy.exc import OperationalError
from sqlalchemy.schema import CreateSchema, DropSchema
from sqlalchemy_utils.functions import database_exists, create_database, drop_database
from pyramid.paster import get_appsettings, bootstrap
from pyramid.paster import bootstrap
from pyramid.config import Configurator
from lxml import etree
......@@ -20,7 +20,7 @@ from lxml import etree
from obsportal.models.meta import Base, SCHEMAS
from obsportal.cli.tools import before_command, after_command, get_config_uri, get_root_path
from obsportal.tools.writers import StdoutWriter
from obsportal.tools.envvars import update_settings_with_envvars
from obsportal.tools.settings import load_settings
logger = logging.getLogger('obsportal.cli.database')
......@@ -123,11 +123,9 @@ def create(encoding, template, structure, settings, log, debug, skip_exist):
config_uri = get_config_uri(settings)
if config_uri is not None:
before_command(config_uri, log, debug)
logger.info("database:create()")
app_settings = get_appsettings(config_uri)
app_settings = update_settings_with_envvars(app_settings)
app_settings = load_settings(config_uri)
engine = engine_from_config(app_settings, 'sqlalchemy.')
config = Configurator(settings=app_settings)
......@@ -181,8 +179,7 @@ def create_structure(settings, log, debug, skip_exist):
logger.info("database:create_structure()")
app_settings = get_appsettings(config_uri)
app_settings = update_settings_with_envvars(app_settings)
app_settings = load_settings(config_uri)
engine = engine_from_config(app_settings, 'sqlalchemy.')
config = Configurator(settings=app_settings)
......@@ -232,8 +229,7 @@ def drop(settings, log, debug):
logger.info("database:drop()")
app_settings = get_appsettings(config_uri)
app_settings = update_settings_with_envvars(app_settings)
app_settings = load_settings(config_uri)
engine = engine_from_config(app_settings, 'sqlalchemy.')
# CHECK IF DB EXISTS
......@@ -258,8 +254,7 @@ def drop_structure(settings, log, debug):
logger.info("database:drop_structure()")
app_settings = get_appsettings(config_uri)
app_settings = update_settings_with_envvars(app_settings)
app_settings = load_settings(config_uri)
engine = engine_from_config(app_settings, 'sqlalchemy.')
try:
......@@ -429,8 +424,7 @@ def diagram_er(output_file, settings, log, debug):
from sqlalchemy_schemadisplay import create_schema_graph
click.echo("Rendering diagram from database...")
app_settings = get_appsettings(config_uri)
app_settings = update_settings_with_envvars(app_settings)
app_settings = load_settings(config_uri)
engine = engine_from_config(app_settings, 'sqlalchemy.')
# See https://github.com/sqlalchemy/sqlalchemy/wiki/SchemaDisplay
......
......@@ -3,7 +3,6 @@ import click
import os
import logging
import progressbar
from pyramid.paster import setup_logging
logger = logging.getLogger('obsportal.cli')
......
import logging
import os
from pyramid.settings import asbool
from pyramid.paster import get_appsettings
logger = logging.getLogger(__name__)
def load_settings(config_uri, section_name=None, env_prefix='obsportal'):
# Get settings from INI file
settings = get_appsettings(config_uri, name=section_name)
# Merge global conf. with application conf.
merged_settings = settings.global_conf.copy()
merged_settings.update(settings)
# Merge Environment variables
merged_settings = update_settings_with_envvars(merged_settings, env_prefix)
return merged_settings
# Inspired by pyramid_auto_env:
# https://pypi.org/project/pyramid-auto-env/
# https://raw.githubusercontent.com/marcelomoraes28/pyramid-auto-env/master/pyramid_auto_env/__init__.py
def update_settings_with_envvars(settings, prefix='obsportal'):
for k, v in settings.items():
......@@ -33,4 +48,4 @@ def update_settings_with_envvars(settings, prefix='obsportal'):
settings[k] = asbool(envvar_value) if envvar_value.lower() in ['true', 'false'] else envvar_value
logger.info('Found settings replacement for "{}" at "{}". Setting it up.'.format(k, transformed_key))
return settings
\ No newline at end of file
return settings
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment