Example #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
Example #2
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)
Example #3
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
#!/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 = []