From 217241748424e9d73844d3f311ef8897be3b2f80 Mon Sep 17 00:00:00 2001 From: Richard Hitier Date: Wed, 24 Mar 2021 09:22:45 +0100 Subject: [PATCH] Fix mysql_lesia_uri import exception --- app/commands/commands.py | 5 ++--- pdc_config.py | 6 ++++++ resources/db_config.py | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/commands/commands.py b/app/commands/commands.py index 911c9ea..08e0615 100644 --- a/app/commands/commands.py +++ b/app/commands/commands.py @@ -2,6 +2,7 @@ import sys import click import random +from flask import current_app from sqlalchemy.exc import OperationalError from sqlalchemy.sql import func from sqlalchemy.ext.automap import automap_base @@ -10,8 +11,6 @@ from sqlalchemy import create_engine from app.models import db, User, Agent, Service, Project, Capacity, Period, Charge -from db_config import mysql_lesia_uri - from . import bp @@ -23,7 +22,7 @@ def feed_from_lesia(): """ Base = automap_base() - engine = create_engine(mysql_lesia_uri) + engine = create_engine(current_app.config['LESIA_AGENTS_DB_URI']) # reflect the tables try: diff --git a/pdc_config.py b/pdc_config.py index 595ad70..2085076 100644 --- a/pdc_config.py +++ b/pdc_config.py @@ -25,6 +25,12 @@ class Config(object): SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \ 'sqlite:///' + os.path.join(root_dir, 'pdc_app.db') + try: + LESIA_AGENTS_DB_URI = mysql_lesia_uri + except NameError: + LESIA_AGENTS_DB_URI = os.environ.get('LESIA_AGENTS_DB_URI') or \ + 'sqlite:///' + os.path.join(root_dir, 'lesia.db') + with open(os.path.join(root_dir, 'VERSION.txt')) as version_file: VERSION = version_file.read().strip() diff --git a/resources/db_config.py b/resources/db_config.py index 6def089..549fcd7 100644 --- a/resources/db_config.py +++ b/resources/db_config.py @@ -39,6 +39,7 @@ POSTGRESTEST = { } postgres_test_uri = 'postgresql://%(user)s:%(pw)s@%(host)s:%(port)s/%(db)s' % POSTGRESTEST +# The lesia mysql agents database MYSQL_LESIA = { 'user': 'mysql', 'pw': 'mysql', -- libgit2 0.21.2