예제 #1
0
def create_app(config=None):
    app = Flask(__name__)
    app.secret_key = configuration.get('webserver', 'SECRET_KEY')
    app.config['LOGIN_DISABLED'] = not configuration.getboolean('webserver', 'AUTHENTICATE')

    csrf.init_app(app)

    #app.config = config
    airflow.load_login()
    airflow.login.login_manager.init_app(app)

    cache = Cache(
        app=app, config={'CACHE_TYPE': 'filesystem', 'CACHE_DIR': '/tmp'})

    app.register_blueprint(ck, url_prefix='/ck')
    app.register_blueprint(routes)
    app.jinja_env.add_extension("chartkick.ext.charts")

    with app.app_context():
        from airflow.www import views

        admin = Admin(
            app, name='Airflow',
            static_url_path='/admin',
            index_view=views.HomeView(endpoint='', url='/admin', name="DAGs"),
            template_mode='bootstrap3',
        )
        av = admin.add_view
        vs = views
        av(vs.Airflow(name='DAGs', category='DAGs'))

        av(vs.QueryView(name='Ad Hoc Query', category="Data Profiling"))
        av(vs.ChartModelView(
            models.Chart, Session, name="Charts", category="Data Profiling"))
        av(vs.KnowEventView(
            models.KnownEvent,
            Session, name="Known Events", category="Data Profiling"))
        av(vs.SlaMissModelView(
            models.SlaMiss,
            Session, name="SLA Misses", category="Browse"))
        av(vs.TaskInstanceModelView(models.TaskInstance,
            Session, name="Task Instances", category="Browse"))
        av(vs.LogModelView(
            models.Log, Session, name="Logs", category="Browse"))
        av(vs.JobModelView(
            jobs.BaseJob, Session, name="Jobs", category="Browse"))
        av(vs.PoolModelView(
            models.Pool, Session, name="Pools", category="Admin"))
        av(vs.ConfigurationView(
            name='Configuration', category="Admin"))
        av(vs.UserModelView(
            models.User, Session, name="Users", category="Admin"))
        av(vs.ConnectionModelView(
            models.Connection, Session, name="Connections", category="Admin"))
        av(vs.VariableView(
            models.Variable, Session, name="Variables", category="Admin"))

        admin.add_link(base.MenuLink(
            category='Docs', name='Documentation',
            url='http://pythonhosted.org/airflow/'))
        admin.add_link(
            base.MenuLink(category='Docs',
                name='Github',url='https://github.com/airbnb/airflow'))

        av(vs.VersionView(name='Version', category="About"))

        av(vs.DagRunModelView(
            models.DagRun, Session, name="DAG Runs", category="Browse"))
        av(vs.DagModelView(models.DagModel, Session, name=None))
        # Hack to not add this view to the menu
        admin._menu = admin._menu[:-1]

        def integrate_plugins():
            """Integrate plugins to the context"""
            from airflow.plugins_manager import (
                admin_views, flask_blueprints, menu_links)
            for v in admin_views:
                admin.add_view(v)
            for bp in flask_blueprints:
                app.register_blueprint(bp)
            for ml in sorted(menu_links, key=lambda x: x.name):
                admin.add_link(ml)

        integrate_plugins()

        @app.context_processor
        def jinja_globals():
            return {
                'hostname': socket.getfqdn(),
            }

        @app.teardown_appcontext
        def shutdown_session(exception=None):
            settings.Session.remove()

        return app
예제 #2
0
    def test_17_dict_config(self):
        cache = Cache(config={'CACHE_TYPE': 'simple'})
        cache.init_app(self.app)

        assert cache.config['CACHE_TYPE'] == 'simple'
예제 #3
0
파일: ext.py 프로젝트: startover/firefly
from __future__ import absolute_import
# coding=utf-8
from flask import current_app
from flask_babel import Babel
from flask_cache import Cache
from flask_login import LoginManager
from flask_mail import Mail
from flask_mako import MakoTemplates
from flask_mongoengine import MongoEngine
from flask_redis import FlaskRedis
from flask_restful import Api
from flask_security import Security
from werkzeug.local import LocalProxy

api = Api()
babel = Babel()
cache = Cache()
db = MongoEngine()
login_manager = LoginManager()
mail = Mail()
mako = MakoTemplates()
redis_store = FlaskRedis()
security = Security()

