From 0281dd2ccb3fec3718072e4917879d6b53ad24e7 Mon Sep 17 00:00:00 2001 From: Yoshihiro OKUMURA Date: Tue, 9 May 2023 19:45:03 +0900 Subject: [PATCH] update document and remove debug code. --- README.md | 25 +++++++++++-------------- mdrsclient/api/file.py | 15 +++++++-------- mdrsclient/api/folder.py | 15 +++++++-------- mdrsclient/api/laboratory.py | 3 +-- mdrsclient/api/user.py | 5 ++--- mdrsclient/commands/file.py | 13 ++++++++----- 6 files changed, 36 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 8e1d289..3320102 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ $ mdrs config create neurodata https://neurodata.riken.jp/api ``` ### login -login to remote host +Login to remote host ``` $ mdrs login neurodata: Username: (enter your login name) @@ -52,12 +52,6 @@ Create a new folder $ mdrs mkdir neurodata:/NIU/Repository/TEST ``` -### rmdir -Remove a existing folder -``` -$ mdrs rmdir neurodata:/NIU/Repository/TEST -``` - ### metadata Get a folder metadata ``` @@ -65,28 +59,31 @@ $ mdrs metadata neurodata:/NIU/Repository/TEST ``` ### upload -Upload the file or directories +Upload the file or directory ``` $ mdrs upload ./sample.dat neurodata:/NIU/Repository/TEST/ $ mdrs upload -r ./dataset neurodata:/NIU/Repository/TEST/ ``` ### download -Download a file +Download the file or folder ``` $ mdrs download neurodata:/NIU/Repository/TEST/sample.dat ./ +$ mdrs download -r neurodata:/NIU/Repository/TEST/dataset ./ ``` -### move -Move a file +### mv +Move or rename the file or folder ``` $ mdrs move neurodata:/NIU/Repository/TEST/sample.dat neurodata:/NIU/Repository/TEST2/sample2.dat +$ mdrs move neurodata:/NIU/Repository/TEST/dataset neurodata:/NIU/Repository/TEST2/ ``` -### remove -Remove a file +### rm +Remove the file or folder ``` -$ mdrs remove neurodata:/NIU/Repository/TEST2/sample2.dat +$ mdrs rm neurodata:/NIU/Repository/TEST2/sample2.dat +$ mdrs rm -r neurodata:/NIU/Repository/TEST2/dataset ``` ### file-metadata diff --git a/mdrsclient/api/file.py b/mdrsclient/api/file.py index ab9d011..8108912 100644 --- a/mdrsclient/api/file.py +++ b/mdrsclient/api/file.py @@ -1,4 +1,3 @@ -import sys from typing import Final from pydantic import parse_obj_as @@ -19,7 +18,7 @@ class FileApi(BaseApi): ENTRYPOINT: Final[str] = "v2/file/" def retrieve(self, id: str) -> File: - print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) + # print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) url = self.ENTRYPOINT + id + "/" token_check(self.connection) response = self._get(url) @@ -27,7 +26,7 @@ class FileApi(BaseApi): return parse_obj_as(File, response.json()) def create(self, folder_id: str, path: str) -> str: - print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) + # print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) url = self.ENTRYPOINT token_check(self.connection) data = {"folder_id": folder_id} @@ -41,7 +40,7 @@ class FileApi(BaseApi): return ret.id def update(self, file: File, path: str | None) -> bool: - print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) + # print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) url = self.ENTRYPOINT + file.id + "/" token_check(self.connection) if path is not None: @@ -59,7 +58,7 @@ class FileApi(BaseApi): return True def destroy(self, file: File) -> bool: - print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) + # print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) url = self.ENTRYPOINT + file.id + "/" token_check(self.connection) response = self._delete(url) @@ -67,7 +66,7 @@ class FileApi(BaseApi): return True def move(self, file: File, folder_id: str) -> bool: - print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) + # print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) url = self.ENTRYPOINT + file.id + "/move/" data = {"folder": folder_id} token_check(self.connection) @@ -76,7 +75,7 @@ class FileApi(BaseApi): return True def metadata(self, file: File) -> dict: - print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) + # print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) url = self.ENTRYPOINT + file.id + "/metadata/" token_check(self.connection) response = self._get(url) @@ -84,7 +83,7 @@ class FileApi(BaseApi): return response.json() def download(self, file: File, path: str) -> bool: - print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) + # print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) url = "v2/" + file.download_url response = self._get(url, stream=True) self._raise_response_error(response) diff --git a/mdrsclient/api/folder.py b/mdrsclient/api/folder.py index 85043fa..81e50fe 100644 --- a/mdrsclient/api/folder.py +++ b/mdrsclient/api/folder.py @@ -1,4 +1,3 @@ -import sys from typing import Final from pydantic import parse_obj_as @@ -18,7 +17,7 @@ class FolderApi(BaseApi): ENTRYPOINT: Final[str] = "v2/folder/" def list(self, laboratory_id: int, path: str) -> list[FolderSimple]: - print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) + # print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) url = self.ENTRYPOINT params = {"path": path, "laboratory_id": laboratory_id} token_check(self.connection) @@ -30,7 +29,7 @@ class FolderApi(BaseApi): return ret def retrieve(self, id: str) -> Folder: - print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) + # print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) url = self.ENTRYPOINT + id + "/" token_check(self.connection) response = self._get(url) @@ -39,7 +38,7 @@ class FolderApi(BaseApi): return ret def create(self, name: str, parent_id: str) -> str: - print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) + # print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) url = self.ENTRYPOINT data = {"name": name, "parent_id": parent_id, "description": "", "template_id": -1} token_check(self.connection) @@ -49,7 +48,7 @@ class FolderApi(BaseApi): return ret.id def update(self, folder: FolderSimple) -> bool: - print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) + # print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) url = self.ENTRYPOINT + folder.id + "/" data = { "name": folder.name, @@ -61,7 +60,7 @@ class FolderApi(BaseApi): return True def destroy(self, id: str) -> bool: - print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) + # print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) url = self.ENTRYPOINT + id + "/" token_check(self.connection) response = self._delete(url) @@ -69,7 +68,7 @@ class FolderApi(BaseApi): return True def move(self, folder: FolderSimple, folder_id: str) -> bool: - print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) + # print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) url = self.ENTRYPOINT + folder.id + "/move/" data = {"parent": folder_id} token_check(self.connection) @@ -78,7 +77,7 @@ class FolderApi(BaseApi): return True def metadata(self, id: str) -> dict: - print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) + # print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) url = self.ENTRYPOINT + id + "/metadata/" token_check(self.connection) response = self._get(url) diff --git a/mdrsclient/api/laboratory.py b/mdrsclient/api/laboratory.py index 9008ff6..39ccfe6 100644 --- a/mdrsclient/api/laboratory.py +++ b/mdrsclient/api/laboratory.py @@ -1,4 +1,3 @@ -import sys from typing import Final from pydantic import parse_obj_as @@ -12,7 +11,7 @@ class LaboratoryApi(BaseApi): ENTRYPOINT: Final[str] = "v2/laboratory/" def list(self) -> Laboratories: - print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) + # print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) url = self.ENTRYPOINT token_check(self.connection) response = self._get(url) diff --git a/mdrsclient/api/user.py b/mdrsclient/api/user.py index 0ab1eaf..b8a635e 100644 --- a/mdrsclient/api/user.py +++ b/mdrsclient/api/user.py @@ -1,4 +1,3 @@ -import sys from typing import Final import requests @@ -20,7 +19,7 @@ class UserApi(BaseApi): ENTRYPOINT: Final[str] = "v2/" def auth(self, username: str, password: str) -> tuple[User, Token]: - print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) + # print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) url = self.ENTRYPOINT + "auth/" data = {"username": username, "password": password} response = self._post(url, data=data) @@ -33,7 +32,7 @@ class UserApi(BaseApi): return (user, token) def refresh(self, token: Token) -> Token: - print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) + # print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name) url = self.ENTRYPOINT + "refresh/" data = {"refresh": token.refresh} response = self._post(url, data=data) diff --git a/mdrsclient/commands/file.py b/mdrsclient/commands/file.py index b6d2357..ab345b3 100644 --- a/mdrsclient/commands/file.py +++ b/mdrsclient/commands/file.py @@ -40,7 +40,7 @@ class FileCommand(BaseCommand): @staticmethod def register(top_level_subparsers: _SubParsersAction) -> None: # upload - upload_parser = top_level_subparsers.add_parser("upload", help="upload the file or directories") + upload_parser = top_level_subparsers.add_parser("upload", help="upload the file or directory") upload_parser.add_argument( "-r", "--recursive", help="Upload directories and their contents recursive", action="store_true" ) @@ -48,7 +48,7 @@ class FileCommand(BaseCommand): upload_parser.add_argument("remote_path", help="Remote folder path (remote:/lab/path/)") upload_parser.set_defaults(func=FileCommand.upload) # download - download_parser = top_level_subparsers.add_parser("download", help="download the file or folders") + download_parser = top_level_subparsers.add_parser("download", help="download the file or folder") download_parser.add_argument( "-r", "--recursive", help="Download folders and their contents recursive", action="store_true" ) @@ -56,12 +56,12 @@ class FileCommand(BaseCommand): download_parser.add_argument("local_path", help="Local folder path (/foo/bar/)") download_parser.set_defaults(func=FileCommand.download) # mv - move_parser = top_level_subparsers.add_parser("mv", help="move or rename file or folder") + move_parser = top_level_subparsers.add_parser("mv", help="move or rename the file or folder") move_parser.add_argument("src_path", help="Source remote path (remote:/lab/path/src)") move_parser.add_argument("dest_path", help="Destination remote path (remote:/lab/path/dest)") move_parser.set_defaults(func=FileCommand.move) # rm - remove_parser = top_level_subparsers.add_parser("rm", help="remove file or folder") + remove_parser = top_level_subparsers.add_parser("rm", help="remove the file or folder") remove_parser.add_argument( "-r", "--recursive", help="Remove folders and their contents recursive", action="store_true" ) @@ -111,6 +111,7 @@ class FileCommand(BaseCommand): dest_folder_id = folder_api.create(dest_folder_name, folders[dest_parent_folder_path].id) else: dest_folder_id = dest_folder_simple.id + print(dest_folder_path) folders[dest_folder_path] = folder_api.retrieve(dest_folder_id) if dest_folder_simple is None: folders[dest_parent_folder_path].sub_folders.append(folders[dest_folder_path]) @@ -266,7 +267,7 @@ class FileCommand(BaseCommand): file_api.create(upload_file.folder.id, upload_file.path) else: file_api.update(file, upload_file.path) - pass + print(upload_file.path) except MDRSException as e: print(f"API Error: {e}") @@ -278,6 +279,7 @@ class FileCommand(BaseCommand): file_dirname = os.path.join(local_dirname, folder.name) if not os.path.exists(file_dirname): os.makedirs(file_dirname) + print(file_dirname) for file in folder.files: file_path = os.path.join(file_dirname, file.name) download_files.append(DownloadFile(file, file_path)) @@ -296,3 +298,4 @@ class FileCommand(BaseCommand): @staticmethod def _multiple_download_worker(file_api: FileApi, download_file: DownloadFile) -> None: file_api.download(download_file.file, download_file.path) + print(download_file.path)