about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMunyoki Kilyungi2024-03-28 17:54:06 +0300
committerBonfaceKilz2024-04-02 13:55:15 +0300
commit7252ea1ef81530f02af11b3e8fdd333991152815 (patch)
tree281e2a19bf4b92814adfc25e2abe746f087c3e89
parentae56e74b3fd759bdb12a368ce34813b1e20f91e3 (diff)
downloadgenenetwork2-7252ea1ef81530f02af11b3e8fdd333991152815.tar.gz
Properly chain all the git and write operations together.
* gn2/wqflask/edit.py (save_dataset_metadata): Chain running the git
commands and the write operation together.

Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
-rw-r--r--gn2/wqflask/edit.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/gn2/wqflask/edit.py b/gn2/wqflask/edit.py
index b845fad0..0397296e 100644
--- a/gn2/wqflask/edit.py
+++ b/gn2/wqflask/edit.py
@@ -45,17 +45,22 @@ def save_dataset_metadata(
         author: str, content: str, msg: str
 ) -> Either:
     """Save dataset metadata to git"""
-
-    (__run_cmd__(f"git -C {git_dir} reset --hard origin".split(" "))
-     .then(lambda _: __run_cmd__(
-         f"git -C {git_dir} pull".split(" ")))
-     )
-
-    with Path(output).open(mode="w") as _f:
-        _f.write(content)
+    def __write__():
+        try:
+            with Path(output).open(mode="w") as f_:
+                f_.write(content)
+                return Right(0)
+        except Exception as e_:
+            return Left({
+                "command": "Writing to File",
+                "error": str(e_)
+            })
 
     return (
-        __run_cmd__(f"git -C {git_dir} add .".split(" "))
+        __run_cmd__(f"git -C {git_dir} reset --hard origin".split(" "))
+        .then(lambda _: __run_cmd__(f"git -C {git_dir} pull".split(" ")))
+        .then(lambda _: __write__())
+        .then(lambda _: __run_cmd__(f"git -C {git_dir} add .".split(" ")))
         .then(lambda _: __run_cmd__(
             f"git -C {git_dir} commit -m".split(" ") + [
                 f'{msg}', f"--author='{author}'", "--no-gpg-sign"