logger = LocalProxy(lambda: current_app.logger)
예제 #4
0
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
from flask_cache import Cache
from flask.logging import getLogger, DEBUG

app = Flask(__name__)
app.config.from_object('app.default_config')
app.config.from_envvar('FLASK_CONFIG_PATH', silent=True)

if app.debug:
    log = getLogger('console')
    log.setLevel(DEBUG)
else:
    from logging.handlers import RotatingFileHandler
    file_handler = RotatingFileHandler('bsb.log')
    file_handler.setLevel(DEBUG)
    app.logger.addHandler(file_handler)

app.logger.debug(app.config)

cache = Cache(app, config=app.config)
db = SQLAlchemy(app)

login_manager = LoginManager()
login_manager.init_app(app)

from app import views, models
예제 #5
0
from flask import Flask, render_template
import feedparser
import re
from flask_cache import Cache

app = Flask(__name__)
cache = Cache(app, config={'CACHE_TYPE': 'simple'})


#get source type: jpg, gif, mp4
def post_Type(summary):
    imgType = 'src="(.+?\.jpg)"'
    gifType = 'src="(.+?\.gif)"'
    mp4Type = 'src="(.+?\.mp4)"'
    imgre = re.compile(imgType)
    gifre = re.compile(gifType)
    mp4re = re.compile(mp4Type)
    imglist = re.findall(imgre, summary)
    giflist = re.findall(gifre, summary)
    mp4list = re.findall(mp4re, summary)
    if imglist != []:
        return 'img', imglist[0]
    elif giflist != []:
        return 'gif', giflist[0]
    elif mp4list != []:
        return 'mp4', mp4list[0]
    else:
        return 'other type', 'other type'


#parse the xml
예제 #6
0
__version__ = '0.7.0'
__author__ = 'Chris Kitching, Michael Søndergaard, Vytautas Mickus, Michel Jung'
__contact__ = '*****@*****.**'
__license__ = 'GPLv3'
__copyright__ = 'Copyright (c) 2011-2015 ' + __author__

if sys.version_info.major != 3:
    raise RuntimeError(
        "FAForever API requires python 3.\n")


# ======== Init Flask ==========

app = Flask('api')
CORS(app)
cache = Cache(config={'CACHE_TYPE': 'simple'}, with_jinja2_ext=False)

login_manager = LoginManager()
login_manager.init_app(app)

_make_response = app.make_response

@app.after_request
def after_request(response):
    response.headers['Access-Control-Allow-Origin'] = '*'
    response.headers['Access-Control-Allow-Headers'] = 'Content-Type,Authorization'
    response.headers['Access-Control-Allow-Methods'] = 'GET,PUT,POST,DELETE'
    return response

@app.errorhandler(ApiException)
def handle_api_exception(error):
예제 #7
0
def setup_cache(app, cache_config):
    """Setup the flask-cache on a flask app"""
    if cache_config and cache_config.get('CACHE_TYPE') != 'null':
        return Cache(app, config=cache_config)
예제 #8
0
app = Flask(__name__)
app.config.from_object(CONFIG_MODULE)
conf = app.config

if not app.debug:
    # In production mode, add log handler to sys.stderr.
    app.logger.addHandler(logging.StreamHandler())
    app.logger.setLevel(logging.INFO)
logging.getLogger('pyhive.presto').setLevel(logging.INFO)

db = SQLA(app)


utils.pessimistic_connection_handling(db.engine.pool)

cache = Cache(app, config=app.config.get('CACHE_CONFIG'))
tables_cache = Cache(app, config=app.config.get('TABLE_NAMES_CACHE_CONFIG'))


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'))
예제 #9
0
def register_cache(app):
    cache = Cache()
    cache.init_app(app)
    return cache
예제 #10
0
from flask_socketio import SocketIO
from mongoengine import connect
from slackclient import SlackClient
from config import config
from app.utils.json_util import CustomFlaskJSONEncoder

ResultTuple = namedtuple('ResultTuple', ['data', 'errors', 'common'])


# current config
config_name = os.environ.get('APP_CONFIG', 'development')
current_config = config[config_name]

# Flask extensions
socketio = SocketIO()
cache = Cache(config=current_config.CACHE_CONFIG)
mail = Mail()

celery_app = Celery(__name__,
                broker=current_config.CELERY_BROKER_URL,
                backend=current_config.CELERY_RESULT_BACKEND)
