From a8abd3169aa15e43413afa19d875ef9f04923471 Mon Sep 17 00:00:00 2001 From: Stefan Giroux Date: Fri, 8 Aug 2025 08:59:08 -0500 Subject: [PATCH 1/3] feat: add enum management group --- smpmgr/enumeration_management.py | 63 ++++++++++++++++++++++++++++++++ smpmgr/main.py | 5 ++- 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 smpmgr/enumeration_management.py diff --git a/smpmgr/enumeration_management.py b/smpmgr/enumeration_management.py new file mode 100644 index 0000000..c485df6 --- /dev/null +++ b/smpmgr/enumeration_management.py @@ -0,0 +1,63 @@ +"""The enum subcommand group.""" + +import asyncio +import logging +from typing import List, cast + +import typer +from rich import print +from smpclient.generics import error, success +from smpclient.requests.enumeration_management import GroupDetails, ListSupportedGroups +from typing_extensions import Annotated + +from smpmgr.common import Options, connect_with_spinner, get_smpclient, smp_request + +app = typer.Typer(name="enum", help="The SMP Enumeration Management Group.") +logger = logging.getLogger(__name__) + + +@app.command() +def get_supported_groups(ctx: typer.Context) -> None: + """Request groups supported by the server.""" + + options = cast(Options, ctx.obj) + smpclient = get_smpclient(options) + + async def f() -> None: + await connect_with_spinner(smpclient, options.timeout) + + r = await smp_request(smpclient, options, ListSupportedGroups(), "Waiting for supported groups...") # type: ignore # noqa + + if error(r): + print(r) + elif success(r): + print(r.groups) + else: + raise Exception("Unreachable") + + asyncio.run(f()) + + +@app.command() +def get_group_details( + ctx: typer.Context, + groups: Annotated[List[int], typer.Argument(help="Groups to retrieve details for")], +) -> None: + """Request groups supported by the server.""" + + options = cast(Options, ctx.obj) + smpclient = get_smpclient(options) + + async def f() -> None: + await connect_with_spinner(smpclient, options.timeout) + + r = await smp_request(smpclient, options, GroupDetails(groups=groups), "Waiting for group details...") # type: ignore # noqa + + if error(r): + print(r) + elif success(r): + print(r.groups) + else: + raise Exception("Unreachable") + + asyncio.run(f()) diff --git a/smpmgr/main.py b/smpmgr/main.py index e0721e2..768cb05 100644 --- a/smpmgr/main.py +++ b/smpmgr/main.py @@ -19,6 +19,7 @@ from typing_extensions import Annotated, assert_never from smpmgr import ( + enumeration_management, file_management, image_management, os_management, @@ -68,6 +69,7 @@ app.add_typer(stat_management.app) app.add_typer(image_management.app) app.add_typer(file_management.app) +app.add_typer(enumeration_management.app) app.add_typer(intercreate.app) app.command()(shell_management.shell) app.command()(terminal.terminal) @@ -85,8 +87,7 @@ def options( ), ble: str = typer.Option(None, help="The Bluetooth address to connect to"), timeout: float = typer.Option( - 2.0, - help="Transport timeout in seconds; how long to wait for initial connection and requests.", + 2.0, help="Transport timeout in seconds; how long to wait for requests" ), mtu: int | None = typer.Option( From 5eb9a254beb42e23dcb5320e510ed5bf0346737c Mon Sep 17 00:00:00 2001 From: sgfeniex Date: Tue, 12 Aug 2025 09:17:58 -0500 Subject: [PATCH 2/3] refactor: simplify enum managment commands We don't need to do extra processing on these. --- smpmgr/enumeration_management.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/smpmgr/enumeration_management.py b/smpmgr/enumeration_management.py index c485df6..7171ad2 100644 --- a/smpmgr/enumeration_management.py +++ b/smpmgr/enumeration_management.py @@ -25,15 +25,8 @@ def get_supported_groups(ctx: typer.Context) -> None: async def f() -> None: await connect_with_spinner(smpclient, options.timeout) - r = await smp_request(smpclient, options, ListSupportedGroups(), "Waiting for supported groups...") # type: ignore # noqa - - if error(r): - print(r) - elif success(r): - print(r.groups) - else: - raise Exception("Unreachable") + print(r) asyncio.run(f()) @@ -50,14 +43,7 @@ def get_group_details( async def f() -> None: await connect_with_spinner(smpclient, options.timeout) - r = await smp_request(smpclient, options, GroupDetails(groups=groups), "Waiting for group details...") # type: ignore # noqa - - if error(r): - print(r) - elif success(r): - print(r.groups) - else: - raise Exception("Unreachable") + print(r) asyncio.run(f()) From f1610bfbf697db7e725415b14505f48eac25c772 Mon Sep 17 00:00:00 2001 From: JP Hutchins Date: Sun, 12 Oct 2025 14:24:52 -0700 Subject: [PATCH 3/3] lint: remove unused imports --- smpmgr/enumeration_management.py | 1 - 1 file changed, 1 deletion(-) diff --git a/smpmgr/enumeration_management.py b/smpmgr/enumeration_management.py index 7171ad2..d826225 100644 --- a/smpmgr/enumeration_management.py +++ b/smpmgr/enumeration_management.py @@ -6,7 +6,6 @@ import typer from rich import print -from smpclient.generics import error, success from smpclient.requests.enumeration_management import GroupDetails, ListSupportedGroups from typing_extensions import Annotated