tryorchard-cli 0.0.3__tar.gz → 0.0.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/PKG-INFO +1 -1
  2. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/client.py +40 -7
  3. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/cmd_debugger.py +18 -18
  4. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/cmd_exec.py +32 -24
  5. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/cmd_frida.py +18 -18
  6. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/cmd_input.py +17 -17
  7. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/cmd_kernel.py +8 -5
  8. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/cmd_lifecycle.py +21 -22
  9. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/cmd_net.py +61 -29
  10. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/cmd_record.py +21 -19
  11. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/cmd_remote.py +5 -4
  12. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/cmd_sandbox.py +14 -14
  13. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/cmd_telephony.py +7 -7
  14. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/output.py +20 -0
  15. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/pyproject.toml +1 -1
  16. tryorchard_cli-0.0.5/tests/test_progress.py +42 -0
  17. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/tests/test_remote.py +3 -1
  18. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/tryorchard_cli.egg-info/PKG-INFO +1 -1
  19. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/tryorchard_cli.egg-info/SOURCES.txt +1 -0
  20. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/README.md +0 -0
  21. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/__init__.py +0 -0
  22. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/cli.py +0 -0
  23. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/cmd_access.py +0 -0
  24. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/cmd_relay.py +0 -0
  25. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/config.py +0 -0
  26. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/context.py +0 -0
  27. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/ptyshell.py +0 -0
  28. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/selector.py +0 -0
  29. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/viewers.py +0 -0
  30. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/orchard/wsbridge.py +0 -0
  31. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/setup.cfg +0 -0
  32. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/tests/test_client.py +0 -0
  33. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/tests/test_config.py +0 -0
  34. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/tests/test_debugger.py +0 -0
  35. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/tests/test_frida.py +0 -0
  36. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/tests/test_input.py +0 -0
  37. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/tests/test_net.py +0 -0
  38. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/tests/test_selector.py +0 -0
  39. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/tests/test_viewers.py +0 -0
  40. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/tests/test_wsbridge.py +0 -0
  41. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/tryorchard_cli.egg-info/dependency_links.txt +0 -0
  42. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/tryorchard_cli.egg-info/entry_points.txt +0 -0
  43. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/tryorchard_cli.egg-info/requires.txt +0 -0
  44. {tryorchard_cli-0.0.3 → tryorchard_cli-0.0.5}/tryorchard_cli.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tryorchard-cli
3
- Version: 0.0.3
3
+ Version: 0.0.5
4
4
  Summary: Orchard CLI — drive sandboxes (sandbox/snapshot/template/team/key management and live adb/scrcpy/vnc/shell/logs/files) from the terminal.
5
5
  License: MIT
6
6
  Requires-Python: >=3.10
@@ -2,12 +2,35 @@
2
2
  how a server error turns into a message a human can act on."""
3
3
  from __future__ import annotations
4
4
 
5
+ from collections.abc import Callable
5
6
  from pathlib import Path
6
7
 
7
8
  import httpx
8
9
 
9
10
  from .config import Config
10
11
 
12
+ # A progress sink: called with the number of bytes transferred since the last call.
13
+ Progress = Callable[[int], None]
14
+
15
+
16
+ class _CountingReader:
17
+ """Wraps a binary file object so every `.read()` reports the bytes consumed to a
18
+ progress callback. Everything else (seek/tell/close/fileno) delegates, so httpx
19
+ can still size a multipart part and stream it from disk without buffering it."""
20
+
21
+ def __init__(self, fh, progress: "Progress | None"):
22
+ self._fh = fh
23
+ self._progress = progress
24
+
25
+ def read(self, size: int = -1) -> bytes:
26
+ data = self._fh.read(size)
27
+ if data and self._progress:
28
+ self._progress(len(data))
29
+ return data
30
+
31
+ def __getattr__(self, name):
32
+ return getattr(self._fh, name)
33
+
11
34
 
12
35
  class ApiError(Exception):
13
36
  """A non-2xx REST response, with a message mapped for the terminal."""
@@ -87,10 +110,11 @@ class Client:
87
110
  return self._request("DELETE", path, **kw)
88
111
 
89
112
  def post_files(self, path: str, files: list[tuple[str, Path]], data: dict | None = None,
90
- timeout: float | None = None):
113
+ timeout: float | None = None, progress: "Progress | None" = None):
91
114
  """multipart POST (APK install, file upload). `files` is [(field, path)].