celery_app.autodiscover_tasks([__name__])

slack_client = SlackClient(current_config.SLACK_TOKEN)

redis_client = redis.StrictRedis.from_url(current_config.REDIS_DOMAIN, db=0)

auth_redis_client = redis.StrictRedis.from_url(current_config.AUTH_REDIS_URL)

#s3 connection
# boto_client = boto3.client('s3', aws_access_key_id=current_config.AWS_ACCESS_KEY,
예제 #11
0
# coding:utf-8
# 集成第三方包
from flask_cache import Cache
from flask_session import Session

from mainApp.apis import init_api
from mainApp.models import init_db
from flask_mail import Mail

mail = Mail()

cache = Cache(
    config={
        'CACHE_TYPE': 'redis',
        'CACHE_REDIS_HOST': '10.35.163.24',
        'CACHE_REDIS_POST': '6379',
        'CACHE_REDIS_DB': 12,
        'CACHE_REDIS_PASSWORD': 109321
    })

se = Session()


def init_ext(app):
    #初始化数据库
    init_db(app)
    #初始化api接口
    init_api(app)

    #初始化mail
    mail.init_app(app)
예제 #12
0
from flask_mongoengine import MongoEngine

db = MongoEngine()

from flask_elasticsearch import FlaskElasticsearch

es = FlaskElasticsearch()

# Flask-Login
from flask_login import LoginManager

login_manager = LoginManager()

# Flask-WTF csrf protection
from flask_wtf.csrf import CSRFProtect

csrf = CSRFProtect()

# Flask-Mail
from flask_mail import Mail

mail = Mail()

from flask_cache import Cache

cache = Cache(config={'CACHE_TYPE': 'memcached'})

from .cron import Cron

cron = Cron()
예제 #13
0
# coding=UTF-8
import re
import json
import os
import fake_objects
import utils
from fake_resources import FakeResources
from functools import wraps
from flask import current_app as app
from flask_cache import Cache


CACHE = Cache(app, config=app.config['CACHE_CONFIG'])


def failure_content(status_code, reason, message):
    content = {
        'apiVersion': 'v1',
        'kind': 'Status',
        'code': status_code,
        'reason': reason,
        'message': message,
        'status': 'Failure'
    }
    return content


class ObjectOperator(object):
    def __init__(self, target_name, target_namespace,
                 targets, key, content={}):
        kind = 'None'
예제 #14
0
def register_cache(app):
    cache = Cache(config={'CACHE_TYPE': 'null'})
    cache.init_app(app)
    return cache
예제 #15
0
from jose import jwt
from jose.jwt import JWTError

from aggregator import (
    COUNT_HISTOGRAM_LABELS, COUNT_HISTOGRAM_PREFIX, NUMERIC_SCALARS_PREFIX, SCALAR_MEASURE_MAP)
from db import get_db_connection_string, histogram_revision_map, _preparedb

pool = None
db_connection_string = get_db_connection_string(read_only=True)
app = Flask(__name__)
dockerflow = Dockerflow(app, version_path='/app')

app.config.from_pyfile('config.py')

CORS(app, resources=r'/*', allow_headers=['Authorization', 'Content-Type'])
cache = Cache(app, config={'CACHE_TYPE': app.config["CACHETYPE"]})
sslify = SSLify(app, permanent=True, skips=['__version__', '__heartbeat__', '__lbheartbeat__', 'status'])

patch_all()
patch_psycopg()
cache.clear()

# For caching - change this if after backfilling submission_date data
SUBMISSION_DATE_ETAG = 'submission_date_v1'
CLIENT_CACHE_SLACK_SECONDS = 3600

# If we get a query string not in this set we throw a 405.
ALLOWED_DIMENSIONS = ('application', 'architecture', 'child', 'dates', 'label',
                      'metric', 'os', 'osVersion', 'version')

# Disallowed metrics for serving - matches regex
예제 #16
0
 def _create_blogging_engine(self):
     cache = Cache(self.app, config={"CACHE_TYPE": "simple"})
     return BloggingEngine(self.app, self.storage, cache=cache)
예제 #17
0
CONFIG_MODULE = os.environ.get('SUPERSET_CONFIG', 'superset.config')

app = Flask(__name__)
app.config.from_object(CONFIG_MODULE)
conf = app.config

if not app.debug:
    # In production mode, add log handler to sys.stderr.
    app.logger.addHandler(logging.StreamHandler())
    app.logger.setLevel(logging.INFO)

