Example #1
0
def create_app(config_file="../redwind.cfg", is_queue=False):
    from redwind import extensions
    from redwind.views import views
    from redwind.admin import admin
    from redwind.services import services
    from redwind.micropub import micropub
    from redwind.imageproxy import imageproxy

    app = Flask(__name__)
    app.config.from_pyfile(config_file)
    app.config["CONFIG_FILE"] = config_file

    app.jinja_env.trim_blocks = True
    app.jinja_env.lstrip_blocks = True
    app.jinja_env.add_extension("jinja2.ext.autoescape")
    app.jinja_env.add_extension("jinja2.ext.with_")
    app.jinja_env.add_extension("jinja2.ext.i18n")

    extensions.init_app(app)

    if app.config.get("PROFILE"):
        from werkzeug.contrib.profiler import ProfilerMiddleware

        f = open("logs/profiler.log", "w")
        app.wsgi_app = ProfilerMiddleware(app.wsgi_app, f, restrictions=[60], sort_by=("cumtime", "tottime", "ncalls"))

    # logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
    if app.debug:
        app.logger.setLevel(logging.ERROR)
    else:
        app.logger.setLevel(logging.DEBUG)
        stream_handler = StreamHandler()
        # stream_handler = RotatingFileHandler(app.config.get('QUEUE_LOG' if is_queue else 'APP_LOG'), maxBytes=10000, backupCount=1)
        formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
        stream_handler.setFormatter(formatter)
        app.logger.addHandler(stream_handler)

        recipients = app.config.get("ADMIN_EMAILS")
        if recipients:
            error_handler = SMTPHandler("localhost", "Redwind <redwind@kylewm.com>", recipients, "redwind error")
            error_handler.setLevel(logging.ERROR)
            error_handler.setFormatter(Formatter(MAIL_FORMAT))
            app.logger.addHandler(error_handler)

    app.register_blueprint(views)
    app.register_blueprint(admin)
    app.register_blueprint(services)
    app.register_blueprint(micropub)
    app.register_blueprint(imageproxy)

    for plugin in [
        "facebook",
        "instagram",
        "locations",
        "push",
        "twitter",
        "wm_receiver",
        "wm_sender",
        "wordpress",
        "posse",
    ]:
        # app.logger.info('loading plugin module %s', plugin)
        module = importlib.import_module("redwind.plugins." + plugin)
        try:
            module.register(app)
        except:
            app.logger.warn("no register method for plugin module %s", plugin)

    return app
Example #2
0
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.httpauth import HTTPBasicAuth
from flask.ext.mail import Mail
from flask.ext.cache import Cache
import os
import yaml


app = Flask(__name__)
app.secret_key = "SUPERSECRET"  # you should change this to something equally random
app.config["CONFIG_FILE"] = os.path.abspath("app/config.yaml")
configStr = open(app.config["CONFIG_FILE"], "r")
app.config["CONFIG"] = yaml.load(configStr)
sqlite_db = os.path.abspath("db/elastatus.db")
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:////%s" % sqlite_db

db = SQLAlchemy(app)
auth = HTTPBasicAuth()
mail = Mail(app)
cache = Cache()
cache.init_app(
    app, config={"CACHE_TYPE": "simple", "CACHE_DEFAULT_TIMEOUT": app.config["CONFIG"]["sgaudit"]["cache_timeout"]}
)

if app.config["CONFIG"]["jobs"]["enabled"]:
    from jobs import *


from app.models import *