Exemplo n.º 1
0
def create_app(config):
    def _initialize(app):
        """Load the external website settings and assets configurations into current application
        :param app:
        :return:
        """
        if app.initialized:
            return app

        cwd = app.path

        config_file = path.join(cwd, '_config.yml')
        asset_file = path.join(cwd, "_assets.yml")

        if path.exists(config_file):
            settings = yaml.load(open(config_file).read())
            app.site = Site(**settings)
            app.config['BABEL_DEFAULT_LOCALE'] = getattr(
                app.site, 'lang', 'en')
        else:
            raise IOError(
                'System initialize fail: the `_config.yml` can not be found in the root of current website.'
            )

        path.exists(asset_file) and app.assets_env.register(
            YAMLLoader(asset_file).load_bundles())

        app.url_map.converters['regex'] = RegexConverter
        app.initialized = True

        return app

    app = Flask(__name__, static_url_path='/static/vendors')
    app.config.from_object(config)

    Bootstrap(app)
    babel = Babel(app)
    app.pages = FlatPages(app)
    app.assets_env = Environment(app)
    app.path = config.APP_PATH
    app.init = lambda: _initialize(app)
    app.initialized = False
    app.url_map.converters['regex'] = RegexConverter

    @babel.localeselector
    def get_local():

        if hasattr(g, 'lang'):
            _lang = getattr(g, 'lang', 'en')
        else:
            _lang = getattr(app.site, 'lang', 'en')

        if _lang != '':
            return _lang
        else:
            return 'en'

    return app
Exemplo n.º 2
0
def create_app(config):
    def _initialize(app):
        """Load the external website settings and assets configurations into current application
        :param app:
        :return:
        """
        if app.initialized:
            return app

        cwd = app.path

        config_file = path.join(cwd, '_config.yml')
        asset_file = path.join(cwd, "_assets.yml")

        if path.exists(config_file):
            settings = yaml.load(open(config_file).read())
            app.site = Site(**settings)
            app.config['BABEL_DEFAULT_LOCALE'] = getattr(app.site, 'lang', 'en')
        else:
            raise IOError('System initialize fail: the `_config.yml` can not be found in the root of current website.')

        path.exists(asset_file) and app.assets_env.register(YAMLLoader(asset_file).load_bundles())

        app.url_map.converters['regex'] = RegexConverter
        app.initialized = True

        return app

    app = Flask(__name__, static_url_path='/static/vendors')
    app.config.from_object(config)

    Bootstrap(app)
    babel = Babel(app)
    app.pages = FlatPages(app)
    app.assets_env = Environment(app)
    app.path = config.APP_PATH
    app.init = lambda: _initialize(app)
    app.initialized = False
    app.url_map.converters['regex'] = RegexConverter

    @babel.localeselector
    def get_local():

        if hasattr(g,'lang'):
            _lang = getattr(g, 'lang', 'en')
        else :
            _lang = getattr(app.site, 'lang', 'en')

        if _lang != '':
            return _lang
        else:
            return 'en'

    return app
Exemplo n.º 3
0
def create_app(path, config, test=False):
    app = Flask(__name__, static_folder='base/static')
    app.config.from_object(config)
    app.path = path
    register_extensions(app, test)
    register_blueprints(app)
    configure_login_manager(app)
    configure_database(app, test)
    configure_rest_api(app)
    configure_logs(app)
    return app
Exemplo n.º 4
0
def create_app(path):
    app = Flask(__name__, static_folder='public')
    app.config.from_object(app_config_dict['Development'])
    app.production = not app.config['DEBUG']
    app.path = path
    CORS(app)  # CORS handler
    register_blueprints(app)
    configure_database(app)
    # if app.production:
    #     app.vault_client = create_vault_client(app)
    return app
Exemplo n.º 5
0
def create_app(path, config):
    app = Flask(__name__, static_folder='base/static')
    app.config.from_object(config)
    app.production = not app.config['DEBUG']
    app.path = path
    register_blueprints(app)
    configure_database(app)
    if app.production:
        app.vault_client = create_vault_client(app)

    return app
Exemplo n.º 6
0
def create_app(path, test=False, selenium=False):
    app = Flask(__name__, static_folder='base/static')
    if selenium:
        app.config.from_object(config_dict['Selenium'])
    else:
        app.config.from_object(config_mode)
    app.path = path
    register_extensions(app, test)
    register_blueprints(app)
    configure_login_manager(app)
    configure_database(app, test)
    configure_rest_api(app)
    configure_logs(app)
    return app
Exemplo n.º 7
0
def create_app(path: Path, config: str) -> Flask:
    app = Flask(__name__, static_folder="static")
    app.config.from_object(config_mapper[config.capitalize()])  # type: ignore
    app.mode = app.config["MODE"]
    app.path = path
    register_extensions(app)
    configure_login_manager(app)
    controller.init_services()
    configure_database(app)
    controller.init_forms()
    configure_cli(app)
    configure_context_processor(app)
    configure_rest_api(app)
    configure_errors(app)
    configure_authentication()
    return app
