Beispiel #1
0
def create_app(config_file,
               blueprints=[],
               custom_error_endpoints=False,
               custom_template_paths=[],
               custom_before_handler=None,
               custom_before_handler_args=[],
               custom_before_handler_kargs={},
               custom_after_handler=None,
               custom_after_handler_args=[],
               custom_after_handler_kargs={},
               template_folder=None,
               cors=True,
               ssl_only=True,
               db_enabled=True,
               static_url_path=None,
               static_folder=None):

    if config_file is None:
        raise (Exception("Hey, 'config_files' cannot be 'None'!"))

    flask_init_options = {}
    if template_folder:
        flask_init_options['template_folder'] = template_folder
    if static_url_path:
        flask_init_options['static_url_path'] = static_url_path
    if static_folder:
        flask_init_options['static_folder'] = static_folder

    app = Flask(__name__, **flask_init_options)
    app = load_config(app, config_file)

    if ssl_only is True and app.config.get("DEBUG") is False:
        sslify = SSLify(app)

    app = setup_templates(app, custom_template_paths)
    app = setup_debug_log(app)
    app = register_blue_prints(app, blueprints)
    app = error_endpoints(app, custom_error_endpoints)
    app = before_handler(app, custom_before_handler,
                         custom_before_handler_args,
                         custom_before_handler_kargs)
    app = after_handler(app, custom_after_handler, custom_after_handler_args,
                        custom_after_handler_kargs, db_enabled)
    if db_enabled:
        app = init_db(app)
    app = setup_routes(app)

    if cors is True:
        cors = CORS(app)
        app.config['CORS_HEADERS'] = 'Content-Type'

    if app.config.get('DEBUG') is False:
        mail = Mail(app)
        mail_on_500(app, app.config.get('ADMINS'))

    return app
Beispiel #2
0
def setup_error_emails(app):
    """Sets up emails on errors if the SMTP server is specified in the settings.
    """
    if 'OPBEAT' in app.config:
        app.logger.info("setting up opbeat")
        config = app.config['OPBEAT']
        opbeat = Opbeat(app,
            organization_id=config['ORGANIZATION_ID'],
            app_id=config['APP_ID'],
            secret_token=config['SECRET_TOKEN'])

    if app.debug:
        return

    if 'ERROR_EMAIL_RECIPIENTS' not in app.config:
      return

    sender = app.config.get("MAIL_DEFAULT_SENDER")
    recipients = app.config['ERROR_EMAIL_RECIPIENTS'].split(",")
    mail_on_500(app, recipients, sender=sender)
Beispiel #3
0
def setup_error_emails(app):
    """Sets up emails on errors if the SMTP server is specified in the settings.
    """
    if 'OPBEAT' in app.config:
        app.logger.info("setting up opbeat")
        config = app.config['OPBEAT']
        opbeat = Opbeat(app,
                        organization_id=config['ORGANIZATION_ID'],
                        app_id=config['APP_ID'],
                        secret_token=config['SECRET_TOKEN'])

    if app.debug:
        return

    if 'ERROR_EMAIL_RECIPIENTS' not in app.config:
        return

    sender = app.config.get("MAIL_DEFAULT_SENDER")
    recipients = app.config['ERROR_EMAIL_RECIPIENTS'].split(",")
    mail_on_500(app, recipients, sender=sender)
Beispiel #4
0
from multiprocessing import Process
import glob
import sqlite3
import traceback
import time

logging.getLogger().addHandler(logging.StreamHandler())
logging.getLogger().setLevel(logging.INFO)

ADMINISTRATORS = (
    '*****@*****.**',
)

app = Flask(__name__)
mail_on_500(app, ADMINISTRATORS)
Compress(app)
app.config['COMPRESS_DEBUG'] = True
cache = SimpleCache()

