2023-05-18 11:45:18 +09:00
|
|
|
import json
|
2023-07-19 21:47:47 +09:00
|
|
|
from argparse import Namespace
|
|
|
|
from typing import Any
|
2023-05-10 18:17:35 +09:00
|
|
|
|
2023-12-12 20:05:46 +09:00
|
|
|
from mdrsclient.api import FoldersApi
|
2023-05-10 18:17:35 +09:00
|
|
|
from mdrsclient.commands.base import BaseCommand
|
|
|
|
|
|
|
|
|
|
|
|
class MetadataCommand(BaseCommand):
|
|
|
|
@classmethod
|
2023-07-19 21:47:47 +09:00
|
|
|
def register(cls, parsers: Any) -> None:
|
2023-05-10 18:17:35 +09:00
|
|
|
metadata_parser = parsers.add_parser("metadata", help="get a folder metadata")
|
2023-05-10 20:10:43 +09:00
|
|
|
metadata_parser.add_argument("-p", "--password", help="password to use when open locked folder")
|
2023-05-10 18:17:35 +09:00
|
|
|
metadata_parser.add_argument("remote_path", help="remote folder path (remote:/lab/path/)")
|
2023-07-19 21:47:47 +09:00
|
|
|
metadata_parser.set_defaults(func=cls.func)
|
2023-05-10 18:17:35 +09:00
|
|
|
|
2023-07-19 21:47:47 +09:00
|
|
|
@classmethod
|
|
|
|
def func(cls, args: Namespace) -> None:
|
|
|
|
remote_path = str(args.remote_path)
|
|
|
|
password = str(args.password) if args.password else None
|
|
|
|
cls.metadata(remote_path, password)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def metadata(cls, remote_path: str, password: str | None) -> None:
|
|
|
|
(remote, laboratory_name, r_path) = cls._parse_remote_host_with_path(remote_path)
|
|
|
|
connection = cls._create_connection(remote)
|
|
|
|
laboratory = cls._find_laboratory(connection, laboratory_name)
|
|
|
|
folder = cls._find_folder(connection, laboratory, r_path, password)
|
2023-12-12 20:05:46 +09:00
|
|
|
folder_api = FoldersApi(connection)
|
2023-05-10 18:17:35 +09:00
|
|
|
metadata = folder_api.metadata(folder.id)
|
2023-06-06 17:04:32 +09:00
|
|
|
print(json.dumps(metadata, ensure_ascii=False))
|