Skip to content

Commit

Permalink
Merge pull request #223 from kjsanger/feature/json-io
Browse files Browse the repository at this point in the history
Add baton JSON serialization/deserialization for Python applications
  • Loading branch information
kjsanger authored Oct 18, 2024
2 parents 6d9e5eb + 6008d92 commit fe2f16a
Show file tree
Hide file tree
Showing 5 changed files with 595 additions and 192 deletions.
43 changes: 32 additions & 11 deletions src/partisan/icommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import subprocess
from io import StringIO
from pathlib import Path, PurePath
from typing import List, Union

from structlog import get_logger

Expand All @@ -44,6 +43,16 @@ def rmgroup(name: str):
_run(cmd)


def mkuser(name: str):
cmd = ["iadmin", "mkuser", name, "rodsuser"]
_run(cmd)


def rmuser(name: str):
cmd = ["iadmin", "rmuser", name]
_run(cmd)


def group_exists(name: str) -> bool:
info = iuserinfo(name)
for line in info.splitlines():
Expand All @@ -56,6 +65,18 @@ def group_exists(name: str) -> bool:
return False


def user_exists(name: str) -> bool:
info = iuserinfo(name)
for line in info.splitlines():
log.debug("Checking line", line=line)
if re.match(r"type:\s+(rodsuser|groupadmin|rodsadmin)", line):
log.debug("User check", exists=True, name=name)
return True

log.debug("User check", exists=False, name=name)
return False


def iuserinfo(name: str = None) -> str:
cmd = ["iuserinfo"]
if name is not None:
Expand All @@ -69,7 +90,7 @@ def iuserinfo(name: str = None) -> str:
raise RodsError(completed.stderr.decode("utf-8").strip())


def imkdir(remote_path: Union[PurePath, str], make_parents=True):
def imkdir(remote_path: PurePath | str, make_parents=True):
cmd = ["imkdir"]
if make_parents:
cmd.append("-p")
Expand Down Expand Up @@ -122,8 +143,8 @@ def iinit():


def iget(
remote_path: Union[PurePath, str],
local_path: Union[PurePath, str],
remote_path: PurePath | str,
local_path: PurePath | str,
force=False,
verify_checksum=True,
recurse=False,
Expand All @@ -142,8 +163,8 @@ def iget(


def iput(
local_path: Union[PurePath, str],
remote_path: Union[PurePath, str],
local_path: PurePath | str,
remote_path: PurePath | str,
force=False,
verify_checksum=True,
recurse=False,
Expand All @@ -161,7 +182,7 @@ def iput(
_run(cmd)


def irm(remote_path: Union[PurePath, str], force=False, recurse=False):
def irm(remote_path: PurePath | str, force=False, recurse=False):
cmd = ["irm"]
if force:
cmd.append("-f")
Expand All @@ -181,14 +202,14 @@ def irm(remote_path: Union[PurePath, str], force=False, recurse=False):
raise


def itrim(remote_path: Union[PurePath, str], replica_num: int, min_replicas=2):
def itrim(remote_path: PurePath | str, replica_num: int, min_replicas=2):
cmd = ["itrim", "-n", f"{replica_num}", "-N", f"{min_replicas}", remote_path]
_run(cmd)


def icp(
from_path: Union[PurePath, str],
to_path: Union[PurePath, str],
from_path: PurePath | str,
to_path: PurePath | str,
force=False,
verify_checksum=True,
recurse=False,
Expand Down Expand Up @@ -257,7 +278,7 @@ def remove_specific_sql(alias):
_run(cmd)


def _run(cmd: List[str]):
def _run(cmd: list[str]):
log.debug("Running command", cmd=cmd)

completed = subprocess.run(cmd, capture_output=True)
Expand Down
Loading

0 comments on commit fe2f16a

Please sign in to comment.