diff --git a/README.md b/README.md index 6a8ceb3..46ab539 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,14 @@ mdrs file-metadata neurodata:/NIU/Repository/TEST/dataset/sample.dat mdrs file-metadata -p SHARING_PASSWORD neurodata:/NIU/Repository/PW_Open/Readme.txt ``` +### version + +Show the tool name and version number + +```shell +mdrs version +``` + ### help Show the help message and exit diff --git a/mdrsclient/VERSION b/mdrsclient/VERSION deleted file mode 100644 index 7962dcf..0000000 --- a/mdrsclient/VERSION +++ /dev/null @@ -1 +0,0 @@ -1.3.13 diff --git a/mdrsclient/__main__.py b/mdrsclient/__main__.py index ce02dc5..36a7964 100644 --- a/mdrsclient/__main__.py +++ b/mdrsclient/__main__.py @@ -17,6 +17,7 @@ from mdrsclient.commands import ( MvCommand, RmCommand, UploadCommand, + VersionCommand, WhoamiCommand, ) from mdrsclient.exceptions import MDRSException @@ -29,6 +30,7 @@ def main() -> None: parsers = parser.add_subparsers(title="subcommands") ConfigCommand.register(parsers) + VersionCommand.register(parsers) LoginCommand.register(parsers) LogoutCommand.register(parsers) WhoamiCommand.register(parsers) diff --git a/mdrsclient/__version__.py b/mdrsclient/__version__.py index 6036a39..6beae3c 100644 --- a/mdrsclient/__version__.py +++ b/mdrsclient/__version__.py @@ -1,8 +1,5 @@ -import os +from importlib.metadata import version -here = os.path.realpath(os.path.dirname(__file__)) - -with open(os.path.join(here, "VERSION")) as version_file: - __version__ = version_file.read().strip() +__version__ = version("mdrs-client-python") __all__ = ["__version__"] diff --git a/mdrsclient/commands/__init__.py b/mdrsclient/commands/__init__.py index 1af7650..1420d62 100644 --- a/mdrsclient/commands/__init__.py +++ b/mdrsclient/commands/__init__.py @@ -12,6 +12,7 @@ from mdrsclient.commands.mkdir import MkdirCommand from mdrsclient.commands.mv import MvCommand from mdrsclient.commands.rm import RmCommand from mdrsclient.commands.upload import UploadCommand +from mdrsclient.commands.version import VersionCommand from mdrsclient.commands.whoami import WhoamiCommand __all__ = [ @@ -29,5 +30,6 @@ __all__ = [ "MvCommand", "RmCommand", "UploadCommand", + "VersionCommand", "WhoamiCommand", ] diff --git a/mdrsclient/commands/ls.py b/mdrsclient/commands/ls.py index 715a39c..7c1591f 100644 --- a/mdrsclient/commands/ls.py +++ b/mdrsclient/commands/ls.py @@ -23,7 +23,7 @@ class LsCommandContext: laboratory: Laboratory password: str is_json: bool - is_quick: bool + is_quiet: bool is_recursive: bool @@ -35,7 +35,7 @@ class LsCommand(BaseCommand): ls_parser.add_argument("-J", "--json", help="turn on json output", action="store_true") ls_parser.add_argument( "-q", - "--quick", + "--quiet", help="don't output header row. this option is forced if the -r option is specified", action="store_true", ) @@ -49,11 +49,11 @@ class LsCommand(BaseCommand): password = str(args.password) if args.password else None is_json = bool(args.json) is_recursive = bool(args.recursive) - is_quick = bool(args.quick) if not is_recursive else True - cls.ls(remote_path, password, is_json, is_recursive, is_quick) + is_quiet = bool(args.quiet) if not is_recursive else True + cls.ls(remote_path, password, is_json, is_recursive, is_quiet) @classmethod - def ls(cls, remote_path: str, password: str | None, is_json: bool, is_recursive: bool, is_quick: bool) -> None: + def ls(cls, remote_path: str, password: str | None, is_json: bool, is_recursive: bool, is_quiet: bool) -> 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) @@ -63,7 +63,7 @@ class LsCommand(BaseCommand): laboratory, password if password is not None else "", is_json, - is_quick, + is_quiet, is_recursive, ) folder = cls._find_folder(connection, laboratory, r_path, password) @@ -89,7 +89,7 @@ class LsCommand(BaseCommand): } length: dict[str, int] = {} for key in label.keys(): - length[key] = len(label[key]) if not context.is_quick else 0 + length[key] = len(label[key]) if not context.is_quiet else 0 for sub_folder in folder.sub_folders: sub_laboratory = context.connection.laboratories.find_by_id(sub_folder.laboratory_id) sub_laboratory_name = sub_laboratory.name if sub_laboratory is not None else "(invalid)" @@ -114,7 +114,7 @@ class LsCommand(BaseCommand): print(f"{context.prefix}{folder.path}:") print(f"total {sum(f.size for f in files)}") - if not context.is_quick: + if not context.is_quiet: print(header) print("-" * len(header.expandtabs())) diff --git a/mdrsclient/commands/version.py b/mdrsclient/commands/version.py new file mode 100644 index 0000000..7970ff8 --- /dev/null +++ b/mdrsclient/commands/version.py @@ -0,0 +1,20 @@ +from argparse import Namespace +from typing import Any + +from mdrsclient.__version__ import __version__ +from mdrsclient.commands.base import BaseCommand + + +class VersionCommand(BaseCommand): + @classmethod + def register(cls, parsers: Any) -> None: + version_parser = parsers.add_parser("version", help="show the version of this tool") + version_parser.set_defaults(func=cls.func) + + @classmethod + def func(cls, args: Namespace) -> None: + cls.version() + + @classmethod + def version(cls) -> None: + print(f"mdrs {__version__}") diff --git a/pyproject.toml b/pyproject.toml index 91a864b..5f37bad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,12 +1,12 @@ [tool.poetry] name = "mdrs-client-python" -version = "1.3.13" +version = "1.3.14" description = "The mdrs-client-python is python library and a command-line client for up- and downloading files to and from MDRS based repository." authors = ["Yoshihiro OKUMURA "] license = "MIT" readme = "README.md" classifiers=[ - "Development Status :: 3 - Alpha", + "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "Intended Audience :: Science/Research", @@ -14,6 +14,7 @@ classifiers=[ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", "OSI Approved :: MIT License", "Topic :: Utilities", ]