db = SQLA(app)

utils.pessimistic_connection_handling(db.engine.pool)

cache = Cache(app, config=app.config.get('CACHE_CONFIG'))

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)
예제 #18
0
from flask_cache import Cache
from aiida.restapi.api import app
from aiida.restapi.common.config import cache_config

#Would be nice to be able to specify here what has to be cached or not!
#Probably this is not doable because cachced and memoize only work as decorators
cache = Cache(app, config=cache_config)
예제 #19
0
def register_cache(app):
    cache = Cache()
    return cache
예제 #20
0
def create_app(test_config=None):
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)

    app.config.from_mapping(
        SECRET_KEY='dev',
        DATABASE=os.path.join(app.instance_path, 'eyesight.sqlite'),
    )

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile('config.py', silent=True)
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    CORS(app, support_credentials=True)

    # 使用Flask-Cache
    # http://www.pythondoc.com/flask-cache/index.html

    # Check Configuring Flask-Cache section for more details
    cache = Cache(app, config={'CACHE_TYPE': 'simple'})
    cache.init_app(app)

    cachePortrait = Cache(app, config={'CACHE_TYPE': 'simple'})
    cachePortrait.init_app(app)

    @cache.cached(timeout=5, key_prefix='classIdCnt')
    def cache_classIdCnt(method, data):
        if (method == "save"):
            saved_id = json.dumps(data)
            cache.set('classidcnt', saved_id, timeout=5)

            print("classid缓存成功")
        elif (method == "load"):
            return cache.get('classidcnt')

    @cachePortrait.cached(timeout=5, key_prefix='portrait')
    def cache_portrait(method, data):
        if (method == "save"):

            saved_portrait = json.dumps(data)
            #print(saved_portrait)
            cache.set('portrait', saved_portrait, timeout=5)

            print("portrait缓存成功")
        elif (method == "load"):
            print(cache.get('portrait'))
            return cache.get('portrait')

    #Video streaming generator function
    def gen(type):
        while True:
            if type == 'POST':
                fopen = [open('loaded.jpg', 'rb').read()]
                frame = fopen[0]
                time.sleep(0.1)
                yield (b'--frame\r\n'
                       b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')

            elif type == 'UDP':
                sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

                host = ''
                port = 1082
                server_address = (host, port)

                #允许复用地址
                sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
                sock.bind(server_address)
                print("UDP LINK BIND COMPLETE")
                data, server = sock.recvfrom(65507)
                print("Fragment size : {}".format(len(data)))
                if len(data) == 4:
                    # This is a message error sent back by the server
                    if (data == "FAIL"):
                        continue
                yield (b'--frame\r\n'
                       b'Content-Type: image/jpeg\r\n\r\n' + data + b'\r\n')

    # a simple page that says hello
    @app.route('/hello', methods=['GET', 'POST'])
    def hello():
        if (request.method == 'POST'):
            post_json = request.get_json()
            return jsonify({'you sent': post_json}), 201
        else:
            return jsonify({'about': "Hello World"})

    # route带参数
    #  http://127.0.0.1:5000/multi/100
    @app.route('/multi/<int:num>', methods=['GET'])
    def get_multuply(num):
        return jsonify({'result': num * 10})

    # API Objectdatas resource

    @app.route('/api/objectdatas', methods=['GET', 'POST'])
    def api_objects():
        if (request.method == 'POST'):
            objects_json = request.get_json()
            obj_ndarray = np.array(objects_json['data'][1])
            obj_name = objects_json['data'][0]
            print(obj_ndarray)
            cv2.imwrite('eyesight/objectdatas/%s.jpg' % obj_name, obj_ndarray)
            print("目标剪切图片保存完成")
            return 201

        else:
            print("GET")

    # API livestream
    @app.route('/api/livestream/udp', methods=['GET'])
    def api_livestream():
        # Create a UDP socket

        return Response(gen('UDP'),
                        mimetype='multipart/x-mixed-replace; boundary=frame')

    # API classid
    # 每一帧目标捕获数统计
    @app.route('/api/classid', methods=['GET', 'POST'])
    def api_classid():
        if (request.method == 'POST'):
            classid_json = request.get_json()

            classid_data = classid_json['data']
            print(classid_data)
            cache_classIdCnt("save", classid_data)

            return jsonify({'clasdid_data': classid_data}), 201

        elif (request.method == 'GET'):

            print("GET CLASS ID---")
            print(cache_classIdCnt("load", None))
            return cache_classIdCnt("load", None)

    #API portrait
    @app.route('/api/portrait', methods=['GET', 'POST'])
    def api_portrait():
        if (request.method == 'POST'):
            portrait_json = request.get_json()

            portrait_data = portrait_json['data']
            print('[POST Portrait Data]')

            cache_portrait("save", portrait_data)
            return jsonify({'portrait_data': portrait_data}), 201

        elif (request.method == 'GET'):
            print("[GET Portrait Data]")

            print(cache_portrait("load", None))
            return cache_portrait("load", None)

    # sample
    #serach query
    @app.route('/search', methods=['GET', 'POST'])
    @cross_origin(supports_credentials=True)
    def search():
        params = {'query': request.args.get('query')}
        if params['query'] == 'test':
            persons = [{
                'name': 'david',
                'age': 10
            }, {
                'name': 'black',
                'age': 19
            }]
            print("test")
            return json.dumps(persons)

        if params['query'] == 'object':
            path = 'eyesight/objectdatas'
            datas = []
            for file in os.listdir(path):
                name = file.split(':', 1)[0]
                value = file.split(':', 1)[1][:-3]
                #img = cv2.imread(path + '/'+file).tolist()
                with open(path + '/' + file, 'rb') as f:
                    img = base64.b64encode(f.read())
                img = img.decode('utf-8')  #将image2str转为str
                #imgstr = bytes.decode(img)
                #img = Response(img, mimetype="image/jpeg")
                #print(name+value)
                datas.append({'img': img, 'name': name, 'value': value})
            #print(datas)
            return json.dumps(datas)

        return "OK"

    from . import db
    db.init_app(app)

    from . import auth
    app.register_blueprint(auth.bp)
    return app
예제 #21
0
from flask_bootstrap import Bootstrap
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_uploads import UploadSet, configure_uploads, patch_request_class, IMAGES
from flask_mail import Mail
from flask_login import LoginManager
from flask_moment import Moment
from flask_cache import Cache
bootstrap = Bootstrap()
db = SQLAlchemy()
migrate = Migrate(db=db)
mail = Mail()
login_manager = LoginManager()
file = UploadSet('photos', IMAGES)
moment = Moment()
cache = Cache(config={'CACHE_TYPE': 'simple'})  #缓存类型simple(内存)
# cache = Cache(config={'CACHE_TYPE':'redis'})#缓存类型redis(redis数据库)


def config_extensions(app):
    bootstrap.init_app(app)
    db.init_app(app)
    migrate.init_app(app)
    mail.init_app(app)
    moment.init_app(app)
    cache.init_app(app)
    configure_uploads(app, file)
    patch_request_class(app, size=None)

    login_manager.init_app(app)
    #指定登录端点
예제 #22
0
파일: __init__.py 프로젝트: Xzya/navitia
    headers=['Access-Control-Request-Headers', 'Authorization'],
)
app.config['CORS_HEADERS'] = 'Content-Type'

