From ce10813d92ec80551af0f30ab67429e7840e0b80 Mon Sep 17 00:00:00 2001 From: Eirini Koutsaniti Date: Mon, 11 Dec 2023 12:18:03 +0100 Subject: [PATCH] Update return value of mkdir, mv, copy and symlink --- firecrest/AsyncClient.py | 16 ++++++++++++---- firecrest/BasicClient.py | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/firecrest/AsyncClient.py b/firecrest/AsyncClient.py index 621e684..ca4b168 100644 --- a/firecrest/AsyncClient.py +++ b/firecrest/AsyncClient.py @@ -593,8 +593,9 @@ async def list_files( async def mkdir( self, machine: str, target_path: str, p: Optional[bool] = None - ) -> None: + ) -> str: """Creates a new directory. + When successful, the method returns a string with the path of the newly created directory. :param machine: the machine name where the filesystem belongs to :param target_path: the absolute target path @@ -611,9 +612,11 @@ async def mkdir( data=data, ) self._json_response([resp], 201) + return target_path - async def mv(self, machine: str, source_path: str, target_path: str) -> None: + async def mv(self, machine: str, source_path: str, target_path: str) -> str: """Rename/move a file, directory, or symlink at the `source_path` to the `target_path` on `machine`'s filesystem. + When successful, the method returns a string with the new path of the file. :param machine: the machine name where the filesystem belongs to :param source_path: the absolute source path @@ -626,6 +629,7 @@ async def mv(self, machine: str, source_path: str, target_path: str) -> None: data={"targetPath": target_path, "sourcePath": source_path}, ) self._json_response([resp], 200) + return target_path async def chmod(self, machine: str, target_path: str, mode: str) -> None: """Changes the file mod bits of a given file according to the specified mode. @@ -675,8 +679,9 @@ async def chown( ) self._json_response([resp], 200) - async def copy(self, machine: str, source_path: str, target_path: str) -> None: + async def copy(self, machine: str, source_path: str, target_path: str) -> str: """Copies file from `source_path` to `target_path`. + When successful, the method returns a string with the path of the newly created file. :param machine: the machine name where the filesystem belongs to :param source_path: the absolute source path @@ -689,6 +694,7 @@ async def copy(self, machine: str, source_path: str, target_path: str) -> None: data={"targetPath": target_path, "sourcePath": source_path}, ) self._json_response([resp], 201) + return target_path async def file_type(self, machine: str, target_path: str) -> str: """Uses the `file` linux application to determine the type of a file. @@ -726,8 +732,9 @@ async def stat( ) return self._json_response([resp], 200)["output"] - async def symlink(self, machine: str, target_path: str, link_path: str) -> None: + async def symlink(self, machine: str, target_path: str, link_path: str) -> str: """Creates a symbolic link. + When successful, the method returns a string with the path of the newly created link. :param machine: the machine name where the filesystem belongs to :param target_path: the absolute path that the symlink will point to @@ -740,6 +747,7 @@ async def symlink(self, machine: str, target_path: str, link_path: str) -> None: data={"targetPath": target_path, "linkPath": link_path}, ) self._json_response([resp], 201) + return target_path async def simple_download( self, machine: str, source_path: str, target_path: str | pathlib.Path | BytesIO diff --git a/firecrest/BasicClient.py b/firecrest/BasicClient.py index d0f1c0b..3a70fa8 100644 --- a/firecrest/BasicClient.py +++ b/firecrest/BasicClient.py @@ -419,8 +419,9 @@ def list_files( ) return self._json_response([resp], 200)["output"] - def mkdir(self, machine: str, target_path: str, p: Optional[bool] = None) -> None: + def mkdir(self, machine: str, target_path: str, p: Optional[bool] = None) -> str: """Creates a new directory. + When successful, the method returns a string with the path of the newly created directory. :param machine: the machine name where the filesystem belongs to :param target_path: the absolute target path @@ -437,9 +438,11 @@ def mkdir(self, machine: str, target_path: str, p: Optional[bool] = None) -> Non data=data, ) self._json_response([resp], 201) + return target_path - def mv(self, machine: str, source_path: str, target_path: str) -> None: + def mv(self, machine: str, source_path: str, target_path: str) -> str: """Rename/move a file, directory, or symlink at the `source_path` to the `target_path` on `machine`'s filesystem. + When successful, the method returns a string with the new path of the file. :param machine: the machine name where the filesystem belongs to :param source_path: the absolute source path @@ -452,6 +455,7 @@ def mv(self, machine: str, source_path: str, target_path: str) -> None: data={"targetPath": target_path, "sourcePath": source_path}, ) self._json_response([resp], 200) + return target_path def chmod(self, machine: str, target_path: str, mode: str) -> None: """Changes the file mod bits of a given file according to the specified mode. @@ -501,8 +505,9 @@ def chown( ) self._json_response([resp], 200) - def copy(self, machine: str, source_path: str, target_path: str) -> None: + def copy(self, machine: str, source_path: str, target_path: str) -> str: """Copies file from `source_path` to `target_path`. + When successful, the method returns a string with the path of the newly created file. :param machine: the machine name where the filesystem belongs to :param source_path: the absolute source path @@ -515,6 +520,7 @@ def copy(self, machine: str, source_path: str, target_path: str) -> None: data={"targetPath": target_path, "sourcePath": source_path}, ) self._json_response([resp], 201) + return target_path def file_type(self, machine: str, target_path: str) -> str: """Uses the `file` linux application to determine the type of a file. @@ -552,8 +558,9 @@ def stat( ) return self._json_response([resp], 200)["output"] - def symlink(self, machine: str, target_path: str, link_path: str) -> None: + def symlink(self, machine: str, target_path: str, link_path: str) -> str: """Creates a symbolic link. + When successful, the method returns a string with the path of the newly created link. :param machine: the machine name where the filesystem belongs to :param target_path: the absolute path that the symlink will point to @@ -566,6 +573,7 @@ def symlink(self, machine: str, target_path: str, link_path: str) -> None: data={"targetPath": target_path, "linkPath": link_path}, ) self._json_response([resp], 201) + return target_path def simple_download( self, machine: str, source_path: str, target_path: str | pathlib.Path | BytesIO