fixed type errors when pylance type checking mode is strict.

This commit is contained in:
2023-07-19 21:47:47 +09:00
parent 23025bd679
commit 08d8a0626a
24 changed files with 387 additions and 236 deletions

View File

@ -1,5 +1,6 @@
import os
from argparse import Namespace, _SubParsersAction
from argparse import Namespace
from typing import Any
from mdrsclient.api import FileApi, FolderApi
from mdrsclient.commands.base import BaseCommand
@ -8,23 +9,29 @@ from mdrsclient.exceptions import IllegalArgumentException
class RmCommand(BaseCommand):
@classmethod
def register(cls, parsers: _SubParsersAction) -> None:
command = cls()
def register(cls, parsers: Any) -> None:
rm_parser = parsers.add_parser("rm", help="remove the file or folder")
rm_parser.add_argument(
"-r", "--recursive", help="remove folders and their contents recursive", action="store_true"
)
rm_parser.add_argument("remote_path", help="remote file path (remote:/lab/path/file)")
rm_parser.set_defaults(func=command.rm)
rm_parser.set_defaults(func=cls.func)
def rm(self, args: Namespace) -> None:
(remote, laboratory_name, r_path) = self._parse_remote_host_with_path(args.remote_path)
@classmethod
def func(cls, args: Namespace) -> None:
remote_path = str(args.remote_path)
is_recursive = bool(args.recursive)
cls.rm(remote_path, is_recursive)
@classmethod
def rm(cls, remote_path: str, is_recursive: bool) -> None:
(remote, laboratory_name, r_path) = cls._parse_remote_host_with_path(remote_path)
r_path = r_path.rstrip("/")
r_dirname = os.path.dirname(r_path)
r_basename = os.path.basename(r_path)
connection = self._create_connection(remote)
laboratory = self._find_laboratory(connection, laboratory_name)
parent_folder = self._find_folder(connection, laboratory, r_dirname)
connection = cls._create_connection(remote)
laboratory = cls._find_laboratory(connection, laboratory_name)
parent_folder = cls._find_folder(connection, laboratory, r_dirname)
file = parent_folder.find_file(r_basename)
if file is not None:
file_api = FileApi(connection)
@ -33,7 +40,7 @@ class RmCommand(BaseCommand):
folder = parent_folder.find_sub_folder(r_basename)
if folder is None:
raise IllegalArgumentException(f"Cannot remove `{r_path}`: No such file or folder.")
if not args.recursive:
if not is_recursive:
raise IllegalArgumentException(f"Cannot remove `{r_path}`: Is a folder.")
folder_api = FolderApi(connection)
folder_api.destroy(folder.id, True)