diff --git a/config/requirements.txt b/config/requirements.txt index 88ea3d75..0f36f4bb 100644 --- a/config/requirements.txt +++ b/config/requirements.txt @@ -1,3 +1,4 @@ flask flask-bootstrap redis +gitpython diff --git a/config/server.py b/config/server.py index a0e3564f..4246410b 100644 --- a/config/server.py +++ b/config/server.py @@ -8,28 +8,34 @@ app = flask.Flask(__name__) flask_bootstrap.Bootstrap(app) db = redis.StrictRedis(host='localhost', port=6379, db=0) -app.jinja_loader = jinja2.ChoiceLoader([ - app.jinja_loader, - jinja2.FileSystemLoader("flavors"), -]) + +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') -def render_flavor(flavor, template, **context): - path = os.path.join(flavor, template) - return flask.render_template(path, **context) + @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)) -@app.route("/") -def index(): - return flask.render_template('index.html') - - -@app.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) if __name__ == "__main__": + build_app("/tmp/mailutest") app.run(debug=True) diff --git a/config/setup.py b/config/setup.py new file mode 100644 index 00000000..4cff7a43 --- /dev/null +++ b/config/setup.py @@ -0,0 +1,35 @@ +import git +import tempfile +import argparse +import os +import shutil +import re + + +VERSION_BRANCH = re.compile("(master|\d+\.\d+)") + + +def main(upstream, dest): + shutil.rmtree(dest, ignore_errors=True) + os.makedirs(dest, exist_ok=True) + with tempfile.TemporaryDirectory() as clone_path: + repo = git.Repo.clone_from(upstream, clone_path) + for branch in repo.refs: + if not branch.name.startswith("origin/"): + continue + name = branch.name[len("origin/"):] + if not VERSION_BRANCH.match(name): + continue + branch.checkout() + config_path = os.path.join(clone_path, "config") + if os.path.exists(config_path): + shutil.copytree(config_path, os.path.join(dest, name)) + print("Imported branch {}".format(name)) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("upstream", help="Path to Mailu git repository") + parser.add_argument("dest", help="Destination directory for data files") + args = parser.parse_args() + main(**vars(args)) diff --git a/config/templates/index.html b/config/templates/wizard.html similarity index 100% rename from config/templates/index.html rename to config/templates/wizard.html