92
- `timeout` overrides the default for large uploads (an AVD profile is GBs)."""
93
- handles = [(field, (p.name, p.open("rb"))) for field, p in files]
115
+ `timeout` overrides the default for large uploads (an AVD profile is GBs).
116
+ `progress` is called with bytes read as the files stream out."""
117
+ handles = [(field, (p.name, _CountingReader(p.open("rb"), progress))) for field, p in files]
94
118
  kw = {"files": handles, "data": data or {}}
95
119
  if timeout is not None:
96
120
  kw["timeout"] = timeout
@@ -101,7 +125,7 @@ class Client:
101
125
  fh.close()
102
126
 
103
127
  def post_stream(self, path: str, source: Path, params: dict | None = None,
104
- timeout: float = 7200.0):
128
+ timeout: float = 7200.0, progress: "Progress | None" = None):
105
129
  """POST a file as a raw streaming body (no multipart) — for a multi-GB upload
106
130
  that must not be buffered. Reads the file in chunks via a generator so neither
107
131
  the client nor the server ever holds the whole file. Metadata rides the query."""
@@ -110,6 +134,8 @@ class Client:
110
134
  def chunks():
111
135
  with source.open("rb") as fh:
112
136
  while data := fh.read(1 << 20):
137
+ if progress:
138
+ progress(len(data))
113
139
  yield data
114
140
 
115
141
  return self._request("POST", path, params=params or {}, content=chunks(),
@@ -118,7 +144,7 @@ class Client:
118
144
  timeout=timeout)
119
145
 
120
146
  def stream_file_to(self, base_url: str, path: str, token: str, source: Path,
121
- timeout: float = 7200.0):
147
+ timeout: float = 7200.0, progress: "Progress | None" = None):
122
148
  """Stream a file as a raw body straight to a node agent (not the control plane),
123
149
  chunked so nothing is buffered. Used for direct multi-GB AVD uploads."""
124
150
  size = source.stat().st_size
@@ -126,6 +152,8 @@ class Client:
126
152
  def chunks():
127
153
  with source.open("rb") as fh:
128
154
  while data := fh.read(1 << 20):
155
+ if progress:
156
+ progress(len(data))
129
157
  yield data
130
158
 
131
159
  with httpx.Client(timeout=httpx.Timeout(timeout, connect=10)) as c:
@@ -137,7 +165,8 @@ class Client:
137
165
  raise ApiError(r.status_code, _detail(r))
138
166
  return r.json()
139
167
 
140
- def stream_to_file(self, path: str, dest: Path, timeout: float = 3600.0) -> int:
168
+ def stream_to_file(self, path: str, dest: Path, timeout: float = 3600.0,
169
+ progress: "Progress | None" = None) -> int:
141
170
  """Stream an authed endpoint (relative path) to a file — for large downloads
142
171
  like an AVD profile. Carries the normal Authorization header."""
143
172
  total = 0
@@ -149,9 +178,11 @@ class Client:
149
178
  for chunk in r.iter_bytes(1 << 20):
150
179
  fh.write(chunk)
151
180
  total += len(chunk)
181
+ if progress:
182
+ progress(len(chunk))
152
183
  return total
153
184
 
154
- def download(self, absolute_url: str, dest: Path) -> int:
185
+ def download(self, absolute_url: str, dest: Path, progress: "Progress | None" = None) -> int:
155
186
  """Stream a signed-grant URL (full URL incl. ?token=) to a file. The
156
187
  grant is the credential, so this call carries no Authorization header."""
157
188
  total = 0
@@ -163,4 +194,6 @@ class Client:
163
194
  for chunk in r.iter_bytes(65536):
164
195
  fh.write(chunk)
165
196
  total += len(chunk)
197
+ if progress:
198
+ progress(len(chunk))
166
199
  return total
