update document and remove debug code.

This commit is contained in:
Yoshihiro OKUMURA 2023-05-09 19:45:03 +09:00
parent 35defa39a6
commit 0281dd2ccb
Signed by: orrisroot
GPG Key ID: 470AA444C92904B2
6 changed files with 36 additions and 40 deletions

View File

@ -15,7 +15,7 @@ $ mdrs config create neurodata https://neurodata.riken.jp/api
``` ```
### login ### login
login to remote host Login to remote host
``` ```
$ mdrs login neurodata: $ mdrs login neurodata:
Username: (enter your login name) Username: (enter your login name)
@ -52,12 +52,6 @@ Create a new folder
$ mdrs mkdir neurodata:/NIU/Repository/TEST $ mdrs mkdir neurodata:/NIU/Repository/TEST
``` ```
### rmdir
Remove a existing folder
```
$ mdrs rmdir neurodata:/NIU/Repository/TEST
```
### metadata ### metadata
Get a folder metadata Get a folder metadata
``` ```
@ -65,28 +59,31 @@ $ mdrs metadata neurodata:/NIU/Repository/TEST
``` ```
### upload ### upload
Upload the file or directories Upload the file or directory
``` ```
$ mdrs upload ./sample.dat neurodata:/NIU/Repository/TEST/ $ mdrs upload ./sample.dat neurodata:/NIU/Repository/TEST/
$ mdrs upload -r ./dataset neurodata:/NIU/Repository/TEST/ $ mdrs upload -r ./dataset neurodata:/NIU/Repository/TEST/
``` ```
### download ### download
Download a file Download the file or folder
``` ```
$ mdrs download neurodata:/NIU/Repository/TEST/sample.dat ./ $ mdrs download neurodata:/NIU/Repository/TEST/sample.dat ./
$ mdrs download -r neurodata:/NIU/Repository/TEST/dataset ./
``` ```
### move ### mv
Move a file 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/sample.dat neurodata:/NIU/Repository/TEST2/sample2.dat
$ mdrs move neurodata:/NIU/Repository/TEST/dataset neurodata:/NIU/Repository/TEST2/
``` ```
### remove ### rm
Remove a file 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 ### file-metadata

View File

@ -1,4 +1,3 @@
import sys
from typing import Final from typing import Final
from pydantic import parse_obj_as from pydantic import parse_obj_as
@ -19,7 +18,7 @@ class FileApi(BaseApi):
ENTRYPOINT: Final[str] = "v2/file/" ENTRYPOINT: Final[str] = "v2/file/"
def retrieve(self, id: str) -> 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 + "/" url = self.ENTRYPOINT + id + "/"
token_check(self.connection) token_check(self.connection)
response = self._get(url) response = self._get(url)
@ -27,7 +26,7 @@ class FileApi(BaseApi):
return parse_obj_as(File, response.json()) return parse_obj_as(File, response.json())
def create(self, folder_id: str, path: str) -> str: 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 url = self.ENTRYPOINT
token_check(self.connection) token_check(self.connection)
data = {"folder_id": folder_id} data = {"folder_id": folder_id}
@ -41,7 +40,7 @@ class FileApi(BaseApi):
return ret.id return ret.id
def update(self, file: File, path: str | None) -> bool: 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 + "/" url = self.ENTRYPOINT + file.id + "/"
token_check(self.connection) token_check(self.connection)
if path is not None: if path is not None:
@ -59,7 +58,7 @@ class FileApi(BaseApi):
return True return True
def destroy(self, file: File) -> bool: 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 + "/" url = self.ENTRYPOINT + file.id + "/"
token_check(self.connection) token_check(self.connection)
response = self._delete(url) response = self._delete(url)
@ -67,7 +66,7 @@ class FileApi(BaseApi):
return True return True
def move(self, file: File, folder_id: str) -> bool: 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/" url = self.ENTRYPOINT + file.id + "/move/"
data = {"folder": folder_id} data = {"folder": folder_id}
token_check(self.connection) token_check(self.connection)
@ -76,7 +75,7 @@ class FileApi(BaseApi):
return True return True
def metadata(self, file: File) -> dict: 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/" url = self.ENTRYPOINT + file.id + "/metadata/"
token_check(self.connection) token_check(self.connection)
response = self._get(url) response = self._get(url)
@ -84,7 +83,7 @@ class FileApi(BaseApi):
return response.json() return response.json()
def download(self, file: File, path: str) -> bool: 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 url = "v2/" + file.download_url
response = self._get(url, stream=True) response = self._get(url, stream=True)
self._raise_response_error(response) self._raise_response_error(response)

