From f7519a4478a70f786b63d164afc177202d7ff265 Mon Sep 17 00:00:00 2001 From: Ali Date: Fri, 5 Jul 2024 11:52:14 +0200 Subject: [PATCH] added support for glob patterns in --- aiida_firecrest/transport.py | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/aiida_firecrest/transport.py b/aiida_firecrest/transport.py index c3b1237..2963db0 100644 --- a/aiida_firecrest/transport.py +++ b/aiida_firecrest/transport.py @@ -581,6 +581,19 @@ def copy( raise NotImplementedError( "Dereferencing not implemented in FirecREST server" ) + + if self.has_magic(remotesource): # type: ignore + for item in self.iglob(remotesource): # type: ignore + # item is of str type, so we need to split it to get the file name + filename = item.split("/")[-1] if self.isfile(item) else "" + self.copy( + item, + remotedestination + filename, + dereference=dereference, + recursive=recursive, + ) + return + source = self._cwd.joinpath( remotesource ) # .enable_cache() it's removed from from path.py to be investigated @@ -820,6 +833,17 @@ def get( self.gettree(remote, localpath) elif remote.is_file(): self.getfile(remote, localpath) + elif self.has_magic(remotepath): # type: ignore + for item in self.iglob(remotepath): # type: ignore + # item is of str type, so we need to split it to get the file name + filename = item.split("/")[-1] if self.isfile(item) else "" + self.get( + item, + localpath + filename, + dereference=dereference, + ignore_nonexisting=ignore_nonexisting, + ) + return elif not ignore_nonexisting: raise FileNotFoundError(f"Source file does not exist: {remote}") @@ -1021,6 +1045,19 @@ def put( local = Path(localpath) if not local.is_absolute(): raise ValueError("The localpath must be an absolute path") + + if self.has_magic(localpath): # type: ignore + for item in self.iglob(localpath): # type: ignore + # item is of str type, so we need to split it to get the file name + filename = item.split("/")[-1] if self.isfile(item) else "" + self.put( + item, + remotepath + filename, + dereference=dereference, + ignore_nonexisting=ignore_nonexisting, + ) + return + if not Path(local).exists() and not ignore_nonexisting: raise FileNotFoundError(f"Source file does not exist: {localpath}")