Changeset - 873cff4229e3
[Not reviewed]
0 1 0
Joar Wandborg - 10 years ago 2013-12-17 10:18:35
joar@wandborg.se
[web] Late init of storage engine.
1 file changed with 5 insertions and 1 deletions:
0 comments (0 inline, 0 general)
accounting/web.py
Show inline comments
...
 
@@ -2,35 +2,36 @@
 
This module contains the high-level webservice logic such as the Flask setup
 
and the Flask endpoints.
 
'''
 
import sys
 
import logging
 
import argparse
 

	
 
from flask import Flask, jsonify, request
 
from flask.ext.sqlalchemy import SQLAlchemy
 
from flask.ext.script import Manager
 
from flask.ext.migrate import Migrate, MigrateCommand
 

	
 
from accounting.storage import Storage
 
from accounting.storage.ledgercli import Ledger
 
from accounting.storage.sql import SQLStorage
 
from accounting.transport import AccountingEncoder, AccountingDecoder
 
from accounting.exceptions import AccountingException
 
from accounting.decorators import jsonify_exceptions
 

	
 

	
 
app = Flask('accounting')
 
app.config.from_pyfile('config.py')
 

	
 
storage = Ledger(app=app)
 
storage = Storage()
 

	
 
if isinstance(storage, SQLStorage):
 
    # TODO: Move migration stuff into SQLStorage
 
    db = storage.db
 
    migrate = Migrate(app, db)
 

	
 
    manager = Manager(app)
 
    manager.add_command('db', MigrateCommand)
 

	
 

	
 
@app.before_request
 
def init_ledger():
...
 
@@ -143,20 +144,23 @@ def transaction_post():
 
def main(argv=None):
 
    prog = __name__
 
    if argv is None:
 
        prog = sys.argv[0]
 
        argv = sys.argv[1:]
 

	
 
    parser = argparse.ArgumentParser(prog=prog)
 
    parser.add_argument('-v', '--verbosity',
 
                        default='INFO',
 
                        help=('Filter logging output. Possible values:' +
 
                              ' CRITICAL, ERROR, WARNING, INFO, DEBUG'))
 

	
 
    global storage
 
    storage = Ledger(app=app)
 

	
 
    args = parser.parse_args(argv)
 

	
 
    logging.basicConfig(level=getattr(logging, args.verbosity, 'INFO'))
 

	
 
    app.run(host=app.config['HOST'], port=app.config['PORT'])
 

	
 
if __name__ == '__main__':
 
    main()
0 comments (0 inline, 0 general)