View File

@ -1,4 +1,3 @@
import sys
from typing import Final from typing import Final
from pydantic import parse_obj_as from pydantic import parse_obj_as
@ -18,7 +17,7 @@ class FolderApi(BaseApi):
ENTRYPOINT: Final[str] = "v2/folder/" ENTRYPOINT: Final[str] = "v2/folder/"
def list(self, laboratory_id: int, path: str) -> list[FolderSimple]: 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 url = self.ENTRYPOINT
params = {"path": path, "laboratory_id": laboratory_id} params = {"path": path, "laboratory_id": laboratory_id}
token_check(self.connection) token_check(self.connection)
@ -30,7 +29,7 @@ class FolderApi(BaseApi):
return ret return ret
def retrieve(self, id: str) -> Folder: 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 + "/" url = self.ENTRYPOINT + id + "/"
token_check(self.connection) token_check(self.connection)
response = self._get(url) response = self._get(url)
@ -39,7 +38,7 @@ class FolderApi(BaseApi):
return ret return ret
def create(self, name: str, parent_id: str) -> str: 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 url = self.ENTRYPOINT
data = {"name": name, "parent_id": parent_id, "description": "", "template_id": -1} data = {"name": name, "parent_id": parent_id, "description": "", "template_id": -1}
token_check(self.connection) token_check(self.connection)
@ -49,7 +48,7 @@ class FolderApi(BaseApi):
return ret.id return ret.id
def update(self, folder: FolderSimple) -> bool: 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 + "/" url = self.ENTRYPOINT + folder.id + "/"
data = { data = {
"name": folder.name, "name": folder.name,
@ -61,7 +60,7 @@ class FolderApi(BaseApi):
return True return True
def destroy(self, id: str) -> bool: 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 + "/" url = self.ENTRYPOINT + id + "/"
token_check(self.connection) token_check(self.connection)
response = self._delete(url) response = self._delete(url)
@ -69,7 +68,7 @@ class FolderApi(BaseApi):
return True return True
def move(self, folder: FolderSimple, folder_id: str) -> bool: 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/" url = self.ENTRYPOINT + folder.id + "/move/"
data = {"parent": folder_id} data = {"parent": folder_id}
token_check(self.connection) token_check(self.connection)
@ -78,7 +77,7 @@ class FolderApi(BaseApi):
return True return True
def metadata(self, id: str) -> dict: 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/" url = self.ENTRYPOINT + id + "/metadata/"
token_check(self.connection) token_check(self.connection)
response = self._get(url) response = self._get(url)

View File

@ -1,4 +1,3 @@
import sys
from typing import Final from typing import Final
from pydantic import parse_obj_as from pydantic import parse_obj_as
@ -12,7 +11,7 @@ class LaboratoryApi(BaseApi):
ENTRYPOINT: Final[str] = "v2/laboratory/" ENTRYPOINT: Final[str] = "v2/laboratory/"
def list(self) -> Laboratories: 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 url = self.ENTRYPOINT
token_check(self.connection) token_check(self.connection)
response = self._get(url) response = self._get(url)

View File

@ -1,4 +1,3 @@
import sys
from typing import Final from typing import Final
import requests import requests
@ -20,7 +19,7 @@ class UserApi(BaseApi):
ENTRYPOINT: Final[str] = "v2/" ENTRYPOINT: Final[str] = "v2/"
def auth(self, username: str, password: str) -> tuple[User, Token]: 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/" url = self.ENTRYPOINT + "auth/"
data = {"username": username, "password": password} data = {"username": username, "password": password}
response = self._post(url, data=data) response = self._post(url, data=data)
@ -33,7 +32,7 @@ class UserApi(BaseApi):
return (user, token) return (user, token)
def refresh(self, token: Token) -> 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/" url = self.ENTRYPOINT + "refresh/"
data = {"refresh": token.refresh} data = {"refresh": token.refresh}
response = self._post(url, data=data) response = self._post(url, data=data)

View File

@ -40,7 +40,7 @@ class FileCommand(BaseCommand):
@staticmethod @staticmethod
def register(top_level_subparsers: _SubParsersAction) -> None: def register(top_level_subparsers: _SubParsersAction) -> None:
# upload # 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( upload_parser.add_argument(
"-r", "--recursive", help="Upload directories and their contents recursive", action="store_true" "-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.add_argument("remote_path", help="Remote folder path (remote:/lab/path/)")
upload_parser.set_defaults(func=FileCommand.upload) upload_parser.set_defaults(func=FileCommand.upload)
# download # 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( download_parser.add_argument(
"-r", "--recursive", help="Download folders and their contents recursive", action="store_true" "-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.add_argument("local_path", help="Local folder path (/foo/bar/)")
download_parser.set_defaults(func=FileCommand.download) download_parser.set_defaults(func=FileCommand.download)
# mv # 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("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.add_argument("dest_path", help="Destination remote path (remote:/lab/path/dest)")
move_parser.set_defaults(func=FileCommand.move) move_parser.set_defaults(func=FileCommand.move)
# rm # 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( remove_parser.add_argument(
"-r", "--recursive", help="Remove folders and their contents recursive", action="store_true" "-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) dest_folder_id = folder_api.create(dest_folder_name, folders[dest_parent_folder_path].id)
else: else:
dest_folder_id = dest_folder_simple.id dest_folder_id = dest_folder_simple.id
print(dest_folder_path)
folders[dest_folder_path] = folder_api.retrieve(dest_folder_id) folders[dest_folder_path] = folder_api.retrieve(dest_folder_id)
if dest_folder_simple is None: if dest_folder_simple is None:
folders[dest_parent_folder_path].sub_folders.append(folders[dest_folder_path]) 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) file_api.create(upload_file.folder.id, upload_file.path)
else: else:
file_api.update(file, upload_file.path) file_api.update(file, upload_file.path)
pass print(upload_file.path)
except MDRSException as e: except MDRSException as e:
print(f"API Error: {e}") print(f"API Error: {e}")
@ -278,6 +279,7 @@ class FileCommand(BaseCommand):
file_dirname = os.path.join(local_dirname, folder.name) file_dirname = os.path.join(local_dirname, folder.name)
if not os.path.exists(file_dirname): if not os.path.exists(file_dirname):
os.makedirs(file_dirname) os.makedirs(file_dirname)
print(file_dirname)
for file in folder.files: for file in folder.files:
file_path = os.path.join(file_dirname, file.name) file_path = os.path.join(file_dirname, file.name)
download_files.append(DownloadFile(file, file_path)) download_files.append(DownloadFile(file, file_path))
@ -296,3 +298,4 @@ class FileCommand(BaseCommand):
@staticmethod @staticmethod
def _multiple_download_worker(file_api: FileApi, download_file: DownloadFile) -> None: def _multiple_download_worker(file_api: FileApi, download_file: DownloadFile) -> None:
file_api.download(download_file.file, download_file.path) file_api.download(download_file.file, download_file.path)
print(download_file.path)