From 7252ea1ef81530f02af11b3e8fdd333991152815 Mon Sep 17 00:00:00 2001 From: Munyoki Kilyungi Date: Thu, 28 Mar 2024 17:54:06 +0300 Subject: 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 --- gn2/wqflask/edit.py | 23 ++++++++++++++--------- 1 file 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" -- cgit 1.4.1