Files
orrisroot 4c9954c1fd fix: clear the type checker and linter findings
flake8 reported 49 findings and pyright 10, and two of them were real
bugs rather than matters of style. The rest were unused imports and
four functions over the complexity limit.

- Unlock a DOI folder with the id the DOI response carries, rather
  than an attribute the model does not have, which raised
  `AttributeError` on every locked DOI folder.
- Size the `ls` Size column from the sub-folder on the row rather than
  from its parent, which pushed the later columns out of line.
- Share the path resolution and the destination checks between `cp`
  and `mv`, and split the recursive download and the `ls` row
  printing, bringing all four functions under the complexity limit.
- Accept a client built without a connection, which `config` and
  `version` rely on, and report the reason if one is then asked for.
- Declare the config protocol's constructor for the type checker
  alone, so the protocol keeps its guard against being instantiated.
- Remove 41 unused imports, and let flake8 accept black's spacing.
- Point pyright at the project's own environment, without which it
  resolved no dependency and reported 124 findings that were not real.
- Cover the two fixes and the shared `cp`/`mv` paths with new tests.
2026-09-04 18:23:17 +09:00

46 lines
1.8 KiB
Python

from argparse import Namespace
from typing import Any
from mdrsclient.commands.base import BaseCommand
class LabsCommand(BaseCommand):
@classmethod
def register(cls, parsers: Any) -> None:
labs_parser = parsers.add_parser("labs", help="list all laboratories")
labs_parser.add_argument("remote", help="label of remote host")
labs_parser.set_defaults(func=cls.func)
@classmethod
def func(cls, args: Namespace) -> None:
remote = str(args.remote)
cls.labs(remote)
@classmethod
def labs(cls, remote: str) -> None:
from mdrsclient.client import MdrsClient
remote_host = MdrsClient.parse_remote_host(remote)
client = MdrsClient.from_remote(remote_host)
laboratories = client.get_laboratories()
label = {"id": "ID", "name": "Name", "pi_name": "PI", "full_name": "Laboratory"}
length: dict[str, int] = {}
for key in label.keys():
length[key] = len(label[key])
for laboratory in laboratories:
length["id"] = max(length["id"], len(str(laboratory.id)))
length["name"] = max(length["name"], len(laboratory.name))
length["pi_name"] = max(length["pi_name"], len(laboratory.pi_name))
length["full_name"] = max(length["full_name"], len(laboratory.full_name))
header = (
f"{label['name']:{length['name']}}\t"
f"{label['pi_name']:{length['pi_name']}}\t{label['full_name']:{length['full_name']}}"
)
print(header)
print("-" * len(header.expandtabs()))
for laboratory in laboratories:
print(
f"{laboratory.name:{length['name']}}\t"
f"{laboratory.pi_name:{length['pi_name']}}\t{laboratory.full_name:{length['full_name']}}"
)