<s> """<STR_LIT>""" <EOL> import os <EOL> import logging <EOL> import docker as _docker <EOL> import flask <EOL> import raven . contrib <EOL> from celery import Celery , Task <EOL> from werkzeug . local import LocalProxy <EOL> from flask . ext . sqlalchemy import SQLAlchemy <EOL> from flask . ext . migrate import Migrate <EOL> from flask . ext . login import LoginManager <EOL> from flask . ext . principal import Principal <EOL> from flask . ext . assets import Environment , Bundle <EOL> from flask . ext . wtf . csrf import CsrfProtect <EOL> from flask . ext . mail import Mail <EOL> from flask . ext . moment import Moment <EOL> VERSION = '<STR_LIT>' <EOL> def get_version ( ) : <EOL> return VERSION <EOL> db = SQLAlchemy ( ) <EOL> migrate = Migrate ( ) <EOL> login_manager = LoginManager ( ) <EOL> principal = Principal ( ) <EOL> celery = Celery ( ) <EOL> csrf = CsrfProtect ( ) <EOL> mail = Mail ( ) <EOL> moment = Moment ( ) <EOL> docker = LocalProxy ( lambda : _docker . Client ( <EOL> base_url = flask . current_app . config [ '<STR_LIT>' ] , <EOL> version = flask . current_app . config [ '<STR_LIT>' ] ) ) <EOL> def create_app ( config = None ) : <EOL> """<STR_LIT>""" <EOL> app = flask . Flask ( __name__ ) <EOL> config = config or os . environ . get ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> app . config . from_object ( config ) <EOL> configure_logging ( app ) <EOL> configure_extensions ( app ) <EOL> configure_blueprints ( app ) <EOL> register_jinja2_globals_and_filters ( app ) <EOL> return app <EOL> def configure_logging ( app ) : <EOL> app . logger . setLevel ( logging . INFO ) <EOL> if not ( app . debug or app . testing ) : <EOL> handler = logging . StreamHandler ( ) <EOL> app . logger . addHandler ( handler ) <EOL> def configure_extensions ( app ) : <EOL> db . init_app ( app ) <EOL> migrate . init_app ( app , db ) <EOL> login_manager . init_app ( app ) <EOL> principal . init_app ( app ) <EOL> init_celery_app ( app , celery ) <EOL> csrf . init_app ( app ) <EOL> mail . init_app ( app ) <EOL> moment . init_app ( app ) <EOL> assets = Environment ( app ) <EOL> css = Bundle ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> output = '<STR_LIT>' ) <EOL> js = Bundle ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> output = '<STR_LIT>' ) <EOL> assets . register ( '<STR_LIT>' , css ) <EOL> assets . register ( '<STR_LIT>' , js ) <EOL> def configure_blueprints ( app ) : <EOL> from . import auth <EOL> app . register_blueprint ( auth . bp ) <EOL> from . import repos <EOL> app . register_blueprint ( repos . bp , url_prefix = '<STR_LIT>' ) <EOL> from . import accounts <EOL> app . register_blueprint ( accounts . bp , url_prefix = '<STR_LIT>' ) <EOL> from . import projects <EOL> app . register_blueprint ( projects . bp , url_prefix = '<STR_LIT>' ) <EOL> from . import builds <EOL> app . register_blueprint ( builds . bp ) <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return flask . redirect ( flask . url_for ( '<STR_LIT>' ) ) <EOL> def register_jinja2_globals_and_filters ( app ) : <EOL> import wtforms <EOL> from kozmic . builds import get_ansi_to_html_converter <EOL> app . jinja_env . globals [ '<STR_LIT>' ] = get_version <EOL> app . jinja_env . globals [ '<STR_LIT>' ] = lambda field : isinstance ( field , wtforms . HiddenField ) <EOL> ansi_converter = get_ansi_to_html_converter ( ) <EOL> app . jinja_env . filters [ '<STR_LIT>' ] = lambda ansi : ansi_converter . convert ( ansi , full = False ) <EOL> app . jinja_env . filters [ '<STR_LIT>' ] = lambda dt : moment . create ( dt ) . format ( '<STR_LIT>' ) <EOL> app . jinja_env . globals [ '<STR_LIT>' ] = ansi_converter . produce_headers <EOL> def init_celery_app ( app , celery ) : <EOL> celery . config_from_object ( app . config ) <EOL> class ContextTask ( Task ) : <EOL> abstract = True <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> with create_app ( ) . app_context ( ) : <EOL> return super ( ContextTask , self ) . __call__ ( * args , ** kwargs ) <EOL> celery . Task = ContextTask <EOL> sentry_dsn = app . config [ '<STR_LIT>' ] <EOL> if sentry_dsn : <EOL> client = raven . Client ( sentry_dsn ) <EOL> raven . contrib . celery . register_signal ( client ) </s>
