mdrs-client-python/mdrsclient/commands/metadata.py

25 lines
1.1 KiB
Python
Raw Normal View History

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")
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)
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)
print(json.dumps(metadata))