From 9b45187ecfef7e818ed9fae8523883114ed4aebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonah=20Br=C3=BCchert?= Date: Fri, 16 Feb 2024 21:06:37 +0100 Subject: [PATCH] Add more ci scripts --- ci/fetch-feeds.py | 31 +++++++++++++++++++++++++++++++ ci/motis-import.py | 31 +++++++++++++++++++++++++++++++ src/fetch.py | 1 + 3 files changed, 63 insertions(+) create mode 100755 ci/fetch-feeds.py create mode 100755 ci/motis-import.py mode change 100644 => 100755 src/fetch.py diff --git a/ci/fetch-feeds.py b/ci/fetch-feeds.py new file mode 100755 index 00000000..f2083cdc --- /dev/null +++ b/ci/fetch-feeds.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +# SPDX-FileCopyrightText: 2024 Jonah Brüchert +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +import sys +from pathlib import Path +import subprocess + +if len(sys.argv) < 2: + print("Argument run-reason is missing.") + print("Must be one of timer, merge-request") + sys.exit(1) + +run_reason = sys.argv[1] +feed_dir = Path("feeds/") + +match run_reason: + case "timer": + for feed in feed_dir.glob("*.json"): + subprocess.check_call(["./src/fetch.py", str(feed.absolute())]) + case "merge-request": + changed_files = subprocess.check_output( + ["git", "diff", "--name-only", "-r", "HEAD^1", "HEAD"]) \ + .decode().splitlines() + + changed_feeds = [f for f in changed_files if + f.startswith("feeds/") and f.endswith(".json")] + + for feed in changed_feeds: + subprocess.check_call(["./src/fetch.py", feed]) diff --git a/ci/motis-import.py b/ci/motis-import.py new file mode 100755 index 00000000..3321a3ca --- /dev/null +++ b/ci/motis-import.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +# SPDX-FileCopyrightText: 2024 Jonah Brüchert +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +import subprocess +import time +import sys + + +def run_motis_import() -> bool: + p = subprocess.Popen(["motis", "--import.require_successful", "1"], + stderr=subprocess.PIPE) + + for line in iter(p.stderr.readline, ""): + if p.poll(): + return False + + sys.stdout.buffer.write(line) + if b"system boot finished" in line: + p.terminate() + return True + else: + time.sleep(1) + + +if __name__ == "__main__": + if run_motis_import(): + sys.exit(0) + else: + sys.exit(1) diff --git a/src/fetch.py b/src/fetch.py old mode 100644 new mode 100755 index e29c5b37..dd025706 --- a/src/fetch.py +++ b/src/fetch.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # SPDX-FileCopyrightText: 2023 Jonah Brüchert # # SPDX-License-Identifier: AGPL-3.0-or-later