superset/caravel/__init__.py

69 lines
2.1 KiB
Python
Raw Normal View History

2016-03-18 02:44:58 -04:00
"""Package's main module!"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
2016-03-18 02:44:58 -04:00
import logging
import os
from logging.handlers import TimedRotatingFileHandler
2016-03-18 02:44:58 -04:00
from flask import Flask, redirect
from flask_appbuilder import SQLA, AppBuilder, IndexView
from flask_appbuilder.baseviews import expose
from flask_cache import Cache
from flask_migrate import Migrate
2016-03-18 02:44:58 -04:00
from caravel import version
VERSION = version.VERSION_STRING
2016-03-18 02:44:58 -04:00
APP_DIR = os.path.dirname(__file__)
2016-03-29 00:55:58 -04:00
CONFIG_MODULE = os.environ.get('CARAVEL_CONFIG', 'caravel.config')
2016-03-18 02:44:58 -04:00
app = Flask(__name__)
app.config.from_object(CONFIG_MODULE)
if not app.debug:
# In production mode, add log handler to sys.stderr.
app.logger.addHandler(logging.StreamHandler())
app.logger.setLevel(logging.INFO)
2016-03-18 02:44:58 -04:00
db = SQLA(app)
2016-03-16 23:25:41 -04:00
cache = Cache(app, config=app.config.get('CACHE_CONFIG'))
2016-03-18 02:44:58 -04:00
migrate = Migrate(app, db, directory=APP_DIR + "/migrations")
# Logging configuration
logging.basicConfig(format=app.config.get('LOG_FORMAT'))
logging.getLogger().setLevel(app.config.get('LOG_LEVEL'))
if app.config.get('ENABLE_TIME_ROTATE'):
logging.getLogger().setLevel(app.config.get('TIME_ROTATE_LOG_LEVEL'))
handler = TimedRotatingFileHandler(app.config.get('FILENAME'),
when=app.config.get('ROLLOVER'),
interval=app.config.get('INTERVAL'),
backupCount=app.config.get('BACKUP_COUNT'))
logging.getLogger().addHandler(handler)
if app.config.get('ENABLE_CORS'):
from flask_cors import CORS
CORS(app, **app.config.get('CORS_OPTIONS'))
2016-03-18 02:44:58 -04:00
class MyIndexView(IndexView):
@expose('/')
def index(self):
2016-03-29 00:55:58 -04:00
return redirect('/caravel/welcome')
2016-03-18 02:44:58 -04:00
appbuilder = AppBuilder(
app, db.session,
2016-03-29 00:55:58 -04:00
base_template='caravel/base.html',
2016-03-18 02:44:58 -04:00
indexview=MyIndexView,
security_manager_class=app.config.get("CUSTOM_SECURITY_MANAGER"))
sm = appbuilder.sm
get_session = appbuilder.get_session
2016-03-29 00:55:58 -04:00
from caravel import config, views # noqa