25 lines
1.1 KiB
Python
25 lines
1.1 KiB
Python
import json
|
|
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")
|
|
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)
|
|
folder_api = FolderApi(connection)
|
|
metadata = folder_api.metadata(folder.id)
|
|
print(json.dumps(metadata))
|