aboutsummaryrefslogtreecommitdiff
path: root/gn2
diff options
context:
space:
mode:
authorMunyoki Kilyungi2024-03-28 17:52:44 +0300
committerBonfaceKilz2024-04-02 13:55:15 +0300
commitae56e74b3fd759bdb12a368ce34813b1e20f91e3 (patch)
tree7dceb11972276d89e0581281456f53dddb7818a5 /gn2
parentf1f25ae3811e8aad771996de4e48881adf66a2cc (diff)
downloadgenenetwork2-ae56e74b3fd759bdb12a368ce34813b1e20f91e3.tar.gz
Refactor __run_cmd into private function __run_cmd__.
* gn2/wqflask/edit.py: Import Right. Delete curry. (save_dataset_metadata)[__run_cmd]: Move this... (__run_cmd__): ... here. Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn2')
-rw-r--r--gn2/wqflask/edit.py54
1 files changed, 32 insertions, 22 deletions
diff --git a/gn2/wqflask/edit.py b/gn2/wqflask/edit.py
index 500d1dae..b845fad0 100644
--- a/gn2/wqflask/edit.py
+++ b/gn2/wqflask/edit.py
@@ -5,8 +5,7 @@ from urllib.parse import urljoin
from pathlib import Path
from gn2.wqflask.oauth2.session import session_info
-from pymonad.tools import curry
-from pymonad.either import Either, Left
+from pymonad.either import Either, Left, Right
from flask import (Blueprint,
flash,
@@ -21,36 +20,47 @@ from gn2.wqflask.oauth2.checks import require_oauth2_edit_resource_access
metadata = Blueprint("metadata", __name__)
+def __run_cmd__(cmd) -> Either:
+ """Run a given command and return it's results as an Either monad"""
+ _result = ""
+ try:
+ _result = subprocess.run(
+ cmd, capture_output=True
+ )
+ except Exception as e_:
+ return Left({
+ "command": cmd,
+ "error": str(e_),
+ })
+ if _result.stderr:
+ return Left({
+ "command": cmd,
+ "error": _result.stderr.decode()
+ })
+ return Right(_result.stdout)
+
+
def save_dataset_metadata(
git_dir: str, output: str,
author: str, content: str, msg: str
) -> Either:
"""Save dataset metadata to git"""
- @curry(2)
- def __run_cmd(cmd, status_code):
- __result = subprocess.run(
- cmd, capture_output=True
- )
- if __result.stderr or status_code != 0:
- return Left({
- "command": cmd,
- "error": __result.stderr.decode()
- })
- return 0
- (Either.insert(0)
- .then(__run_cmd(f"git -C {git_dir} reset --hard origin".split(" ")))
- .then(__run_cmd(f"git -C {git_dir} pull".split(" "))))
+ (__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)
+
return (
- Either.insert(0)
- .then(__run_cmd(f"git -C {git_dir} add .".split(" ")))
- .then(__run_cmd(f"git -C {git_dir} commit -m".split(" ") + [
- f'{msg}', f"--author='{author}'", "--no-gpg-sign"
- ]))
- .then(__run_cmd(f"git -C {git_dir} \
+ __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"
+ ]))
+ .then(lambda _: __run_cmd__(f"git -C {git_dir} \
push origin master --dry-run".split(" ")))
)