This repository has been archived on 2020-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
magic-app/magic_app/app.py

41 lines
1020 B
Python

from json import loads
from pathlib import Path
from flask import Flask, render_template, send_from_directory
app = Flask(__name__)
def get_apps():
"""All apps that can be installed."""
apps_path = (Path(app.root_path) / "static" / "apps.json").absolute()
try:
with open(apps_path, "r") as handle:
return [key for key in loads(handle.read())]
except Exception as exception:
print("Failed to load apps.json, saw {}".format(str(exception)))
@app.route("/")
def home():
apps = get_apps()
return render_template("index.html", apps=apps)
@app.route("/apps")
def apps_list():
return send_from_directory("static", "apps.json")
@app.route("/<app>")
def app_config(app_name):
# TODO(decentral1se): clone the app repository to somewhere under /tmp read
# all the env vars, secrets, etc. and fire up a wtform and deploy button
# using a new app.html template in the templates directory
pass
if __name__ == "__main__":
app.run(host="0.0.0.0")