forked from Mailu/Mailu
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathserver.py
41 lines (29 loc) · 1.1 KB
/
server.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
import flask
import flask_bootstrap
import redis
import os
import jinja2
app = flask.Flask(__name__)
flask_bootstrap.Bootstrap(app)
db = redis.StrictRedis(host='localhost', port=6379, db=0)
def build_app(setup_path):
for version in ("master", "1.8"):
bp = flask.Blueprint(version, __name__)
template_dir = os.path.join(setup_path, version, "templates")
flavor_dir = os.path.join(setup_path, version, "flavors")
bp.jinja_loader = jinja2.ChoiceLoader([
jinja2.FileSystemLoader(template_dir),
jinja2.FileSystemLoader(flavor_dir)
])
@bp.route("/")
def wizard():
return flask.render_template('wizard.html')
@bp.route("/setup", methods=["POST"])
def setup():
flavor = flask.request.form.get("flavor", "compose")
rendered = render_flavor(flavor, "setup.html")
return flask.render_template("setup.html", contents=rendered)
app.register_blueprint(bp, url_prefix="/{}".format(version))
if __name__ == "__main__":
build_app("/tmp/mailutest")
app.run(debug=True)