-
Notifications
You must be signed in to change notification settings - Fork 0
/
cbb.py
65 lines (50 loc) · 2.2 KB
/
cbb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
import logging
import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_injector import FlaskInjector
from injector import Module, Injector, singleton
from sqlalchemy.ext.declarative import declarative_base
from db import db
from routes import blueprint as main_blueprint
from routes.config import blueprint as config_blueprint
from routes.config.account import blueprint as config_account_blueprint
from routes.config.plan import blueprint as config_plan_blueprint
from routes.config.settings import blueprint as config_settings_blueprint
il = logging.getLogger('injector')
il.addHandler(logging.StreamHandler())
il.level = logging.DEBUG
# We use standard SQLAlchemy models rather than the Flask-SQLAlchemy magic, as
# it requires a global Flask app object and SQLAlchemy db object.
Base = declarative_base()
def main():
db_path = os.path.join(os.path.dirname(os.path.realpath(__file__)) + os.sep + 'app.db')
app = Flask(__name__)
app.secret_key = os.getenv('SECRET_KEY', 'b3D$EJAQ4g91U8UPqwZ4yaaSoAsH!V')
app.register_blueprint(main_blueprint, url_prefix='/')
app.register_blueprint(config_blueprint, url_prefix='/config')
app.register_blueprint(config_account_blueprint, url_prefix='/config/account')
app.register_blueprint(config_plan_blueprint, url_prefix='/config/plan')
app.register_blueprint(config_settings_blueprint, url_prefix='/config/settings')
app.config.update(
SQLALCHEMY_DATABASE_URI='sqlite:///{0}'.format(db_path),
SQLALCHEMY_TRACK_MODIFICATIONS=False
)
app.debug = os.getenv('DEBUGGING', 'N') == 'Y'
injector = Injector([AppModule(app)])
FlaskInjector(app=app, injector=injector)
app.run()
class AppModule(Module):
def __init__(self, app):
self.app = app
"""Configure the application."""
def configure(self, binder):
# We configure the DB here, explicitly, as Flask-SQLAlchemy requires
# the DB to be configured before request handlers are called.
with self.app.app_context():
db.init_app(self.app)
Base.metadata.create_all(db.engine)
binder.bind(SQLAlchemy, to=db, scope=singleton)
if __name__ == '__main__':
main()