Commit 217241748424e9d73844d3f311ef8897be3b2f80

Authored by hitier
1 parent 7e08aa0c

Fix mysql_lesia_uri import exception

app/commands/commands.py
... ... @@ -2,6 +2,7 @@ import sys
2 2 import click
3 3 import random
4 4  
  5 +from flask import current_app
5 6 from sqlalchemy.exc import OperationalError
6 7 from sqlalchemy.sql import func
7 8 from sqlalchemy.ext.automap import automap_base
... ... @@ -10,8 +11,6 @@ from sqlalchemy import create_engine
10 11  
11 12 from app.models import db, User, Agent, Service, Project, Capacity, Period, Charge
12 13  
13   -from db_config import mysql_lesia_uri
14   -
15 14 from . import bp
16 15  
17 16  
... ... @@ -23,7 +22,7 @@ def feed_from_lesia():
23 22 """
24 23 Base = automap_base()
25 24  
26   - engine = create_engine(mysql_lesia_uri)
  25 + engine = create_engine(current_app.config['LESIA_AGENTS_DB_URI'])
27 26  
28 27 # reflect the tables
29 28 try:
... ...
pdc_config.py
... ... @@ -25,6 +25,12 @@ class Config(object):
25 25 SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
26 26 'sqlite:///' + os.path.join(root_dir, 'pdc_app.db')
27 27  
  28 + try:
  29 + LESIA_AGENTS_DB_URI = mysql_lesia_uri
  30 + except NameError:
  31 + LESIA_AGENTS_DB_URI = os.environ.get('LESIA_AGENTS_DB_URI') or \
  32 + 'sqlite:///' + os.path.join(root_dir, 'lesia.db')
  33 +
28 34 with open(os.path.join(root_dir, 'VERSION.txt')) as version_file:
29 35 VERSION = version_file.read().strip()
30 36  
... ...
resources/db_config.py
... ... @@ -39,6 +39,7 @@ POSTGRESTEST = {
39 39 }
40 40 postgres_test_uri = 'postgresql://%(user)s:%(pw)s@%(host)s:%(port)s/%(db)s' % POSTGRESTEST
41 41  
  42 +# The lesia mysql agents database
42 43 MYSQL_LESIA = {
43 44 'user': 'mysql',
44 45 'pw': 'mysql',
... ...