Skip to content

Commit

Permalink
Merge pull request #2 from lsst/tickets/DM-3398
Browse files Browse the repository at this point in the history
Configure database engine for all apps.
  • Loading branch information
brianv0 committed Aug 31, 2015
2 parents ceaeaec + 9811464 commit 4b63fb5
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions bin/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,34 @@
from flask import Flask, request
import json
import logging as log
import os
import sys

from lsst.dax.dbserv import dbREST_v0
from lsst.dax.imgserv import imageREST_v0
from lsst.dax.metaserv import metaREST_v0

import ConfigParser
import sqlalchemy
from sqlalchemy.engine.url import URL


def initEngine():
config = ConfigParser.ConfigParser()
defaults_file = os.path.expanduser("~/.lsst/dbAuth-dbServ.txt")
config.readfp(open(defaults_file))
db_config = dict(config.items("mysql"))
# Translate user name
db_config["username"] = db_config["user"]
del db_config["user"]
# SQLAlchemy part
url = URL("mysql",**db_config)
return sqlalchemy.create_engine(url)

engine = initEngine()

app = Flask(__name__)
app.config["default_engine"] = engine

@app.route('/')
def getRoot():
Expand Down

0 comments on commit 4b63fb5

Please sign in to comment.