]> Lady’s Gitweb - x_status_git/commitdiff
Fix glob iterators to not error when empty
authorLady <redacted>
Sat, 16 Dec 2023 05:09:46 +0000 (00:09 -0500)
committerLady <redacted>
Sat, 23 Dec 2023 20:17:52 +0000 (15:17 -0500)
Python throws an error if no default is provided; provide a default of
`None`.

post-receive

index d273055f13a8bc2741fd70a0960898463fc6b886..46c75c4db2bc02dbf878f6b52c99a612f2ba817b 100755 (executable)
@@ -68,23 +68,23 @@ if stdin.read().split()[-1] == f"refs/heads/{LIVE_BRANCH}":
        # The provided path must be to a `text` object.
        def statusmap (topic, path):
                status = { "@type": "MicroblogPost" }
-               version_path = next(path.parent.glob("0=*"))
+               version_path = next(path.parent.glob("0=*"), None)
                if version_path and version_path.name != "0=x_status_git_1.0":
                        warn(f"Unrecognized version for {path}; skipping.")
                        return None
                if topic:
                        status["subject"] = topic
-               author_path = next(path.parent.glob("1=*"))
+               author_path = next(path.parent.glob("1=*"), None)
                if author_path:
                        status["author"] = { "name": author_path.name[2:] }
                        with author_path.open("r", encoding="utf-8") as text:
                                status["author"]["@id"] = text.read().strip()
-               title_path = next(path.parent.glob("2=*"))
+               title_path = next(path.parent.glob("2=*"), None)
                if title_path:
                        with title_path.open("r", encoding="utf-8") as text:
                                title = text.read().strip()
                                status["title"] = title
-               date_path = next(path.parent.glob("3=*"))
+               date_path = next(path.parent.glob("3=*"), None)
                datetime = ""
                if date_path:
                        with date_path.open("r", encoding="utf-8") as text:
@@ -93,7 +93,7 @@ if stdin.read().split()[-1] == f"refs/heads/{LIVE_BRANCH}":
                else:
                        warn(f"Missing date for {path}; skipping.")
                        return None
-               identifier_path = next(path.parent.glob("4=*"))
+               identifier_path = next(path.parent.glob("4=*"), None)
                identifier = ""
                if identifier_path:
                        identifier = identifier_path.name[2:]
This page took 0.023799 seconds and 4 git commands to generate.