From 3df502e9a988717bd7a8af88080c9b4b224933fe Mon Sep 17 00:00:00 2001 From: almutlue Date: Fri, 17 Jan 2025 14:45:12 +0100 Subject: [PATCH] feat(storage): add update function --- modos/storage.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modos/storage.py b/modos/storage.py index 157d4b59..7f4ab129 100644 --- a/modos/storage.py +++ b/modos/storage.py @@ -50,6 +50,11 @@ def list(self, target: Optional[Path]) -> Generator[Path, None, None]: def open(self, target: Path) -> io.BufferedReader: ... + @abstractmethod + def update(self, source: Path, target: Path): + """Updates target file based on source file. If source is inside modo it will be deleted afterwards.""" + ... + def empty(self) -> bool: return len(self.zarr.attrs.keys()) == 0 @@ -99,6 +104,10 @@ def remove(self, target: Path): def put(self, source: Path, target: Path): shutil.copy(source, self.path / target) + def update(self, source: Path, target: Path): + self.put(source, target) + self.remove(self.path / target) + @dataclass class S3Path: @@ -216,6 +225,12 @@ def remove(self, target: Path): def put(self, source: Path, target: Path): self.zarr.store.fs.put_file(source, self.path / Path(target)) + def update(self, source: Path, target: Path): + if self.exists(source): + self.zarr.store.fs.mv(source, self.path / Path(target)) + else: + self.put(source, target) + # Initialize object's directory given the metadata graph def init_zarr(zarr_store: zarr.storage.Store) -> zh.Group: