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

Configure database engine for all apps. #2

Merged
merged 1 commit into from
Aug 31, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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