@@ -1,6 +1,6 @@
1
1
  """`orchard debugger …` — the on-device lldb (lldb-server + attach).
2
2
 
3
- Every verb takes a sandbox selector (uuid / prefix / name / tag). `status` is a
3
+ Every verb takes a sandbox device (uuid / prefix / name / tag). `status` is a
4
4
  GET; `install` and `start` POST the `/sandboxes/<uuid>/debugger` endpoint with
5
5
  an `action`. `console` opens the interactive lldb stream. Needs a rootable image
6
6
  for ptrace, so on Cuttlefish use a debug sandbox (the cuttlefish-debug image).
@@ -19,11 +19,11 @@ app = typer.Typer(no_args_is_help=True,
19
19
  help="On-device lldb debugger (lldb-server + attach).")
20
20
 
21
21
 
22
- def _debugger(ctx: typer.Context, selector: str, *, get: bool = False, **body: object):
23
- """Resolve the selector, then GET or POST the /debugger endpoint."""
22
+ def _debugger(ctx: typer.Context, device: str, *, get: bool = False, **body: object):
23
+ """Resolve the device, then GET or POST the /debugger endpoint."""
24
24
  with client(ctx) as c:
25
25
  try:
26
- inst = resolve(c, selector)
26
+ inst = resolve(c, device)
27
27
  except SelectorError as e:
28
28
  raise fail(str(e))
29
29
  path = f"/sandboxes/{inst['uuid']}/debugger"
@@ -32,9 +32,9 @@ def _debugger(ctx: typer.Context, selector: str, *, get: bool = False, **body: o
32
32
 
33
33
 
34
34
  @app.command()
35
- def status(ctx: typer.Context, selector: str) -> None:
35
+ def status(ctx: typer.Context, device: str) -> None:
36
36
  """Report lldb-server state on the device."""
37
- _, res = _debugger(ctx, selector, get=True)
37
+ _, res = _debugger(ctx, device, get=True)
38
38
  if cfg(ctx).json:
39
39
  return emit(cfg(ctx), res)
40
40
  table("debugger", ["field", "value"],
@@ -42,51 +42,51 @@ def status(ctx: typer.Context, selector: str) -> None:
42
42
 
43
43
 
44
44
  @app.command()
45
- def install(ctx: typer.Context, selector: str) -> None:
45
+ def install(ctx: typer.Context, device: str) -> None:
46
46
  """Push lldb-server to the device (needs root) and start it."""
47
- inst, res = _debugger(ctx, selector, action="install")
47
+ inst, res = _debugger(ctx, device, action="install")
48
48
  emit(cfg(ctx), res) if cfg(ctx).json else ok(f"lldb-server install → {inst.get('name')}")
49
49
 
50
50
 
51
51
  @app.command()
52
- def start(ctx: typer.Context, selector: str,
52
+ def start(ctx: typer.Context, device: str,
53
53
  process: str = typer.Option(None, "--process", "-p",
54
54
  help="Process to attach to on start.")) -> None:
55
55
  """Start lldb-server, optionally attached to a process."""
56
- inst, res = _debugger(ctx, selector, action="start", process=process)
56
+ inst, res = _debugger(ctx, device, action="start", process=process)
57
57
  emit(cfg(ctx), res) if cfg(ctx).json else ok(f"lldb-server start → {inst.get('name')}")
58
58
 
59
59
 
60
60
  @app.command()
61
- def gdb(ctx: typer.Context, selector: str,
61
+ def gdb(ctx: typer.Context, device: str,
62
62
  process: str = typer.Option(..., "--process", "-p",
63
63
  help="Running app process (package) to attach gdb to.")) -> None:
64
64
  """Attach a gdbserver to an app for gdb/pwndbg (needs a rooted device + the app
65
- running). Then open the tunnel with `orchard gdb <selector>` and `target remote` it."""
66
- inst, res = _debugger(ctx, selector, action="gdb", process=process)
65
+ running). Then open the tunnel with `orchard gdb <device>` and `target remote` it."""
66
+ inst, res = _debugger(ctx, device, action="gdb", process=process)
67
67
  if cfg(ctx).json:
68
68
  emit(cfg(ctx), res)
69
69
  else:
70
70
  ok(f"gdbserver attached to {process} (pid {res.get('pid')}) on {inst.get('name')}")
71
- print(f" tunnel it: orchard gdb {selector}")
71
+ print(f" tunnel it: orchard gdb {device}")
72
72
  print(f" then: {res.get('connect', 'gdb-multiarch -ex \"target remote …\"')}")
73
73
 
74
74
 
75
75
  @app.command("gdb-stop")
76
- def gdb_stop(ctx: typer.Context, selector: str) -> None:
76
+ def gdb_stop(ctx: typer.Context, device: str) -> None:
77
77
  """Detach gdb — stop the on-device gdbserver (the app resumes)."""
78
- inst, res = _debugger(ctx, selector, action="gdb-detach")
78
+ inst, res = _debugger(ctx, device, action="gdb-detach")
79
79
  emit(cfg(ctx), res) if cfg(ctx).json else ok(f"gdb detached → {inst.get('name')}")