Exemplo n.º 8
0
def create_app(path, config):
    app = Flask(__name__, static_folder='base/static')
    app.config.from_object(config)
    app.production = not app.config['DEBUG']
    app.path = path
    register_extensions(app)
    register_blueprints(app)
    configure_login_manager(app)
    configure_database(app)
    configure_rest_api(app)
    configure_logs(app)
    configure_errors(app)
    if app.config['USE_VAULT']:
        app.vault_client = create_vault_client(app)
    info('eNMS starting')
    return app
Exemplo n.º 9
0
def create_app(path: Path, config_class: Type[Config]) -> Flask:
    app = Flask(__name__, static_folder="base/static")
    app.config.from_object(config_class)  # type: ignore
    app.path = path
    register_extensions(app)
    register_blueprints(app)
    configure_login_manager(app)
    configure_database(app)
    configure_rest_api(app)
    configure_logs(app)
    configure_errors(app)
    if USE_VAULT:
        configure_vault_client(app)
    if USE_SYSLOG:
        configure_syslog_server(app)
    info("eNMS starting")
    return app
Exemplo n.º 10
0
import concurrent.futures
import flask
import requests

from flask import Flask, request

import index



app = Flask(__name__)
logging.getLogger("concurrent.futures").addHandler(logging.StreamHandler())
num_clients = 3
port = 9090
app.indexed = False
app.path = None

session = requests.Session()
pool = concurrent.futures.ThreadPoolExecutor(num_clients + 1)

def request_clients(path, params=None):
    results = []
    for i in range(1, num_clients+1):
        url = "http://localhost:%d%s" % (port + i, path,)
        results.append(pool.submit(session.get, *(url,), params=params))
    return [result.result() for result in results]


def _indexer(path):
    ix = index.Index(app.id)
    ix.index_path(path)
Exemplo n.º 11
0
from flask_pymongo import PyMongo

from celery import Celery
from elasticsearch import Elasticsearch, Urllib3HttpConnection
# import certifi


if getattr(sys, 'frozen', False):
    app_path = os.path.abspath(os.path.dirname(sys.executable))
elif __file__:
    app_path = os.path.abspath(os.path.dirname(__file__))+'/..'


app = Flask(__name__, static_folder=app_path+'/files', template_folder=app_path+'/layouts')

app.path = app_path
app.config.from_pyfile(app.path+'/config/environment.py')
try:
	app.config.from_pyfile(app.path+'/config/environment_dev.py')
except FileNotFoundError:
	pass

app.jinja_env.add_extension('jinja2.ext.do')
app.jinja_env.add_extension('jinja2.ext.loopcontrols')

app.mongo = PyMongo(app)
app.caches = {}


# app.search = Elasticsearch(
# 	app.config['ELASTICSEARCH_HOST'].split(','),
Exemplo n.º 12
0
import requests
import os
import glob
from functools import wraps
from passlib.apps import custom_app_context as passHash

from utils import *
from stub import *

app = Flask(__name__)
app.secret_key = "super secret key"

home_dir = os.path.expanduser("~")
app.root = os.path.join(home_dir, ".usablepgp")

app.path = app.root
app.tmp_path = os.path.join(app.path, "tmp")

previous_dec = {}

API_ROUTE = {
    "get_user": "******",
    "get_users": "http://localhost:5000/get_users/",
    "insert_users": "http://localhost:5000/insert_users/",
    "delete_user": "******",
    "update_public_key": "http://localhost:5000/update_public_key/",
    "test_api": "http://localhost:5000/test_api/",
}


def update_path(path):
Exemplo n.º 13
0
app = Flask(__name__)
app.logger_name = 'app.flask'
app.logger.setLevel(logging.NOTSET)
rest_api = Api(app=app)

_logger = logging.getLogger('app')
_logger.setLevel(logging.DEBUG)

logging.getLogger('werkzeug').setLevel(logging.DEBUG)
logging.getLogger('authlib').setLevel(logging.DEBUG)

hashfs = HashFS('app/uploads/')
mimetypes.init()

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


def static_url(url):
    return url + '?v=' + version


def is_module(path: str) -> bool:
    init_path = os.path.join(path, '__init__.py')

    if os.path.isdir(path) and os.path.exists(init_path):
        return True
    elif os.path.isfile(path) and os.path.splitext(path)[1] == '.py':
        return True

    return False
Exemplo n.º 14
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from flask import Flask, render_template, flash, redirect, request, url_for, Markup
import glob
import os
import sys
import subprocess, signal
import stat

app = Flask(__name__)
app.secret_key = "some_secret"
app.path = "/mnt/Movies"
app.fifo = "/home/pi/omx.pipe"


def fifo():
    if os.path.exists(app.fifo):
        pass
    else:
        os.system("mkfifo " + app.fifo)


@app.route("/")
def home():
    if os.path.exists(app.path):
        os.chdir(app.path)
    else:
        sys.exit("Check Path")

    names = []