diff options
author | 2013-07-29 21:55:51 +0300 | |
---|---|---|
committer | 2013-07-29 21:55:51 +0300 | |
commit | e5bdc5bc099096186e00e61604484fc6a1ecdeb2 (patch) | |
tree | 0e31d855e720459ad438216c47898b5080fb8c92 /flask_app.py | |
parent | More basename() defensiveness (diff) | |
download | log-analysis-e5bdc5bc099096186e00e61604484fc6a1ecdeb2.tar.gz log-analysis-e5bdc5bc099096186e00e61604484fc6a1ecdeb2.tar.bz2 log-analysis-e5bdc5bc099096186e00e61604484fc6a1ecdeb2.zip |
Database (SQL) class for functionality common across all processors
Currently uses MySQLdb. Schema included.
Diffstat (limited to 'flask_app.py')
-rw-r--r-- | flask_app.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/flask_app.py b/flask_app.py index 832702c..5356bc4 100644 --- a/flask_app.py +++ b/flask_app.py @@ -4,14 +4,24 @@ When run as a script, the Flask development server is started. """ import os, socket -import submission_pb2, storage -from flask import Flask, request +import submission_pb2, storage, database +from flask import Flask, request, g from portage_processor import PortageProcessor app = Flask(__name__) store = storage.FilesystemStorage('logs/') -processors = {'portage' : PortageProcessor(None, store)} # TODO: initialise from config file +processors = {'portage' : PortageProcessor(store)} # TODO: initialise from config file + +@app.before_request +def before_request(): + g.db = database.get_connection('gsoc', 'gsocpasswd', 'loganalysis') + +@app.teardown_request +def teardown_request(exception): + db = getattr(g, 'db', None) + if db is not None: + db.conn.close() @app.route('/') def index(): @@ -23,7 +33,7 @@ def submit(): submission.ParseFromString(request.data) source = socket.getfqdn(request.remote_addr) # TODO: is this ok? - processors[submission.provider].process(submission, source) + processors[submission.provider].process(submission, source, g.db) return '' if __name__ == '__main__': |