2023-05-18 11:45:18 +09:00
|
|
|
import json
|
2023-05-10 18:17:35 +09:00
|
|
|
from argparse import Namespace, _SubParsersAction
|
|
|
|
|
|
|
|
from mdrsclient.api import FolderApi
|
|
|
|
from mdrsclient.commands.base import BaseCommand
|
|
|
|
|
|
|
|
|
|
|
|
class MetadataCommand(BaseCommand):
|
|
|
|
@classmethod
|
|
|
|
def register(cls, parsers: _SubParsersAction) -> None:
|
|
|
|
command = cls()
|
|
|
|
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/)")
|
|
|
|
metadata_parser.set_defaults(func=command.metadata)
|
|
|
|
|
|
|
|
def metadata(self, args: Namespace) -> None:
|
|
|
|
(remote, laboratory_name, r_path) = self._parse_remote_host_with_path(args.remote_path)
|
|
|
|
connection = self._create_connection(remote)
|
|
|
|
laboratory = self._find_laboratory(connection, laboratory_name)
|
2023-05-10 20:10:43 +09:00
|
|
|
folder = self._find_folder(connection, laboratory, r_path, args.password)
|
2023-05-10 18:17:35 +09:00
|
|
|
folder_api = FolderApi(connection)
|
|
|
|
metadata = folder_api.metadata(folder.id)
|
2023-05-18 11:45:18 +09:00
|
|
|
print(json.dumps(metadata))
|