diff options
| author | toufic ar <contact@toufy.me> | 2026-05-13 23:16:11 +0300 |
|---|---|---|
| committer | toufic ar <contact@toufy.me> | 2026-05-13 23:16:11 +0300 |
| commit | b8d6c62f731c3c7886f2ecc661265eedeb65e41c (patch) | |
| tree | 88e9b424e51197af993572a722f1e5c1d1bda758 /web.py | |
| parent | aca0b3964d79e58aa1b319cbdbd7b1513ba9cfd8 (diff) | |
| download | makeshiftci-b8d6c62f731c3c7886f2ecc661265eedeb65e41c.tar.gz makeshiftci-b8d6c62f731c3c7886f2ecc661265eedeb65e41c.zip | |
test flake webui
Diffstat (limited to 'web.py')
| -rw-r--r-- | web.py | 45 |
1 files changed, 30 insertions, 15 deletions
@@ -13,20 +13,22 @@ from flask import ( stream_template, ) +MSCI_HOME = os.environ.get("MSCI_HOME") + def get_project(project: str) -> dict[str, Any]: - with open(f"./projects/{project}.json", "r") as p: + with open(f"{MSCI_HOME}/projects/{project}.json", "r") as p: return json.loads(p.read()) def get_run(project: str, run: int) -> str: - with open(f"./stdout/public/{project}/{run}", "r") as r: + with open(f"{MSCI_HOME}/stdout/public/{project}/{run}", "r") as r: return r.read() def stream_run(project: str, run: int): while True: - with open(f"./stdout/public/{project}/{run}", "r") as r: + with open(f"{MSCI_HOME}/stdout/public/{project}/{run}", "r") as r: txt = r.read() yield txt if "--MSCI_EXIT_" in txt: @@ -35,14 +37,14 @@ def stream_run(project: str, run: int): def _projects(q: queue.Queue[tuple[str, dict[str, Any]] | None]): - if os.path.isdir("./projects"): - _projects = os.listdir("./projects") + if os.path.isdir(f"{MSCI_HOME}/projects"): + _projects = os.listdir(f"{MSCI_HOME}/projects") for _p in _projects: loaded = get_project(_p.replace(".json", "")) if not loaded["hidden"]: q.put((_p.replace(".json", ""), loaded)) else: - os.mkdir("./projects") + os.mkdir(f"{MSCI_HOME}/projects") q.put(None) @@ -57,7 +59,7 @@ def projects(): def _project_runs(project: str, q: queue.Queue[dict[str, Any] | None]): - pr_stdout = f"./stdout/public/{project}" + pr_stdout = f"{MSCI_HOME}/stdout/public/{project}" if os.path.isdir(pr_stdout): _runs = sorted(os.listdir(pr_stdout), key=int) for _r in _runs: @@ -96,37 +98,43 @@ def project_runs(project: str): def project_exists(name: str): return ( - os.path.isfile(f"./projects/{name}.json") + os.path.isfile(f"{MSCI_HOME}/projects/{name}.json") and get_project(name)["hidden"] == False ) def run_exists(project: str, run: int): if project_exists(project): - if not os.path.isfile(f"./stdout/public/{project}/{run}"): + if not os.path.isfile(f"{MSCI_HOME}/stdout/public/{project}/{run}"): return False return True return False -app = Flask(__name__) +_app = Flask(__name__) +_empty = Flask(__name__) + + +@_empty.route("/", methods=["GET"]) +def ey(): + return "MSCI_HOME not set" -@app.route("/favicon.ico") +@_app.route("/favicon.ico") def favicon(): return send_from_directory( - app.root_path, + _app.root_path, "favicon.ico", mimetype="image/vnd.microsoft.icon", ) -@app.route("/", methods=["GET"]) +@_app.route("/", methods=["GET"]) def home(): return stream_template("home.html", projects=projects()) -@app.route("/<string:project>", methods=["GET"]) +@_app.route("/<string:project>", methods=["GET"]) def project(project: str): if project_exists(project): return stream_template( @@ -138,7 +146,7 @@ def project(project: str): abort(404) -@app.route("/<string:project>/<int:run>", methods=["GET"]) +@_app.route("/<string:project>/<int:run>", methods=["GET"]) def run(project: str, run: int): if run_exists(project, run): return stream_template( @@ -149,3 +157,10 @@ def run(project: str, run: int): run_number=run, ) abort(404) + + +def create_app(): + if not MSCI_HOME: + return _empty + else: + return _app |