EXAC_FILES_DIRECTORY = '../exac_data/'
REGION_LIMIT = 1E5
EXON_PADDING = 50
# Load default config and override config from an environment variable
app.config.update(dict(
    DB_HOST='localhost',
    DB_PORT=27017,
    DB_NAME='exac', 
    DEBUG=True,
    SECRET_KEY='development key',
    LOAD_DB_PARALLEL_PROCESSES = 4,  # contigs assigned to threads, so good to make this a factor of 24 (eg. 2,3,4,6,8)
Beispiel #5
0
def test_install_sanity():
    mail_on_500(Flask('Fake Flask App'), ('*****@*****.**', ))
app.config["SECURITY_SEND_PASSWORD_CHANGE_EMAIL"] = False
app.config["SECURITY_SEND_PASSWORD_RESET_NOTICE_EMAIL"] = False
app.config["SECURITY_PASSWORD_HASH"] = 'sha512_crypt'
app.config["SECURITY_PASSWORD_SALT"] = '' # Set password salt

# Flask-Mail
app.config['MAIL_SERVER'] = 'smtp.gmail.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = '' # Place email address
app.config['MAIL_PASSWORD'] = '' # Place password
mail = Mail(app)

# Flask-ErrorMail
ADMINISTRATORS = [""] # Set administrators emails
mail_on_500(app, ADMINISTRATORS, sender='') # Add sender email

# Flask-DebugToolBar
app.config['DEBUG_TB_PANELS'] = ['flask.ext.mongoengine.panels.MongoDebugPanel']
app.config['DEBUG_TB_ENABLED'] = True

# Flask-MongoEngine
db = MongoEngine(app)
app.session_interface = MongoEngineSessionInterface(db)

login_manager = LoginManager()
login_manager.init_app(app)
login_manager.session_protection = "strong"

assets = Environment(app)
js = Bundle('js/jquery.min.js', 'js/bootstrap.js', 'js/tooltip.js', 'js/notify.min.js', 'js/moment.min.js', 'js/application.js', 'js/app.js', filters="jsmin", output="lib/application.js")
Beispiel #7
0
from collections import defaultdict, OrderedDict
from werkzeug.contrib.cache import SimpleCache

from multiprocessing import Process
import glob
import sqlite3
import traceback
import time

logging.getLogger().addHandler(logging.StreamHandler())
logging.getLogger().setLevel(logging.INFO)

ADMINISTRATORS = ('*****@*****.**', )

app = Flask(__name__)
mail_on_500(app, ADMINISTRATORS)
Compress(app)
app.config['COMPRESS_DEBUG'] = True
cache = SimpleCache()

EXAC_FILES_DIRECTORY = '../exac_data/'
REGION_LIMIT = 1E5
EXON_PADDING = 50
# Load default config and override config from an environment variable
app.config.update(
    dict(
        DB_HOST='localhost',
        DB_PORT=27017,
        DB_NAME='exac',
        DEBUG=True,
        SECRET_KEY='development key',
Beispiel #8
0
    '[in %(pathname)s:%(lineno)d]'
))
app.logger.addHandler(file_handler)


if os.getenv("LOGFILE", None):
    import logging.handlers, logging
    file_handler = logging.handlers.RotatingFileHandler(os.getenv("LOGFILE"), 'a', 10000000, 1000)
    file_handler.setLevel(logging.DEBUG)
    file_handler.setFormatter(logging.Formatter(
        '%(asctime)s %(levelname)s: %(message)s '
        '[in %(pathname)s:%(lineno)d]'
    ))
    app.logger.addHandler(file_handler)

mail_on_500(app, ["*****@*****.**", ])

# Replace this.
DOC_KEY="xx"

def ldapsearch(uid):
    cmd = 'ldapsearch -l 5 -LLL -x -h ldap-too -b "ou=users,ou=moira,dc=mit,dc=edu" ' + pipes.quote("uid=" + uid)
    try:
        output = subprocess.check_output(cmd, shell=True)
    except subprocess.CalledProcessError, e:
        app.logger.error(str(e))
        return None
    out = {}
    lines = output.strip().splitlines()
    for line in lines:
        key, val = line.split(":", 1)
Beispiel #9
0
from flask_errormail import mail_on_500
from datetime import datetime

from os import listdir
from os.path import isfile, join


app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app)

# Load configs
app.config.from_object('app.settings.common')
app.config.from_envvar('GRAFFATHON_SETTINGS')

mail_on_500(app, app.config['ADMINISTRATORS'],
            sender=app.config['MAIL_DEFAULT_SENDER'])

db = SQLAlchemy(app)

login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = '/login'

mail = Mail(app)
mail.init_app(app)

thumb = Thumbnail(app)

from models import SignUp, Admin
from forms import SignUpForm, LoginForm
from emails import send_email, send_all
Beispiel #10
0
def test_install_sanity():
    mail_on_500(Flask("Fake Flask App"), ("*****@*****.**",))
Beispiel #11
0
# Load default config
app.config.from_object('config.default')
# Load instance configuration if exists
app.config.from_pyfile('config.py', silent=True)
# Load configuration file specified in BRAVO_CONFIG_FILE environment variable if exists
app.config.from_envvar('BRAVO_CONFIG_FILE', silent=True)

#app.config.from_object('flask_config.BravoFreeze5GRCh38Config')

if app.config['PROXY']: app.wsgi_app = ProxyFix(app.wsgi_app)
if 'GVS_URL_PREFIX' in os.environ:
    app.config['URL_PREFIX'] = os.environ['GVS_URL_PREFIX']
if 'BRAVO_ADMIN_MODE' in os.environ:
    app.config['ADMIN'] = True if os.environ['BRAVO_ADMIN_MODE'].lower(
    ) == 'true' else False
mail_on_500(app, app.config['ADMINS'])
app.config['COMPRESS_LEVEL'] = 2  # Since we don't cache, faster=better
Compress(app)
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 5  # 5 second browser cache timeout
app.config['TEMPLATES_AUTO_RELOAD'] = True

BASE_COVERAGE = []
BASE_COVERAGE.extend({
    'bp-min-length': 0,
    'path': path
} for path in glob.glob(app.config['BASE_COVERAGE_DIRECTORY'] +
                        'full/*.json.gz'))
BASE_COVERAGE.extend({
    'bp-min-length': 300,
    'binned': True,
    'path': path
Beispiel #12
0
class MyFlask(Flask):
    @cached_property
    def connection(self):
        return Connection(self.config['MONGODB_HOST'], self.config['MONGODB_PORT'])

    @cached_property
    def db(self):
        return getattr(self.connection, self.config['MONGODB_DB'])


app = MyFlask(__name__)
app.root_path = '/'.join(app.root_path.split('/')[:-1])
app.config.from_object('project.settings')


if mail_on_500: mail_on_500(app, app.config['ADMINS'])

markdown = Markdown(app)
command_manager = Manager(app)

assets = Environment(app)
static = {}
static['js'] = map(lambda x: 'js/%s' % x, (
    'jquery.min.js',
    'underscore.js',
    'backbone.js',
    'backbone-forms.js',
    'ejs.js',
    'jquery.form.js',
    'bootstrap-tooltip.js',
    'jquery.reject.js',