import logging
import os
import stripe
import json
from flask import Flask
from flask.ext.principal import Principal
from flask.ext.login import LoginManager
from flask.ext.mail import Mail
from storage import Storage
from config import DefaultConfig
from data.userfiles import Userfiles
app = Flask(__name__)
logger = logging.getLogger(__name__)
logger.debug('Loading default config.')
app.config.from_object(DefaultConfig())
if 'QUAY_CONFIG_FILE' in os.environ:
config_filename = os.environ['QUAY_CONFIG_FILE']
logger.debug('Applying config file: %s', config_filename)
app.config.from_pyfile(config_filename)
overrides = json.loads(os.environ.get('QUAY_CONFIG', '{}'))
logger.debug('Applying %s config overrides.', len(overrides))
app.config.from_object(overrides)
Principal(app, use_sessions=False)
login_manager = LoginManager()
login_manager.init_app(app)
mail = Mail()
mail.init_app(app)
storage = Storage()
storage.init_app(app)
userfiles = Userfiles()
userfiles.init_app(app)
stripe.api_key = app.config.get('STRIPE_SECRET_KEY', None)
mixpanel = app.config['ANALYTICS'].init_app(app)