Skip to content

Commit ba69632

Browse files
authored
Add ListApps support to Python client (#163)
* Add ListApps support to Python client - Add list_apps() method to Device class - Add 'list-apps' CLI command to synapsectl - Fix setup.sh to use python3 for proto generation Usage: synapsectl list-apps <device-uri> Programmatic: device = syn.Device("192.168.1.100:647") apps = device.list_apps() * Revert setup.sh back to python Revert the PROTOC command from python3 to python per reviewer feedback.
1 parent 2a02c65 commit ba69632

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

synapse-api

synapse/cli/rpc.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ def add_commands(subparsers):
9797
)
9898
f.set_defaults(func=get_logs)
9999

100+
g = subparsers.add_parser("list-apps", help="List installed applications on the device")
101+
g.set_defaults(func=list_apps)
102+
100103

101104
def info(args):
102105
device = syn.Device(args.uri, args.verbose)
@@ -338,3 +341,23 @@ def parse_datetime(time_str: Optional[str]) -> Optional[datetime]:
338341
finally:
339342
if output_file:
340343
output_file.close()
344+
345+
346+
def list_apps(args):
347+
console = Console()
348+
with console.status("Listing installed applications...", spinner="bouncingBall"):
349+
device = syn.Device(args.uri, args.verbose)
350+
response = device.list_apps()
351+
352+
if not response:
353+
console.print("[bold red]Failed to list applications")
354+
return
355+
356+
if not response.apps:
357+
console.print("[yellow]No applications installed on the device")
358+
return
359+
360+
console.print("[bold]Installed Applications:[/bold]")
361+
for app in response.apps:
362+
version_str = f" (v{app.version})" if app.version else ""
363+
console.print(f" • {app.name}{version_str}")

synapse/client/device.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
UpdateDeviceSettingsRequest,
1919
UpdateDeviceSettingsResponse,
2020
)
21+
from synapse.api.app_pb2 import (
22+
ListAppsRequest,
23+
ListAppsResponse,
24+
)
2125
from synapse.client.config import Config
2226
from synapse.utils.log import log_level_to_pb
2327

@@ -197,6 +201,15 @@ def update_device_settings(
197201
self.logger.error(f"Error during update settings: {str(e)}")
198202
return None
199203

204+
def list_apps(self) -> Optional[ListAppsResponse]:
205+
"""List installed applications on the device."""
206+
try:
207+
response = self.rpc.ListApps(ListAppsRequest())
208+
return response
209+
except grpc.RpcError as e:
210+
self.logger.error("Error listing apps: %s", e.details())
211+
return None
212+
200213
def _handle_status_response(self, status):
201214
if status.code != StatusCode.kOk:
202215
self.logger.error("Error %d: %s", status.code, status.message)

0 commit comments

Comments
 (0)