Example #1
0
def create_app(config_path=os.environ.get('FILESERVE_CONFIG_FILE', None)):
    app = Flask(__name__)

    # Load the default config file
    app.config.from_pyfile(os.path.join(base_directory, 'config.cfg'))
    # Then try to load a config file for use in production
    if config_path is not None:
        app.config.from_pyfile(config_path)

    if not app.config.get('SQLALCHEMY_DATABASE_URI', None):
        # Last resort, use SQLite database for development
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///{0}'.format(os.path.join(base_directory, 'fileserve.db'))

    if app.config.get('PRODUCTION'):
        app.use_x_sendfile = True
        app.debug = False
    else:
        app.debug = True

    db.init_app(app)
    from . import routes
    routes.init_app(app)
    return app
Example #2
0
#!/usr/bin/env python
from flask import Flask, send_from_directory
from flask import render_template, flash, redirect
import os
import json

try:
    from config import ROOT_DIR
except ImportError:
    ROOT_DIR = '/media/'

app = Flask(__name__)
app.debug = True
app.use_x_sendfile = True

#SERVER_NAME = 'localhost'
#SERVER_PORT = 5000


video_list = ['.mp4', '.webm', '.h264']
audio_list = ['.mp3', '.ogg', '.wav']


def get_file_ext(file_list):
    """
    Function to split filename into name and ext
    """
    files = []
    file_dict = {}
    for f in file_list:
        file_dict = {}
Example #3
0
def create_app(debug=True, enable_profiler=False, profiler_quiet=False, enable_timepro=False):
    """
    :param debug: whether to configure app for debug
    :param enable_profiler: enable flask profiler, causes function to return ProfilerMiddleware rather than Flask object which can be started by run_simple
    :param profiler_quiet: when profiler enabled sets whether profiler output echoed to stdout
    """
    app = Flask("iiab")
    app.url_map.strict_slashes = False
    app.use_x_sendfile = config().getboolean('WEBAPP', 'use_x_sendfile')
    app.secret_key = '1785132b4fd244a2a1ce6ae3f1d978ac'

    # Configuration items
    if debug:
        app.debug = True
        app.config['DEBUG'] = True
        app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0

    base_prefix = config().get('WEBAPP', 'base_prefix')

    blueprints = [
        (top_views.blueprint, base_prefix),
        (search_views.blueprint, base_prefix),
        (gutenberg.gutenberg, base_prefix + "books"),
        (map_views.blueprint, base_prefix + "maps"),
        (video_views.blueprint, base_prefix + "video"),
        (wikipedia_views.blueprint, base_prefix + "wikipedia"),
        (zim_views.blueprint, base_prefix + "zim"),
        (gutenberg_content_views.blueprint, base_prefix + "books"),
        (settings_views.blueprint, base_prefix + "settings"),
    ]
    for blueprint, prefix in blueprints:
        app.register_blueprint(blueprint, url_prefix=prefix)

    gutenberg.set_flask_app(app)
    gutenberg.init_db()

    configure_babel(app)

    # Auto Index the software repository
    autoindex = AutoIndex(app, add_url_rules=False)
    # FIXME: this should be done more elegantly -bcg'13

    @app.route(base_prefix + 'software/<path:path>')
    @app.route(base_prefix + 'software')
    def software_view(path='.'):
        software_dir = config().get_path('SOFTWARE', 'software_dir')
        return autoindex.render_autoindex(path, browse_root=software_dir, endpoint='software_view')

    #print "URL MAP: ", app.url_map

    # Static handling from http://flask.pocoo.org/mailinglist/archive/2011/8/25/static-files-subdomains/#9237e5b3c217b2875c59daaac4c23487
    app.config['STATIC_ROOT'] = config().get_default('WEBAPP', 'static_url_path', None)

    def static(path):
        root = app.config.get('STATIC_ROOT', None)
        if root is None:  # fallback on the normal way
            return url_for('static', filename=path)
        return urlparse.urljoin(root, path)

    @app.context_processor
    def inject_static():
        return dict(static=static)

    if enable_profiler:
        from werkzeug.contrib.profiler import ProfilerMiddleware, MergeStream
        f = open('profiler.log', 'w')
        if profiler_quiet:
            profile_app = ProfilerMiddleware(app, f, profile_dir="/tmp")
        else:
            stream = MergeStream(sys.stdout, f)
            profile_app = ProfilerMiddleware(app, stream, profile_dir="/tmp")
        return profile_app

    if enable_timepro:
        from timepro_flask import TimeProMiddleware, MergeStream
        f = open('timepro.log', 'w')
        if profiler_quiet:
            profile_app = TimeProMiddleware(app, f, profile_dir="/tmp")
        else:
            stream = MergeStream(sys.stdout, f)
            profile_app = TimeProMiddleware(app, stream, profile_dir="/tmp")
        return profile_app


    return app
Example #4
0
            path_info = environ['PATH_INFO']
            if path_info.startswith(script_name):
                environ['PATH_INFO'] = path_info[len(script_name):]
        scheme = environ.get('HTTP_X_SCHEME', '')
        if scheme:
            environ['wsgi.url_scheme'] = scheme
        return self.app(environ, start_response)


app = Flask(__name__, **config)
app.secret_key = os.urandom(20)
app.permanent_session_lifetime = timedelta(days=1)
app.config.from_pyfile("config.py")
app.prefix = "/times/"
app.wsgi_app = ReservePoxied(app.wsgi_app)
app.use_x_sendfile = not app.config['DEBUG']
if not app.debug:
    app.logger.setLevel(logging.INFO)
    app.logger.addHandler(logging.StreamHandler())
    app.logger.info("Start Times Web Server Logging")


class CustomJsonEncoder(JSONEncoder):

    def default(self, obj):
        try:
            if isinstance(obj, datetime):
                return obj.isoformat() + "+0800"
            iterable = iter(obj)
        except TypeError:
            pass
# License for the specific language governing permissions and limitations
# under the License.

from __future__ import with_statement

import logging
import os
import sys

from werkzeug.wsgi import DispatcherMiddleware
from flask import Flask

from airbrush.main import app as airbrush

interpreter = os.path.expanduser("~/local/bin/python")
if sys.executable != interpreter:
    os.execl(interpreter, interpreter, *sys.argv)

app = Flask(__name__)
app.use_x_sendfile = False

handler = logging.FileHandler("error.log")
handler.setLevel(logging.WARNING)
app.logger.addHandler(handler)

app = DispatcherMiddleware(app, {
    "/h": airbrush,
})

application = app