80
80
 
81
81
 
82
82
  @app.command()
83
- def console(ctx: typer.Context, selector: str,
83
+ def console(ctx: typer.Context, device: str,
84
84
  process: str = typer.Option(None, "--process", "-p",
85
85
  help="Process to attach the console to.")) -> None:
86
86
  """Open an interactive lldb console attached to the device (Ctrl-D to exit)."""
87
87
  with client(ctx) as c:
88
88
  try:
89
- inst = resolve(c, selector)
89
+ inst = resolve(c, device)
90
90
  except SelectorError as e:
91
91
  raise fail(str(e))
92
92
  ptyshell.interactive_console(cfg(ctx), inst["uuid"], process)
@@ -10,7 +10,7 @@ import typer
10
10
 
11
11
  from . import ptyshell, wsbridge
12
12
  from .context import cfg, client
13
- from .output import console, emit, fail, ok, table
13
+ from .output import console, emit, fail, ok, table, transfer_progress
14
14
  from .selector import SelectorError, resolve
15
15
 
16
16
  app_app = typer.Typer(no_args_is_help=True, help="Apps on the device (install/list/uninstall).")
@@ -22,27 +22,30 @@ def register(app: typer.Typer) -> None:
22
22
  app.command("logs", help="Stream a sandbox's logs.")(logs)
23
23
  app.add_typer(app_app, name="app")
24
24
  app.add_typer(file_app, name="file")
25
+ # Top-level shortcuts for the two most common transfers (same as `file push/pull`).
26
+ app.command("push", help="Upload a local file to a device (shortcut for `file push`).")(file_push)
27
+ app.command("pull", help="Download a file from a device (shortcut for `file pull`).")(file_pull)
25
28
 
26
29
 
27
- def _resolve(ctx: typer.Context, selector: str) -> dict:
30
+ def _resolve(ctx: typer.Context, device: str) -> dict:
28
31
  with client(ctx) as c:
29
32
  try:
30
- return resolve(c, selector)
33
+ return resolve(c, device)
31
34
  except SelectorError as e:
32
35
  raise fail(str(e))
33
36
 
34
37
 
35
38
  # -- shell ----------------------------------------------------------------
36
- def shell(ctx: typer.Context, selector: str):
37
- inst = _resolve(ctx, selector)
39
+ def shell(ctx: typer.Context, device: str):
40
+ inst = _resolve(ctx, device)
38
41
  ptyshell.interactive_shell(cfg(ctx), inst["uuid"])
39
42
 
40
43
 
41
44
  # -- logs -----------------------------------------------------------------
42
- def logs(ctx: typer.Context, selector: str,
45
+ def logs(ctx: typer.Context, device: str,
43
46
  follow: bool = typer.Option(True, "--follow/--no-follow", "-f",
44
47
  help="Keep streaming (Ctrl-C to stop).")):
45
- inst = _resolve(ctx, selector)
48
+ inst = _resolve(ctx, device)
46
49
  c = cfg(ctx)
47
50
 
48
51
  async def stream() -> None:
@@ -64,10 +67,10 @@ def logs(ctx: typer.Context, selector: str,
64
67
 
65
68
  # -- apps -----------------------------------------------------------------
66
69
  @app_app.command("list")
67
- def app_list(ctx: typer.Context, selector: str,
70
+ def app_list(ctx: typer.Context, device: str,
68
71
  user_only: bool = typer.Option(False, "--user", help="Only third-party apps.")):
69
72
  with client(ctx) as c:
70
- inst = _resolve(ctx, selector)
73
+ inst = _resolve(ctx, device)
71
74
  res = c.get(f"/sandboxes/{inst['uuid']}/apps") or {}
72
75
  apps = res.get("apps", res if isinstance(res, list) else [])
73
76
  if user_only:
@@ -79,34 +82,37 @@ def app_list(ctx: typer.Context, selector: str,
79
82
 
80
83
 
81
84
  @app_app.command("install")
82
- def app_install(ctx: typer.Context, selector: str,
85
+ def app_install(ctx: typer.Context, device: str,
83
86
  apk: list[Path] = typer.Argument(..., help="One .apk, or several split APKs.")):
84
87
  for p in apk:
85
88
  if not p.exists():
86
89
  raise fail(f"no such file: {p}")
90
+ total = sum(p.stat().st_size for p in apk)
91
+ label = apk[0].name if len(apk) == 1 else f"{len(apk)} APKs"
87
92
  with client(ctx) as c:
88
- inst = _resolve(ctx, selector)
89
- res = c.post_files(f"/sandboxes/{inst['uuid']}/apps/install",
90
- files=[("file", p) for p in apk])
93
+ inst = _resolve(ctx, device)
94
+ with transfer_progress(f"installing {label}", total) as adv:
95
+ res = c.post_files(f"/sandboxes/{inst['uuid']}/apps/install",
96
+ files=[("file", p) for p in apk], progress=adv)
91
97
  if cfg(ctx).json:
92
98
  return emit(cfg(ctx), res)
93
99
  ok(f"installed {', '.join(p.name for p in apk)}")
94
100
 
95
101
 
96
102
  @app_app.command("uninstall")
97
- def app_uninstall(ctx: typer.Context, selector: str, package: str):
103
+ def app_uninstall(ctx: typer.Context, device: str, package: str):
98
104
  with client(ctx) as c:
99
- inst = _resolve(ctx, selector)
105
+ inst = _resolve(ctx, device)
100
106
  c.post(f"/sandboxes/{inst['uuid']}/apps/uninstall", json={"package": package})
101
107
  ok(f"uninstalled {package}")
102
108
 
103
109
 
104
110
  # -- files ----------------------------------------------------------------
105
111
  @file_app.command("ls")
106
- def file_ls(ctx: typer.Context, selector: str,
112
+ def file_ls(ctx: typer.Context, device: str,
107
113
  path: str = typer.Argument("/sdcard", help="Directory on the device.")):
108
114
  with client(ctx) as c:
109
- inst = _resolve(ctx, selector)
115
+ inst = _resolve(ctx, device)
110
116
  res = c.get(f"/sandboxes/{inst['uuid']}/files", params={"path": path}) or {}
111
117
  entries = res.get("entries", [])
112
118
  if cfg(ctx).json:
@@ -117,27 +123,29 @@ def file_ls(ctx: typer.Context, selector: str,
117
123
 
118
124
 
119
125
  @file_app.command("push")
120
- def file_push(ctx: typer.Context, selector: str, local: Path,
126
+ def file_push(ctx: typer.Context, device: str, local: Path,
121
127
  dest: str = typer.Argument(..., help="Destination directory on the device.")):
122
128
  """Upload a local file into a device directory."""
123
129
  if not local.exists():
124
130
  raise fail(f"no such file: {local}")
125
131
  with client(ctx) as c:
126
- inst = _resolve(ctx, selector)
127
- res = c.post_files(f"/sandboxes/{inst['uuid']}/files/upload",
128
- files=[("file", local)], data={"path": dest})
132
+ inst = _resolve(ctx, device)
133
+ with transfer_progress(f"pushing {local.name}", local.stat().st_size) as adv:
134
+ res = c.post_files(f"/sandboxes/{inst['uuid']}/files/upload",
135
+ files=[("file", local)], data={"path": dest}, progress=adv)
129
136
  if cfg(ctx).json:
130
137
  return emit(cfg(ctx), res)
131
138
  ok(f"pushed {local.name} → {dest}")
132
139
 
133
140
 
134
141
  @file_app.command("pull")
135
- def file_pull(ctx: typer.Context, selector: str, remote: str,
142
+ def file_pull(ctx: typer.Context, device: str, remote: str,
136
143
  out: Path = typer.Option(None, "--out", "-o", help="Local destination.")):
137
144
  """Download a device file (via a short-lived signed grant)."""
138
145
  with client(ctx) as c:
139
- inst = _resolve(ctx, selector)
146
+ inst = _resolve(ctx, device)
140
147
  grant = c.post(f"/sandboxes/{inst['uuid']}/files/grant", json={"path": remote})
141
148
  dest = out or Path(grant.get("filename") or remote.rsplit("/", 1)[-1] or "download")
142
- n = c.download(cfg(ctx).url.rstrip("/") + grant["url"], dest)
149
+ with transfer_progress(f"pulling {dest.name}", grant.get("size")) as adv:
150
+ n = c.download(cfg(ctx).url.rstrip("/") + grant["url"], dest, progress=adv)
143
151
  ok(f"pulled {remote} → {dest} ({n} bytes)")
@@ -1,6 +1,6 @@
1
1
  """`orchard frida …` — manage frida-server and run frida scripts on a device.
2
2
 
3
- Every verb takes a sandbox selector (uuid / prefix / name / tag). `status` is a
3
+ Every verb takes a sandbox device (uuid / prefix / name / tag). `status` is a
4
4
  GET; the rest POST the unified `/sandboxes/<uuid>/frida` endpoint with an
5
5
  `action`. `inject` runs a script and prints the `send()`/`console` output it
6
6
  collected.
@@ -25,12 +25,12 @@ app = typer.Typer(no_args_is_help=True,
25
25
  help="Manage frida-server and run frida scripts on a device.")
26
26
 
27
27
 
28
- def _frida(ctx: typer.Context, selector: str, *, get: bool = False, **body: object):
29
- """Resolve the selector, then GET or POST the /frida endpoint. Returns
28
+ def _frida(ctx: typer.Context, device: str, *, get: bool = False, **body: object):
29
+ """Resolve the device, then GET or POST the /frida endpoint. Returns
30
30
  (instance, result)."""
31
31
  with client(ctx) as c:
32
32
  try:
33
- inst = resolve(c, selector)
33
+ inst = resolve(c, device)
34
34
  except SelectorError as e:
35
35
  raise fail(str(e))
36
36
  path = f"/sandboxes/{inst['uuid']}/frida"
@@ -54,44 +54,44 @@ def _print_messages(res: dict) -> None:
54
54
 
55
55
 
56
56
  @app.command()
57
- def status(ctx: typer.Context, selector: str) -> None:
57
+ def status(ctx: typer.Context, device: str) -> None:
58
58
  """Report frida-server state on the device."""
59
- _, res = _frida(ctx, selector, get=True)
59
+ _, res = _frida(ctx, device, get=True)
60
60
  emit(cfg(ctx), res) if cfg(ctx).json else _status_lines(res)
61
61
 
62
62
 
63
63
  @app.command()
64
- def install(ctx: typer.Context, selector: str) -> None:
64
+ def install(ctx: typer.Context, device: str) -> None:
65
65
  """Install frida-server and start it (slow: it pulls packages)."""
66
- inst, res = _frida(ctx, selector, action="install")
66
+ inst, res = _frida(ctx, device, action="install")
67
67
  emit(cfg(ctx), res) if cfg(ctx).json else ok(f"frida install → {inst.get('name')}")
68
68
 
69
69
 
70
70
  @app.command()
71
- def start(ctx: typer.Context, selector: str) -> None:
71
+ def start(ctx: typer.Context, device: str) -> None:
72
72
  """Start frida-server."""
73
- inst, res = _frida(ctx, selector, action="start")
73
+ inst, res = _frida(ctx, device, action="start")
74
74
  emit(cfg(ctx), res) if cfg(ctx).json else ok(f"frida start → {inst.get('name')}")
75
75
 
76
76
 
77
77
  @app.command()
78
- def stop(ctx: typer.Context, selector: str) -> None:
78
+ def stop(ctx: typer.Context, device: str) -> None:
79
79
  """Stop frida-server."""
80
- inst, res = _frida(ctx, selector, action="stop")
80
+ inst, res = _frida(ctx, device, action="stop")
81
81
  emit(cfg(ctx), res) if cfg(ctx).json else ok(f"frida stop → {inst.get('name')}")
82
82
 
83
83
 
84
84
  @app.command()
85
- def verify(ctx: typer.Context, selector: str,
85
+ def verify(ctx: typer.Context, device: str,
86
86
  process: str = typer.Option(None, "--process", "-p",
87
87
  help="Process to attach to (default: a busy one).")) -> None:
88
88
  """Prove frida works by attaching and tracing a process."""
89
- _, res = _frida(ctx, selector, action="verify", process=process)
89
+ _, res = _frida(ctx, device, action="verify", process=process)
90
90
  emit(cfg(ctx), res) if cfg(ctx).json else _print_messages(res)
91
91
 
92
92
 
93
93
  @app.command()
94
- def inject(ctx: typer.Context, selector: str,
94
+ def inject(ctx: typer.Context, device: str,
95
95
  script: str = typer.Argument(..., help="Path to a .js script, or '-' for stdin."),
96
96
  process: str = typer.Option(..., "--process", "-p",
97
97
  help="Target process (an app package or label)."),
@@ -99,7 +99,7 @@ def inject(ctx: typer.Context, selector: str,
99
99
  help="Seconds to run the script (1-30).")) -> None:
100
100
  """Run a frida script against a process, then print its output. Android only."""
101
101
  source = sys.stdin.read() if script == "-" else Path(script).read_text()
102
- _, res = _frida(ctx, selector, action="inject", script=source,
102
+ _, res = _frida(ctx, device, action="inject", script=source,
103
103
  process=process, timeout=timeout)
104
104
  emit(cfg(ctx), res) if cfg(ctx).json else _print_messages(res)
105
105
 
@@ -128,7 +128,7 @@ def _render_frame(frame: object) -> None:
128
128
 
129
129
 
130
130
  @app.command()
131
- def stream(ctx: typer.Context, selector: str,
131
+ def stream(ctx: typer.Context, device: str,
132
132
  script: str = typer.Argument(..., help="Path to a .js script, or '-' for stdin."),
133
133
  process: str = typer.Option(..., "--process", "-p",
134
134
  help="Target process (an app package or label)."),
@@ -138,7 +138,7 @@ def stream(ctx: typer.Context, selector: str,
138
138
  source = sys.stdin.read() if script == "-" else Path(script).read_text()
139
139
  with client(ctx) as c:
140
140
  try:
141
- inst = resolve(c, selector)
141
+ inst = resolve(c, device)
142
142
  except SelectorError as e:
143
143
  raise fail(str(e))
144
144
  conf = cfg(ctx)
@@ -1,6 +1,6 @@
1
1
  """`orchard input …` — programmatic touch/click/swipe/key/text on a device.
2
2
 
3
- Every verb takes a sandbox selector (uuid / prefix / name / tag) and POSTs the
3
+ Every verb takes a sandbox device (uuid / prefix / name / tag) and POSTs the
4
4
  unified control endpoint.
5
5
  """
6
6
  from __future__ import annotations
@@ -14,10 +14,10 @@ from .selector import SelectorError, resolve
14
14
  app = typer.Typer(no_args_is_help=True, help="Touch, swipe, type and press keys on a device.")
15
15
 
16
16
 
17
- def _control(ctx: typer.Context, selector: str, action: str, **params: object) -> None:
17
+ def _control(ctx: typer.Context, device: str, action: str, **params: object) -> None:
18
18
  with client(ctx) as c:
19
19
  try:
20
- inst = resolve(c, selector)
20
+ inst = resolve(c, device)
21
21
  except SelectorError as e:
22
22
  raise fail(str(e))
23
23
  res = c.post(f"/sandboxes/{inst['uuid']}/control", json={"action": action, **params})
@@ -27,44 +27,44 @@ def _control(ctx: typer.Context, selector: str, action: str, **params: object) -
27
27
 
28
28
 
29
29
  @app.command()
30
- def tap(ctx: typer.Context, selector: str, x: int, y: int) -> None:
30
+ def tap(ctx: typer.Context, device: str, x: int, y: int) -> None:
31
31
  """Tap (click) at pixel coordinates X Y."""
32
- _control(ctx, selector, "tap", x=x, y=y)
32
+ _control(ctx, device, "tap", x=x, y=y)
33
33
 
34
34
 
35
35
  @app.command()
36
- def swipe(ctx: typer.Context, selector: str, x1: int, y1: int, x2: int, y2: int,
36
+ def swipe(ctx: typer.Context, device: str, x1: int, y1: int, x2: int, y2: int,
37
37
  ms: int = typer.Option(300, "--ms", help="Duration in milliseconds.")) -> None:
38
38
  """Swipe/drag from X1 Y1 to X2 Y2."""
39
- _control(ctx, selector, "swipe", x1=x1, y1=y1, x2=x2, y2=y2, ms=ms)
39
+ _control(ctx, device, "swipe", x1=x1, y1=y1, x2=x2, y2=y2, ms=ms)
40
40
 
41
41
 
42
42
  @app.command()
43
- def key(ctx: typer.Context, selector: str, name: str) -> None:
43
+ def key(ctx: typer.Context, device: str, name: str) -> None:
44
44
  """Press a key: home, back, recents, power, volup, voldown, enter, …"""
45
- _control(ctx, selector, "key", name=name)
45
+ _control(ctx, device, "key", name=name)
46
46
 
47
47
 
48
48
  @app.command()
49
- def text(ctx: typer.Context, selector: str, text: str) -> None:
49
+ def text(ctx: typer.Context, device: str, text: str) -> None:
50
50
  """Type TEXT into the focused field."""
51
- _control(ctx, selector, "text", text=text)
51
+ _control(ctx, device, "text", text=text)
52
52
 
53
53
 
54
54
  @app.command("tap-text")
55
- def tap_text(ctx: typer.Context, selector: str, text: str) -> None:
55
+ def tap_text(ctx: typer.Context, device: str, text: str) -> None:
56
56
  """Find an on-screen element whose label matches TEXT and tap it."""
57
- _control(ctx, selector, "tap_text", text=text)
57
+ _control(ctx, device, "tap_text", text=text)
58
58
 
59
59
 
60
60
  @app.command()
61
- def launch(ctx: typer.Context, selector: str, package: str) -> None:
61
+ def launch(ctx: typer.Context, device: str, package: str) -> None:
62
62
  """Launch an app by package id (Android) / bundle id (iOS)."""
63
- _control(ctx, selector, "launch", app=package)
63
+ _control(ctx, device, "launch", app=package)
64
64
 
65
65
 
66
66
  @app.command("launch-intent")
67
- def launch_intent(ctx: typer.Context, selector: str, package: str, component: str,
67
+ def launch_intent(ctx: typer.Context, device: str, package: str, component: str,
68
68
  action: str = typer.Option(None, "--action", "-a", help="Intent action."),
69
69
  data: str = typer.Option(None, "--data", "-d", help="Intent data URI."),
70
70
  extra: list[str] = typer.Option(None, "--extra", "-e",
@@ -87,4 +87,4 @@ def launch_intent(ctx: typer.Context, selector: str, package: str, component: st
87
87
  params["data"] = data
88
88
  if extras:
89
89
  params["extras"] = extras
90
- _control(ctx, selector, "launch_intent", **params)
90
+ _control(ctx, device, "launch_intent", **params)
@@ -8,7 +8,7 @@ from pathlib import Path
8
8
  import typer
9
9
 
10
10
  from .context import cfg, client
11
- from .output import emit, fail, ok, table
11
+ from .output import emit, fail, ok, table, transfer_progress
12
12
  from .selector import SelectorError, resolve
13
13
 
14
14
  app = typer.Typer(no_args_is_help=True,
@@ -17,12 +17,12 @@ app = typer.Typer(no_args_is_help=True,
17
17
 
18
18
  @app.command("set-params")
19
19
  def set_params(ctx: typer.Context,
20
- selector: str = typer.Argument(..., help="sandbox uuid / name / tag"),
20
+ device: str = typer.Argument(..., help="sandbox uuid / name / tag"),
21
21
  params: str = typer.Argument(..., help="extra guest-kernel command line (applied on next boot)")):
22
22
  """Set a sandbox's extra guest-kernel command-line params. Reboot to apply."""
23
23
  with client(ctx) as c:
24
24
  try:
25
- inst = resolve(c, selector)
25
+ inst = resolve(c, device)
26
26
  except SelectorError as e:
27
27
  raise fail(str(e))
28
28
  res = c.post(f"/sandboxes/{inst['uuid']}/kernel", json={"params": params})
@@ -52,7 +52,9 @@ def upload(ctx: typer.Context, node: str = typer.Argument(..., help="node name")
52
52
  if not path.exists():
53
53
  raise fail(f"no such file: {path}")
54
54
  with client(ctx) as c:
55
- res = c.post_files(f"/kernels/{node}", files=[("file", path)], timeout=1800.0)
55
+ with transfer_progress(f"uploading {path.name} → {node}", path.stat().st_size) as adv:
56
+ res = c.post_files(f"/kernels/{node}", files=[("file", path)],
57
+ timeout=1800.0, progress=adv)
56
58
  if cfg(ctx).json:
57
59
  return emit(cfg(ctx), res)
58
60
  ok(f"uploaded {res.get('name', path.name)} → {node} ({res.get('size', '?')} bytes)")
@@ -65,7 +67,8 @@ def download(ctx: typer.Context, node: str = typer.Argument(..., help="node name
65
67
  """Download a node kernel / vmlinux file (e.g. for local gdb symbols)."""
66
68
  dest = out or Path(name)
67
69
  with client(ctx) as c:
68
- n = c.stream_to_file(f"/kernels/{node}/{name}", dest)
70
+ with transfer_progress(f"downloading {name}", None) as adv:
71
+ n = c.stream_to_file(f"/kernels/{node}/{name}", dest, progress=adv)
69
72
  ok(f"downloaded {name} → {dest} ({n} bytes)")
70
73
 
71
74