Prepare for multi-version setup wizard

master
kaiyou 7 years ago
parent 90ba755abc
commit 88903bc6f5

@ -1,3 +1,4 @@
flask
flask-bootstrap
redis
gitpython

@ -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)
])
def render_flavor(flavor, template, **context):
path = os.path.join(flavor, template)
return flask.render_template(path, **context)
@bp.route("/")
def wizard():
return flask.render_template('wizard.html')
@app.route("/")
def index():
return flask.render_template('index.html')
@app.route("/setup", methods=["POST"])
@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)

@ -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))
Loading…
Cancel
Save