app.wsgi_app = ReverseProxied(app.wsgi_app)
got_request_exception.connect(log_exception, app)

# we want the old behavior for reqparse
compat.patch_reqparse()

rest_api = Api(app, catch_all_404s=True, serve_challenge_on_401=True)

from navitiacommon.models import db

db.init_app(app)
cache = Cache(app, config=app.config['CACHE_CONFIGURATION'])

if app.config['AUTOCOMPLETE_SYSTEMS'] is not None:
    global_autocomplete = {
        k: utils.create_object(v)
        for k, v in app.config['AUTOCOMPLETE_SYSTEMS'].items()
    }
else:
    from jormungandr.autocomplete.kraken import Kraken

    global_autocomplete = {'kraken': Kraken()}

from jormungandr.instance_manager import InstanceManager

i_manager = InstanceManager(
    instances_dir=app.config.get('INSTANCES_DIR', None),
예제 #23
0
#配置第3方库-插件
from flask_bootstrap import Bootstrap
from flask_cache import Cache

from flask_login import LoginManager
from flask_migrate import Migrate
from flask_session import Session
from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()
migrate = Migrate()
lm = LoginManager()

cache = Cache(config={
    "CACHE_TYPE" : "redis",
    "CACHE_KEY_PREFIX" : "CA-",
})


def init_ext(app):
    db.init_app(app)
    Session(app=app)
    migrate.init_app(app=app,db=db)
    Bootstrap(app=app)
    cache.init_app(app=app)
    lm.init_app(app=app)
예제 #24
0
 def init_app(self, app):
     """Flask application initialization."""
     self.cache = Cache(app)
     self.app = app
     app.extensions['zenodo-cache'] = self
예제 #25
0
파일: app.py 프로젝트: jin10086/ip-api
from flask_cors import CORS
from flask_redis import FlaskRedis
from celery import Celery

import pymongo
import logging
import json
import os


app = Flask(__name__)
CORS(app, origins=["*"])
app.config.from_pyfile("config.py")
api = Api(app)
mongo = PyMongo(app)
cache = Cache(app, config={"CACHE_TYPE": "redis"})
redis_store = FlaskRedis(app)

parser = reqparse.RequestParser()
parser.add_argument("ssinfo", location="json", required=True)


class Ip(Resource):

    def post(self):
        args = parser.parse_args()
        print(args.ssinfo)
        data = eval(args.ssinfo)
        update_squid_conf(data["ip_port"])
        # save2db(data, 'ip_port')
        return {"data": data}
예제 #26
0
def create_app(config=None, testing=False):
    app = Flask(__name__)
    app.secret_key = configuration.get('webserver', 'SECRET_KEY')
    app.config['LOGIN_DISABLED'] = not configuration.getboolean(
        'webserver', 'AUTHENTICATE')

    csrf.init_app(app)

    airflow.load_login()
    airflow.login.login_manager.init_app(app)

    from airflow import api
    api.load_auth()
    api.api_auth.init_app(app)

    cache = Cache(app=app,
                  config={
                      'CACHE_TYPE': 'filesystem',
                      'CACHE_DIR': '/tmp'
                  })

    app.register_blueprint(routes)

    log_format = airflow.settings.LOG_FORMAT_WITH_PID
    airflow.settings.configure_logging(log_format=log_format)

    with app.app_context():
        from airflow.www import views

        admin = Admin(
            app,
            name='Airflow',
            static_url_path='/admin',
            index_view=views.HomeView(endpoint='', url='/admin', name="DAGs"),
            template_mode='bootstrap3',
        )
        av = admin.add_view
        vs = views
        av(vs.Airflow(name='DAGs', category='DAGs'))

        av(vs.QueryView(name='Ad Hoc Query', category="Data Profiling"))
        av(
            vs.ChartModelView(models.Chart,
                              Session,
                              name="Charts",
                              category="Data Profiling"))
        av(
            vs.KnownEventView(models.KnownEvent,
                              Session,
                              name="Known Events",
                              category="Data Profiling"))
        av(
            vs.SlaMissModelView(models.SlaMiss,
                                Session,
                                name="SLA Misses",
                                category="Browse"))
        av(
            vs.TaskInstanceModelView(models.TaskInstance,
                                     Session,
                                     name="Task Instances",
                                     category="Browse"))
        av(vs.LogModelView(models.Log, Session, name="Logs",
                           category="Browse"))
        av(
            vs.JobModelView(jobs.BaseJob,
                            Session,
                            name="Jobs",
                            category="Browse"))
        av(
            vs.PoolModelView(models.Pool,
                             Session,
                             name="Pools",
                             category="Admin"))
        av(vs.ConfigurationView(name='Configuration', category="Admin"))
        av(
            vs.UserModelView(models.User,
                             Session,
                             name="Users",
                             category="Admin"))
        av(
            vs.ConnectionModelView(models.Connection,
                                   Session,
                                   name="Connections",
                                   category="Admin"))
        av(
            vs.VariableView(models.Variable,
                            Session,
                            name="Variables",
                            category="Admin"))
        av(vs.XComView(models.XCom, Session, name="XComs", category="Admin"))

        admin.add_link(
            base.MenuLink(category='Docs',
                          name='Documentation',
                          url='http://pythonhosted.org/airflow/'))
        admin.add_link(
            base.MenuLink(category='Docs',
                          name='Github',
                          url='https://github.com/apache/incubator-airflow'))

        av(vs.VersionView(name='Version', category="About"))

        av(
            vs.DagRunModelView(models.DagRun,
                               Session,
                               name="DAG Runs",
                               category="Browse"))
        av(vs.DagModelView(models.DagModel, Session, name=None))
        # Hack to not add this view to the menu
        admin._menu = admin._menu[:-1]

        def integrate_plugins():
            """Integrate plugins to the context"""
            from airflow.plugins_manager import (admin_views, flask_blueprints,
                                                 menu_links)
            for v in admin_views:
                logging.debug('Adding view ' + v.name)
                admin.add_view(v)
            for bp in flask_blueprints:
                logging.debug('Adding blueprint ' + bp.name)
                app.register_blueprint(bp)
            for ml in sorted(menu_links, key=lambda x: x.name):
                logging.debug('Adding menu link ' + ml.name)
                admin.add_link(ml)

        integrate_plugins()

        import airflow.www.api.experimental.endpoints as e
        # required for testing purposes otherwise the module retains
        # a link to the default_auth
        if app.config['TESTING']:
            if six.PY2:
                reload(e)
            else:
                import importlib
                importlib.reload(e)

        app.register_blueprint(e.api_experimental,
                               url_prefix='/api/experimental')

        @app.context_processor
        def jinja_globals():
            return {
                'hostname': socket.getfqdn(),
            }

        @app.teardown_appcontext
        def shutdown_session(exception=None):
            settings.Session.remove()

        return app
예제 #27
0
 def test_19_dict_config_both(self):
     cache = Cache(config={'CACHE_TYPE': 'null'})
     cache.init_app(self.app, config={'CACHE_TYPE': 'simple'})
     from werkzeug.contrib.cache import SimpleCache
     assert isinstance(self.app.extensions['cache'][cache], SimpleCache)
예제 #28
0
import db
import re
import html
from functools import wraps

from datetime import datetime, date, timedelta as td
from flask import Flask, abort, render_template, session, url_for, request, jsonify, redirect, request, make_response
from flask_cache import Cache
from flask.ext.github import GitHub

app = Flask(__name__)
app.config.from_pyfile("app.cfg")
connect("lxlogbot")
cache = Cache(app,
              config={
                  'CACHE_TYPE': 'simple',
                  'CACHE_DEFAULT_TIMEOUT': 3600
              })
github = GitHub(app)
sc = SlackClient(app.config['SLACK_TOKEN'])


@app.cli.command()
def update_cache():
    """Updates username/channel cache"""

    #Get unique channel list
    for c in db.Message.objects().distinct('c'):
        if not db.Channel.objects(cid=c):
            chan = sc.api_call('channels.info', channel=c)
            if 'ok' in chan and chan['ok']:
예제 #29
0
# pylint: disable=invalid-name
app = Flask("kernelci-frontend")

app.root_path = os.path.abspath(os.path.dirname(__file__))

app.config.from_object("dashboard.default_settings")
if os.path.isfile(DEFAULT_CONFIG_FILE):
    app.config.from_pyfile(DEFAULT_CONFIG_FILE)

if os.environ.get(APP_ENVVAR):
    app.config.from_envvar(APP_ENVVAR)

# Save the function.
app_conf_get = app.config.get

app.cache = Cache(app)
app.csrf = CsrfProtect(app)

# Use the custom CSRF token generation.
app.jinja_env.globals["csrf_token_r"] = generate_csrf_token

# Add the custom regular expression converter.
app.url_map.converters["regex"] = RegexConverter

# Initialize the app routes, config and other necessary stuff.
# The app context here is needed since we are using variables defined in the
# config files and we need to access them.
with app.app_context():
    import dashboard.utils.backend as backend
    import dashboard.utils.route as route
예제 #30
0
from flask import Flask, request
from flask_cache import Cache
import urllib
import subprocess

cache_config = {
    'CACHE_TYPE': 'redis',
    'CACHE_REDIS_HOST': '127.0.0.1',
    'CACHE_REDIS_PORT': 6379,
    'CACHE_REDIS_DB': '',
    'CACHE_REDIS_PASSWORD': ''
}
cache = Cache(config=cache_config)


class Colors(object):
    def __init__(self):
        self.cache = {}

    def compute(self, url):
        if url in self.cache:
            print "get from dict.."
            return self.cache[url]
        else:
            print "compute.."
            filename = url.split('/')[-1]
            urllib.urlretrieve(url, './%s' % filename)

            k = subprocess.check_output("identify -format %k ./" + filename,
                                        shell=True)
            self.cache[url] = k