-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
74 lines (56 loc) · 2.21 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
import sys
from flask import Flask
from flask.ext.script import Manager
from flask.ext.seasurf import SeaSurf
from flask_collect import Collect
import gru.utils.web
import gru.utils.templates
import gru.utils.logs
import gru.utils.fs
from gru.config import settings
from gru.plugins.loader.registry import PluginRegistry
from gru.contrib.auth.sessions import ItsdangerousSessionInterface
from gru.contrib.auth.views import blueprint as auth_views
from gru.contrib.inventory.views import blueprint as inventory_views
def generate_app():
app = Flask(
__name__,
template_folder=gru.utils.fs.relative_to(__file__, 'gru/templates'),
static_folder=gru.utils.fs.relative_to(__file__, 'gru/static'))
app.debug = settings.get('flask.debug')
app.permanent_session_lifetime = settings.get('flask.session_seconds')
# Client-side sessions with signed cookies
app.secret_key = settings.get('flask.secret_key')
app.session_interface = ItsdangerousSessionInterface()
# Setup logging
gru.utils.logs.setup_logging(app, settings)
# CSRF protection
SeaSurf(app)
# Load sub-applications
app.register_blueprint(auth_views, url_prefix='/auth')
app.register_blueprint(inventory_views, url_prefix='/inventory')
# Append plugin paths to sys.path
for directory in settings.get('plugins.directories'):
sys.path.append(os.path.abspath(os.path.expanduser(directory)))
# Register plugins
root_path = os.path.realpath(__file__)
app.plugins = PluginRegistry(app, settings)
for plugin_path in settings.get('plugins.modules'):
app.plugins.register(plugin_path)
# Also add authentication backend and inventory provider
app.plugins.register(settings.get('authentication.backend'))
app.plugins.register(settings.get('inventory.provider'))
gru.utils.templates.setup(app)
gru.utils.web.setup_base_views(app, settings)
app.wsgi_app = gru.utils.web.method_rewrite_middleware(app.wsgi_app)
return app
# Entry point.
app = generate_app()
if __name__ == '__main__':
# Wrap the app in a Flask-Scripts manager
manager = Manager(app)
collect = Collect()
collect.init_app(app)
collect.init_script(manager)
manager.run()