Skip to content

Commit a6ac795

Browse files
committed
feat: Add 'image erase' command
Signed-off-by: Tormod Volden <[email protected]>
1 parent ef51bba commit a6ac795

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

smpmgr/image_management.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from smpclient import SMPClient
2121
from smpclient.generics import error, success
2222
from smpclient.mcuboot import ImageInfo
23-
from smpclient.requests.image_management import ImageStatesRead, ImageStatesWrite
23+
from smpclient.requests.image_management import ImageErase, ImageStatesRead, ImageStatesWrite
2424
from typing_extensions import Annotated
2525

2626
from smpmgr.common import Options, connect_with_spinner, get_smpclient, smp_request
@@ -88,6 +88,36 @@ async def f() -> None:
8888
asyncio.run(f())
8989

9090

91+
@app.command()
92+
def erase(
93+
ctx: typer.Context,
94+
slot: Annotated[
95+
int,
96+
typer.Option(help="Image slot to erase, as displayed by image state-read (0-indexed)"),
97+
],
98+
) -> None:
99+
"""Request to erase an image slot on the SMP Server."""
100+
101+
options = cast(Options, ctx.obj)
102+
smpclient = get_smpclient(options)
103+
104+
async def f() -> None:
105+
await connect_with_spinner(smpclient, options.timeout)
106+
107+
r = await smp_request(
108+
smpclient, options, ImageErase(slot=slot), "Waiting for image erase..."
109+
)
110+
111+
if error(r):
112+
print(r)
113+
elif success(r):
114+
pass
115+
else:
116+
raise Exception("Unreachable")
117+
118+
asyncio.run(f())
119+
120+
91121
async def upload_with_progress_bar(
92122
smpclient: SMPClient, file: typer.FileBinaryRead | BufferedReader, slot: int = 0
93123
) -> None:

0 commit comments

Comments
 (0)