lager-cli 0.64.0__tar.gz → 0.66.0__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 (170) hide show
  1. {lager_cli-0.64.0/lager_cli.egg-info → lager_cli-0.66.0}/PKG-INFO +4 -1
  2. {lager_cli-0.64.0 → lager_cli-0.66.0}/README.md +3 -0
  3. {lager_cli-0.64.0 → lager_cli-0.66.0}/__init__.py +1 -1
  4. {lager_cli-0.64.0 → lager_cli-0.66.0}/box_storage.py +82 -3
  5. lager_cli-0.66.0/commands/box/_macos_target.py +87 -0
  6. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/_ssh.py +7 -0
  7. lager_cli-0.66.0/commands/box/_start_script.py +127 -0
  8. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/boxes.py +51 -14
  9. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/config.py +16 -5
  10. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/diagnose.py +1 -0
  11. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/nets.py +266 -24
  12. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/ssh.py +35 -9
  13. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/communication/__init__.py +3 -0
  14. lager_cli-0.66.0/commands/communication/ble_sniffer.py +423 -0
  15. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/communication/i2c.py +27 -14
  16. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/communication/spi.py +46 -16
  17. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/development/debug/commands.py +6 -3
  18. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/development/debug/service_client.py +8 -1
  19. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/development/devenv.py +4 -1
  20. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/measurement/dac.py +13 -0
  21. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/measurement/gpo.py +13 -3
  22. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/measurement/logic.py +26 -21
  23. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/measurement/scope.py +2 -2
  24. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/measurement/watt.py +13 -6
  25. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/power/battery.py +5 -5
  26. lager_cli-0.66.0/commands/utility/_local_install.py +223 -0
  27. lager_cli-0.66.0/commands/utility/_remote_macos.py +357 -0
  28. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/utility/defaults.py +51 -89
  29. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/utility/install.py +70 -2
  30. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/utility/logs.py +4 -4
  31. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/utility/uninstall.py +62 -4
  32. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/utility/update.py +38 -2
  33. {lager_cli-0.64.0 → lager_cli-0.66.0}/context/session.py +4 -2
  34. {lager_cli-0.64.0 → lager_cli-0.66.0}/core/net_helpers.py +21 -0
  35. lager_cli-0.66.0/deployment/macos_box.py +1353 -0
  36. lager_cli-0.66.0/deployment/macos_remote.py +115 -0
  37. {lager_cli-0.64.0 → lager_cli-0.66.0/lager_cli.egg-info}/PKG-INFO +4 -1
  38. {lager_cli-0.64.0 → lager_cli-0.66.0}/lager_cli.egg-info/SOURCES.txt +14 -0
  39. {lager_cli-0.64.0 → lager_cli-0.66.0}/main.py +4 -3
  40. {lager_cli-0.64.0 → lager_cli-0.66.0}/terminal/ui/display.py +1 -1
  41. {lager_cli-0.64.0 → lager_cli-0.66.0}/LICENSE +0 -0
  42. {lager_cli-0.64.0 → lager_cli-0.66.0}/MANIFEST.in +0 -0
  43. {lager_cli-0.64.0 → lager_cli-0.66.0}/NOTICE +0 -0
  44. {lager_cli-0.64.0 → lager_cli-0.66.0}/__main__.py +0 -0
  45. {lager_cli-0.64.0 → lager_cli-0.66.0}/address_utils.py +0 -0
  46. {lager_cli-0.64.0 → lager_cli-0.66.0}/battery/__init__.py +0 -0
  47. {lager_cli-0.64.0 → lager_cli-0.66.0}/battery/battery_tui.py +0 -0
  48. {lager_cli-0.64.0 → lager_cli-0.66.0}/battery/websocket_client.py +0 -0
  49. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/__init__.py +0 -0
  50. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/__init__.py +0 -0
  51. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/_device_identity.py +0 -0
  52. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/_gateway.py +0 -0
  53. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/_host_ops.py +0 -0
  54. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/_mount_prep.py +0 -0
  55. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/_net_preflight.py +0 -0
  56. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/_pip_validation.py +0 -0
  57. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/_shim_verbs.py +0 -0
  58. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/bench.py +0 -0
  59. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/box_group.py +0 -0
  60. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/drivers.py +0 -0
  61. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/dut.py +0 -0
  62. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/hello.py +0 -0
  63. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/instruments.py +0 -0
  64. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/labjack_pins.py +0 -0
  65. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/lock.py +0 -0
  66. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/net_tui.py +0 -0
  67. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/box/ssh_setup.py +0 -0
  68. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/communication/ble.py +0 -0
  69. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/communication/blufi.py +0 -0
  70. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/communication/router.py +0 -0
  71. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/communication/uart.py +0 -0
  72. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/communication/usb.py +0 -0
  73. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/communication/websocket_client.py +0 -0
  74. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/communication/wifi.py +0 -0
  75. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/custom.py +0 -0
  76. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/development/__init__.py +0 -0
  77. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/development/arm.py +0 -0
  78. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/development/debug/__init__.py +0 -0
  79. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/development/debug/net_cache.py +0 -0
  80. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/development/debug/rtt_websocket_client.py +0 -0
  81. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/development/debug/service_helper.py +0 -0
  82. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/development/debug/tunnel.py +0 -0
  83. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/development/python.py +0 -0
  84. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/measurement/__init__.py +0 -0
  85. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/measurement/adc.py +0 -0
  86. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/measurement/dmm.py +0 -0
  87. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/measurement/energy.py +0 -0
  88. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/measurement/gpi.py +0 -0
  89. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/measurement/thermocouple.py +0 -0
  90. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/power/__init__.py +0 -0
  91. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/power/battery_model_csv.py +0 -0
  92. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/power/eload.py +0 -0
  93. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/power/solar.py +0 -0
  94. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/power/supply.py +0 -0
  95. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/security/__init__.py +0 -0
  96. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/security/hsm.py +0 -0
  97. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/utility/__init__.py +0 -0
  98. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/utility/_host_cli.py +0 -0
  99. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/utility/binaries.py +0 -0
  100. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/utility/exec_.py +0 -0
  101. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/utility/install_wheel.py +0 -0
  102. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/utility/lease.py +0 -0
  103. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/utility/login.py +0 -0
  104. {lager_cli-0.64.0 → lager_cli-0.66.0}/commands/utility/webcam.py +0 -0
  105. {lager_cli-0.64.0 → lager_cli-0.66.0}/config.py +0 -0
  106. {lager_cli-0.64.0 → lager_cli-0.66.0}/context/__init__.py +0 -0
  107. {lager_cli-0.64.0 → lager_cli-0.66.0}/context/ci_detection.py +0 -0
  108. {lager_cli-0.64.0 → lager_cli-0.66.0}/context/constants.py +0 -0
  109. {lager_cli-0.64.0 → lager_cli-0.66.0}/context/core.py +0 -0
  110. {lager_cli-0.64.0 → lager_cli-0.66.0}/context/error_handlers.py +0 -0
  111. {lager_cli-0.64.0 → lager_cli-0.66.0}/core/__init__.py +0 -0
  112. {lager_cli-0.64.0 → lager_cli-0.66.0}/core/custom_drivers.py +0 -0
  113. {lager_cli-0.64.0 → lager_cli-0.66.0}/core/group_usage.py +0 -0
  114. {lager_cli-0.64.0 → lager_cli-0.66.0}/core/matchers.py +0 -0
  115. {lager_cli-0.64.0 → lager_cli-0.66.0}/core/net_group.py +0 -0
  116. {lager_cli-0.64.0 → lager_cli-0.66.0}/core/net_storage.py +0 -0
  117. {lager_cli-0.64.0 → lager_cli-0.66.0}/core/param_types.py +0 -0
  118. {lager_cli-0.64.0 → lager_cli-0.66.0}/core/ssh_utils.py +0 -0
  119. {lager_cli-0.64.0 → lager_cli-0.66.0}/core/tui_keys.py +0 -0
  120. {lager_cli-0.64.0 → lager_cli-0.66.0}/core/tui_ws_bridge.py +0 -0
  121. {lager_cli-0.64.0 → lager_cli-0.66.0}/core/utils.py +0 -0
  122. {lager_cli-0.64.0 → lager_cli-0.66.0}/core/version_skew.py +0 -0
  123. {lager_cli-0.64.0 → lager_cli-0.66.0}/core/ws_diagnose.py +0 -0
  124. {lager_cli-0.64.0 → lager_cli-0.66.0}/deployment/__init__.py +0 -0
  125. {lager_cli-0.64.0 → lager_cli-0.66.0}/deployment/scripts/__init__.py +0 -0
  126. {lager_cli-0.64.0 → lager_cli-0.66.0}/deployment/scripts/configure_docker_dns.py +0 -0
  127. {lager_cli-0.64.0 → lager_cli-0.66.0}/deployment/scripts/configure_docker_dns.sh +0 -0
  128. {lager_cli-0.64.0 → lager_cli-0.66.0}/deployment/scripts/convert_to_sparse_checkout.sh +0 -0
  129. {lager_cli-0.64.0 → lager_cli-0.66.0}/deployment/scripts/setup_and_deploy_box.sh +0 -0
  130. {lager_cli-0.64.0 → lager_cli-0.66.0}/deployment/scripts/setup_ssh_key.sh +0 -0
  131. {lager_cli-0.64.0 → lager_cli-0.66.0}/deployment/security/__init__.py +0 -0
  132. {lager_cli-0.64.0 → lager_cli-0.66.0}/deployment/security/etc_lager_perms.sh +0 -0
  133. {lager_cli-0.64.0 → lager_cli-0.66.0}/deployment/security/secure_box_firewall.sh +0 -0
  134. {lager_cli-0.64.0 → lager_cli-0.66.0}/errors.py +0 -0
  135. {lager_cli-0.64.0 → lager_cli-0.66.0}/exceptions.py +0 -0
  136. {lager_cli-0.64.0 → lager_cli-0.66.0}/gateway_auth.py +0 -0
  137. {lager_cli-0.64.0 → lager_cli-0.66.0}/gateway_tunnel.py +0 -0
  138. {lager_cli-0.64.0 → lager_cli-0.66.0}/impl/__init__.py +0 -0
  139. {lager_cli-0.64.0 → lager_cli-0.66.0}/impl/box_config.py +0 -0
  140. {lager_cli-0.64.0 → lager_cli-0.66.0}/impl/measurement/__init__.py +0 -0
  141. {lager_cli-0.64.0 → lager_cli-0.66.0}/impl/measurement/scope.py +0 -0
  142. {lager_cli-0.64.0 → lager_cli-0.66.0}/impl/measurement/scope_stream.py +0 -0
  143. {lager_cli-0.64.0 → lager_cli-0.66.0}/impl/power/__init__.py +0 -0
  144. {lager_cli-0.64.0 → lager_cli-0.66.0}/impl/power/enable_disable.py +0 -0
  145. {lager_cli-0.64.0 → lager_cli-0.66.0}/lager_cli.egg-info/dependency_links.txt +0 -0
  146. {lager_cli-0.64.0 → lager_cli-0.66.0}/lager_cli.egg-info/entry_points.txt +0 -0
  147. {lager_cli-0.64.0 → lager_cli-0.66.0}/lager_cli.egg-info/requires.txt +0 -0
  148. {lager_cli-0.64.0 → lager_cli-0.66.0}/lager_cli.egg-info/top_level.txt +0 -0
  149. {lager_cli-0.64.0 → lager_cli-0.66.0}/lease_client.py +0 -0
  150. {lager_cli-0.64.0 → lager_cli-0.66.0}/pyproject.toml +0 -0
  151. {lager_cli-0.64.0 → lager_cli-0.66.0}/run_record.py +0 -0
  152. {lager_cli-0.64.0 → lager_cli-0.66.0}/safe_unpickle.py +0 -0
  153. {lager_cli-0.64.0 → lager_cli-0.66.0}/setup.cfg +0 -0
  154. {lager_cli-0.64.0 → lager_cli-0.66.0}/setup.py +0 -0
  155. {lager_cli-0.64.0 → lager_cli-0.66.0}/simple_hdlc.py +0 -0
  156. {lager_cli-0.64.0 → lager_cli-0.66.0}/sort_utils.py +0 -0
  157. {lager_cli-0.64.0 → lager_cli-0.66.0}/status.py +0 -0
  158. {lager_cli-0.64.0 → lager_cli-0.66.0}/supply/__init__.py +0 -0
  159. {lager_cli-0.64.0 → lager_cli-0.66.0}/supply/supply_tui.py +0 -0
  160. {lager_cli-0.64.0 → lager_cli-0.66.0}/supply/websocket_client.py +0 -0
  161. {lager_cli-0.64.0 → lager_cli-0.66.0}/terminal/__init__.py +0 -0
  162. {lager_cli-0.64.0 → lager_cli-0.66.0}/terminal/core/__init__.py +0 -0
  163. {lager_cli-0.64.0 → lager_cli-0.66.0}/terminal/core/executor.py +0 -0
  164. {lager_cli-0.64.0 → lager_cli-0.66.0}/terminal/main.py +0 -0
  165. {lager_cli-0.64.0 → lager_cli-0.66.0}/terminal/ui/__init__.py +0 -0
  166. {lager_cli-0.64.0 → lager_cli-0.66.0}/terminal/ui/completer.py +0 -0
  167. {lager_cli-0.64.0 → lager_cli-0.66.0}/terminal/ui/logo.py +0 -0
  168. {lager_cli-0.64.0 → lager_cli-0.66.0}/terminal/ui/repl.py +0 -0
  169. {lager_cli-0.64.0 → lager_cli-0.66.0}/terminal/ui/themes.py +0 -0
  170. {lager_cli-0.64.0 → lager_cli-0.66.0}/update_check.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lager-cli
3
- Version: 0.64.0
3
+ Version: 0.66.0
4
4
  Summary: Lager CLI - Box and Docker connectivity
5
5
  Home-page: https://github.com/lagerdata/lager
6
6
  Author: Lager Data
@@ -205,6 +205,9 @@ lager ble scan --timeout 5.0
205
205
 
206
206
  # Connect to device
207
207
  lager ble connect <address>
208
+
209
+ # Capture 30 s of radio traffic to pcap with a BLE sniffer net (nRF52840 Dongle)
210
+ lager ble-sniffer <net> capture --duration 30 --out cap.pcap
208
211
  ```
209
212
 
210
213
  ## Configuration
@@ -151,6 +151,9 @@ lager ble scan --timeout 5.0
151
151
 
152
152
  # Connect to device
153
153
  lager ble connect <address>
154
+
155
+ # Capture 30 s of radio traffic to pcap with a BLE sniffer net (nRF52840 Dongle)
156
+ lager ble-sniffer <net> capture --duration 30 --out cap.pcap
154
157
  ```
155
158
 
156
159
  ## Configuration
@@ -7,4 +7,4 @@ Lager CLI
7
7
  A Command Line Interface for Lager Data
8
8
  """
9
9
 
10
- __version__ = '0.64.0'
10
+ __version__ = '0.66.0'
@@ -125,7 +125,8 @@ def save_boxes(boxes: Dict[str, str]) -> None:
125
125
  json.dump(data, f, indent=2)
126
126
 
127
127
 
128
- def add_box(name: str, ip: str, user: Optional[str] = None, version: Optional[str] = None) -> None:
128
+ def add_box(name: str, ip: str, user: Optional[str] = None, version: Optional[str] = None,
129
+ python_port: Optional[int] = None, platform: Optional[str] = None) -> None:
129
130
  """Add a box to the local storage.
130
131
 
131
132
  Args:
@@ -133,15 +134,36 @@ def add_box(name: str, ip: str, user: Optional[str] = None, version: Optional[st
133
134
  ip: IP address
134
135
  user: Optional username (if None and version is None, stores in legacy format)
135
136
  version: Optional version/branch name (e.g., "staging", "main")
137
+ python_port: Optional script-service port, recorded only for a Box
138
+ that does not publish it on the default (a Box on macOS). When
139
+ not given, the port already recorded under this Box's name is kept,
140
+ so editing it (a new address included) or re-adding it does not
141
+ lose it.
142
+ platform: Optional operating system of the Box, recorded only when it
143
+ is not Linux ("macos"). Kept across a re-add like ``python_port``.
144
+
145
+ Only the record being replaced is consulted. Another saved Box that
146
+ happens to have the same address (a reused IP, a leftover Mac record) is
147
+ not this Box, and its port or platform must not be copied onto it.
136
148
  """
137
149
  boxes = _load_global_boxes()
138
- if user or version:
150
+ existing = boxes.get(name)
151
+ same_box = isinstance(existing, dict)
152
+ if python_port is None and same_box and "python_port" in existing:
153
+ python_port = existing["python_port"]
154
+ if platform is None and same_box and "platform" in existing:
155
+ platform = existing["platform"]
156
+ if user or version or python_port is not None or platform:
139
157
  # New format with user and/or version
140
158
  box_dict = {"ip": ip}
141
159
  if user:
142
160
  box_dict["user"] = user
143
161
  if version:
144
162
  box_dict["version"] = version
163
+ if python_port is not None:
164
+ box_dict["python_port"] = python_port
165
+ if platform:
166
+ box_dict["platform"] = platform
145
167
  boxes[name] = box_dict
146
168
  else:
147
169
  # Legacy format (just IP string)
@@ -246,6 +268,34 @@ def get_box_name_by_ip(ip: str) -> Optional[str]:
246
268
  return None
247
269
 
248
270
 
271
+ # The port a Box's script-execution service is published on. 5000 on every
272
+ # Linux Box. A Box on macOS publishes it elsewhere, because the system's
273
+ # AirPlay receiver holds 5000 there; the installer records the port it used.
274
+ DEFAULT_PYTHON_SERVICE_PORT = 5000
275
+ PYTHON_SERVICE_PORT_KEY = "python_port"
276
+
277
+
278
+ def get_python_service_port(ip: str) -> int:
279
+ """The script-execution port for the Box at ``ip``.
280
+
281
+ ``DEFAULT_PYTHON_SERVICE_PORT`` unless a saved Box with that address
282
+ records another one. A value that is not a usable port is ignored, and so
283
+ is any failure to read the saved Boxes: this must never be the reason a
284
+ command cannot reach a Box that is on the default port.
285
+ """
286
+ try:
287
+ boxes = load_boxes()
288
+ except Exception:
289
+ return DEFAULT_PYTHON_SERVICE_PORT
290
+ for box_info in boxes.values():
291
+ if not isinstance(box_info, dict) or box_info.get("ip") != ip:
292
+ continue
293
+ port = box_info.get(PYTHON_SERVICE_PORT_KEY)
294
+ if isinstance(port, int) and not isinstance(port, bool) and 0 < port < 65536:
295
+ return port
296
+ return DEFAULT_PYTHON_SERVICE_PORT
297
+
298
+
249
299
  def delete_box(name: str) -> bool:
250
300
  """Delete a box from the global storage. Returns True if deleted, False if not found.
251
301
 
@@ -912,6 +962,7 @@ def acquire_box_lock(
912
962
  wait_seconds=0,
913
963
  poll=2.0,
914
964
  quiet=False,
965
+ fail_open=False,
915
966
  ):
916
967
  """Acquire the box lock for ``holder``.
917
968
 
@@ -930,6 +981,10 @@ def acquire_box_lock(
930
981
 
931
982
  ``holder_type`` and ``ttl_seconds`` are forwarded to the server. Older
932
983
  box versions that don't understand these fields will just ignore them.
984
+
985
+ Any other reply (no lock API, a server error) exits too, unless
986
+ ``fail_open`` is set: then it warns and returns ``("unreachable", None)``,
987
+ so the caller runs without a lock. A collision still exits either way.
933
988
  """
934
989
  import time
935
990
  import click
@@ -1053,6 +1108,23 @@ def acquire_box_lock(
1053
1108
  time.sleep(min(poll, max(0.1, deadline - time.monotonic())))
1054
1109
  continue
1055
1110
 
1111
+ # A box that cannot take a lock at all: an image older than the lock
1112
+ # API (404), or a lock server that errors. With fail_open the caller
1113
+ # carries on unlocked, as the pre-command lock check does; `lager ssh`
1114
+ # uses this because it is how such a box gets repaired.
1115
+ if fail_open:
1116
+ if not quiet:
1117
+ reason = (
1118
+ 'runs an old image without lock support'
1119
+ if resp.status_code == 404
1120
+ else f'did not take the lock (HTTP {resp.status_code})'
1121
+ )
1122
+ click.secho(
1123
+ f"Warning: box '{display}' {reason}; continuing without a lock.",
1124
+ fg='yellow', err=True,
1125
+ )
1126
+ return ('unreachable', None)
1127
+
1056
1128
  # Any other status: bail out.
1057
1129
  if not quiet:
1058
1130
  click.secho(
@@ -1580,9 +1652,15 @@ def auto_lock_around_command(
1580
1652
  holder_type=None,
1581
1653
  heartbeat_interval=None,
1582
1654
  release_retry_seconds=0,
1655
+ fail_open=False,
1583
1656
  ):
1584
1657
  """Context manager: auto-acquire a box lock for the duration of an
1585
- admin command (`install`, `uninstall`, `update`, `install-wheel`).
1658
+ admin command (`install`, `uninstall`, `update`, `install-wheel`), or
1659
+ of a `lager ssh` session.
1660
+
1661
+ ``fail_open`` is passed to :func:`acquire_box_lock`: a box that cannot
1662
+ take a lock (no lock API, a server error) yields state ``"unreachable"``
1663
+ instead of exiting. `lager ssh` sets it; the admin commands do not.
1586
1664
 
1587
1665
  Use as::
1588
1666
 
@@ -1652,6 +1730,7 @@ def auto_lock_around_command(
1652
1730
  holder_type=resolved_type,
1653
1731
  ttl_seconds=resolved_ttl,
1654
1732
  wait_seconds=resolved_wait,
1733
+ fail_open=fail_open,
1655
1734
  )
1656
1735
 
1657
1736
  should_release = (state == 'acquired')
@@ -0,0 +1,87 @@
1
+ # Copyright 2024-2026 Lager Data
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ """Commands the CLI would run on a Box over SSH, when the Box is a Mac.
5
+
6
+ Two things differ from a Linux Box, and both are decided here so that the
7
+ commands themselves stay as they are:
8
+
9
+ * A Box installed on the Mac the CLI runs on is not reached over SSH at all
10
+ (Remote Login is off by default, and there is no ``lagerdata`` user). The
11
+ command runs in a local shell instead.
12
+ * Some commands manage the Linux host: apt packages, sysctl, udev rules,
13
+ systemd units, sudoers. Run on a Mac they would fail obscurely or touch
14
+ the user's machine, so they are refused by name with a plain message.
15
+
16
+ For any Box that is not a Mac :func:`run` returns None and the caller goes
17
+ on to SSH exactly as before.
18
+ """
19
+ import re
20
+ import subprocess
21
+ from typing import Optional, Tuple
22
+
23
+ LINUX_ONLY = re.compile(
24
+ r"(?<![\w.-])(apt-get|apt|dpkg|sysctl|udevadm|systemctl|journalctl|ufw)(?![\w.-])"
25
+ r"|/etc/(udev|sysctl\.d|sudoers\.d|systemd)\b|start_box\.sh")
26
+ REFUSED_STATUS = 1
27
+
28
+
29
+ def _is_local(box_ip: str) -> bool:
30
+ from ..utility._local_install import is_local_target
31
+ return is_local_target(box_ip)
32
+
33
+
34
+ def is_macos_box(box_ip: str) -> bool:
35
+ """True for the Box on this Mac, or a saved Box installed as a Mac."""
36
+ if _is_local(box_ip):
37
+ return True
38
+ from ..utility._remote_macos import saved_macos_box
39
+ return saved_macos_box(box_ip)
40
+
41
+
42
+ def refusal(cmd: str) -> Optional[str]:
43
+ """Why ``cmd`` cannot run on a Mac, or None when it can."""
44
+ found = LINUX_ONLY.search(cmd or "")
45
+ if found is None:
46
+ return None
47
+ what = (found.group(1) or found.group(0)).strip("/")
48
+ return (f"This manages the Linux host of a Box ({what}) and is not supported "
49
+ "for a Box on macOS.")
50
+
51
+
52
+ def run(box_ip: str, cmd: str, *, stdin: Optional[str] = None, timeout: int = 60,
53
+ runner=None) -> Optional[Tuple[int, str, str]]:
54
+ """``(rc, stdout, stderr)`` when this module handles ``cmd``; else None.
55
+
56
+ None for every Box that is not a Mac, and for a remote Mac running a
57
+ command that is fine there: the caller then uses SSH as it always has.
58
+ """
59
+ if not is_macos_box(box_ip):
60
+ return None
61
+ why = refusal(cmd)
62
+ if why is not None:
63
+ return REFUSED_STATUS, "", why
64
+ if not _is_local(box_ip):
65
+ return None
66
+ try:
67
+ proc = (runner or subprocess.run)(["/bin/sh", "-c", cmd], input=stdin, capture_output=True,
68
+ text=True, timeout=timeout)
69
+ except subprocess.TimeoutExpired:
70
+ return REFUSED_STATUS, "", f"the command timed out after {timeout}s on this Mac"
71
+ return proc.returncode, proc.stdout, proc.stderr
72
+
73
+
74
+ def local_shell_argv(box_ip: str, command=(), environ=None) -> Optional[list]:
75
+ """What `lager ssh` runs for the Box on this Mac; None for any other Box.
76
+
77
+ The user's own shell, interactive with no command, or running the
78
+ command the way ``ssh host <command>`` would have.
79
+ """
80
+ if not _is_local(box_ip):
81
+ return None
82
+ import os
83
+ import shlex
84
+ shell = (os.environ if environ is None else environ).get("SHELL") or "/bin/sh"
85
+ if not command:
86
+ return [shell, "-l"]
87
+ return [shell, "-c", " ".join(shlex.quote(arg) for arg in command)]
@@ -698,6 +698,13 @@ def default_ssh_runner(
698
698
  retry can't double-execute anything. Timeouts/no-route are NOT
699
699
  retried — the second attempt would just hang the same way.
700
700
  """
701
+ # A Box on macOS: run on this Mac without SSH, or refuse a command that
702
+ # manages a Linux host. None for every other Box, which goes on below.
703
+ from . import _macos_target
704
+ handled = _macos_target.run(box_ip, cmd, stdin=stdin, timeout=timeout)
705
+ if handled is not None:
706
+ return handled
707
+
701
708
  user = resolve_box_user(box_ip)
702
709
  dest = f"{user}@{box_ip}"
703
710
 
@@ -0,0 +1,127 @@
1
+ # Copyright 2024-2026 Lager Data
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ """
5
+ Which start_box.sh a `lager box-config` bounce runs, and how it runs it.
6
+
7
+ The box checkout at ~/box is a sparse clone of the whole repository, so the
8
+ tracked script lives at ~/box/box/start_box.sh. `lager install` and
9
+ `lager update` flatten that tree after every checkout (`box/*` moves up to
10
+ ~/box, see `_flatten_shell_cmd` in utility/update.py), which leaves
11
+ ~/box/start_box.sh canonical and no ~/box/box at all.
12
+
13
+ A git update that does not flatten (a plain `git reset --hard` in ~/box, as
14
+ some box-management tooling does) restores the complete tracked tree under
15
+ ~/box/box and leaves the earlier flattened copy at ~/box untouched. From then
16
+ on the top-level start_box.sh, and the top-level lager/ tree it builds from,
17
+ are older than what was just deployed. A bounce that hardcodes
18
+ `cd ~/box && ./start_box.sh` then starts the container from that older script
19
+ and source: one that predates `--no-publish` publishes ports another container
20
+ already holds, and `docker run` fails.
21
+
22
+ The rule here is the one such tooling already uses: when ~/box/box holds a
23
+ start_box.sh, it is the newer copy and it wins. Anything under ~/box/box came
24
+ from a checkout later than the last flatten, because a completed flatten
25
+ removes ~/box/box. It additionally requires ~/box/box/lager, because
26
+ start_box.sh builds and mounts from its own directory (`SCRIPT_DIR/lager`);
27
+ a flatten that stopped partway can leave a nested start_box.sh whose lager/
28
+ already moved up, and running that copy would fail at its first `cd`. That
29
+ case falls back to the top-level copy, which is where lager/ went.
30
+
31
+ The script is run with `bash`, never `./start_box.sh`. It is tracked without
32
+ the executable bit, so a checkout that was never flattened by a path that
33
+ runs `chmod +x` cannot be executed directly. `bash ./start_box.sh` is also
34
+ the same process shape that `./start_box.sh` produced through its
35
+ `#!/bin/bash` line, which start_box.sh's own leftover-poller sweep is written
36
+ around.
37
+
38
+ POSIX only: the remote login shell may be dash.
39
+ """
40
+
41
+ from __future__ import annotations
42
+
43
+ from collections.abc import Iterable
44
+
45
+ # Set by the snippet; the directory the chosen start_box.sh lives in.
46
+ START_DIR_VAR = "_lager_start_dir"
47
+
48
+ RESOLVE_START_DIR = (
49
+ f'{START_DIR_VAR}="$HOME/box"; '
50
+ 'if [ -f "$HOME/box/box/start_box.sh" ] && [ -d "$HOME/box/box/lager" ]; '
51
+ f'then {START_DIR_VAR}="$HOME/box/box"; fi'
52
+ )
53
+
54
+
55
+ SKIP_BUILD_VAR = "_lager_skip_build"
56
+
57
+
58
+ def skip_build_if_current() -> str:
59
+ """Shell snippet: set SKIP_BUILD_VAR to 1 when the image is current.
60
+
61
+ A bounce never changes what the image is built from. box_config only
62
+ feeds `docker run` arguments and the post-start pip/cargo/npm steps, so
63
+ rebuilding on every bounce bought nothing: about a minute with a warm
64
+ Docker cache, and a cold build can outlast the bounce's SSH timeout.
65
+
66
+ "Current" means a `lager` image exists AND the tree this bounce will run
67
+ hashes to /etc/lager/build-hash, which `lager install` and `lager update`
68
+ write from the same hasher once their image is in place. The hash is taken
69
+ over the resolved directory, so a ~/box/box tree is measured as itself.
70
+ Anything else builds as before: no image, no recorded hash, or a tree that
71
+ changed since the last install or update (for example a git update that
72
+ did not go through `lager update`). A wrong skip would start new code on
73
+ an old image, so every doubt resolves to building.
74
+ """
75
+ # Lazy: utility.update is large and imports from commands.box.
76
+ from ..utility.update import _build_hash_shell_cmd
77
+
78
+ current = _build_hash_shell_cmd(f'"${START_DIR_VAR}"')
79
+ return (
80
+ f'{SKIP_BUILD_VAR}=""; '
81
+ "if docker image inspect lager >/dev/null 2>&1; then "
82
+ f"_lager_cur=$({current}); "
83
+ # Overridable only so unit tests need not write /etc/lager.
84
+ '_lager_rec=$(cat "${LAGER_BUILD_HASH_FILE:-/etc/lager/build-hash}" '
85
+ "2>/dev/null); "
86
+ 'if [ -n "$_lager_cur" ] && [ "$_lager_cur" = "$_lager_rec" ]; then '
87
+ f"{SKIP_BUILD_VAR}=1; fi; fi"
88
+ )
89
+
90
+
91
+ def start_box_command(
92
+ env: Iterable[tuple[str, str]] = (),
93
+ args: str = "",
94
+ *,
95
+ skip_build_when_current: bool = False,
96
+ ) -> str:
97
+ """Shell command that runs the deployed start_box.sh.
98
+
99
+ `env` pairs are prefixed to the `bash` invocation as `NAME=value`, so they
100
+ reach start_box.sh and nothing else. Values are inserted verbatim: pass
101
+ literals or `"$var"` references set earlier in the same command.
102
+
103
+ `skip_build_when_current` adds `skip_build_if_current` and passes its
104
+ verdict as LAGER_SKIP_BUILD. start_box.sh treats an empty value as unset.
105
+ """
106
+ env = list(env)
107
+ steps = [RESOLVE_START_DIR]
108
+ if skip_build_when_current:
109
+ steps.append(skip_build_if_current())
110
+ env.append(("LAGER_SKIP_BUILD", f'"${SKIP_BUILD_VAR}"'))
111
+ prefix = "".join(f"{name}={value} " for name, value in env)
112
+ suffix = f" {args}" if args else ""
113
+ return (
114
+ "; ".join(steps)
115
+ + f'; cd "${START_DIR_VAR}" && {prefix}bash ./start_box.sh{suffix}'
116
+ )
117
+
118
+
119
+ # start_box.sh's line when LAGER_SKIP_BUILD is set; the bounce reports it.
120
+ SKIPPED_BUILD_MARKER = "Skipping build (LAGER_SKIP_BUILD set"
121
+
122
+
123
+ # For operator-facing hints: where to look when running it by hand.
124
+ MANUAL_START_HINT = (
125
+ "`~/box/box/start_box.sh` if that directory exists, otherwise "
126
+ "`~/box/start_box.sh` (run it with `bash`)"
127
+ )
@@ -810,33 +810,63 @@ def add_all(yes):
810
810
  return
811
811
 
812
812
  added_count = 0
813
+ updated_count = 0
813
814
  skipped_count = 0
814
815
 
816
+ def _ip_of(info):
817
+ return info.get('ip') if isinstance(info, dict) else info
818
+
815
819
  click.echo()
816
820
  for name, ip in boxes_found:
817
821
  existing_boxes = list_boxes()
818
- if name in existing_boxes:
819
- existing_ip = existing_boxes[name].get('ip') if isinstance(existing_boxes[name], dict) else existing_boxes[name]
820
- if existing_ip == ip:
821
- click.echo(f" {name}: ", nl=False)
822
- click.secho('already exists (skipped)', fg='yellow')
823
- skipped_count += 1
824
- continue
822
+ saved = existing_boxes.get(name)
823
+ if saved is not None and _ip_of(saved) == ip:
824
+ click.echo(f" {name}: ", nl=False)
825
+ click.secho('already exists (skipped)', fg='yellow')
826
+ skipped_count += 1
827
+ continue
825
828
 
826
- # Add the box (without triggering prompts)
827
- add_box(name, ip, None, None)
829
+ # Same rules as `lager boxes add`: a changed IP, or an IP another box
830
+ # already has, is replaced only on a confirm (or --yes), so two
831
+ # entries never share an IP.
832
+ same_ip = next((n for n, info in existing_boxes.items()
833
+ if n != name and _ip_of(info) == ip), None)
834
+ if saved is not None or same_ip is not None:
835
+ if not yes:
836
+ click.echo(f" {name}:")
837
+ if saved is not None:
838
+ click.echo(f" saved with IP {_ip_of(saved)}; Tailscale reports {ip}")
839
+ if same_ip is not None:
840
+ click.echo(f" IP {ip} is already saved as {same_ip}, which is replaced")
841
+ if not click.confirm(f" Update {name}?", default=False):
842
+ click.echo(f" {name}: ", nl=False)
843
+ click.secho('not changed (skipped)', fg='yellow')
844
+ skipped_count += 1
845
+ continue
846
+ if same_ip is not None:
847
+ delete_box(same_ip)
848
+
849
+ # Keep a saved user and version; only the IP changes.
850
+ user = saved.get('user') if isinstance(saved, dict) else None
851
+ version = saved.get('version') if isinstance(saved, dict) else None
852
+ add_box(name, ip, user, version)
828
853
  click.echo(f" {name}: ", nl=False)
829
- click.secho('added', fg='green')
830
- added_count += 1
854
+ if saved is not None or same_ip is not None:
855
+ click.secho('updated', fg='green')
856
+ updated_count += 1
857
+ else:
858
+ click.secho('added', fg='green')
859
+ added_count += 1
831
860
 
832
861
  click.echo()
833
862
  click.echo(click.style('Summary:', fg='blue', bold=True))
834
863
  click.echo(f" Added: {added_count}")
864
+ click.echo(f" Updated: {updated_count}")
835
865
  click.echo(f" Skipped: {skipped_count}")
836
866
 
837
- if added_count > 0:
867
+ if added_count or updated_count:
838
868
  click.echo()
839
- click.secho(f'[OK] Successfully added {added_count} box(es)', fg='green')
869
+ click.secho(f'[OK] Added {added_count} and updated {updated_count} box(es)', fg='green')
840
870
 
841
871
 
842
872
  @boxes.command('delete')
@@ -966,11 +996,18 @@ def edit(name, ip, user, version, new_name, yes):
966
996
  click.echo("Cancelled. Box not modified.")
967
997
  return
968
998
 
999
+ # A Box on macOS records the port its script service is published on;
1000
+ # carry it across a rename. None for every Box that records none.
1001
+ stored = load_boxes().get(name)
1002
+ python_port = stored.get("python_port") if isinstance(stored, dict) else None
1003
+ platform = stored.get("platform") if isinstance(stored, dict) else None
1004
+
969
1005
  # If renaming, delete old entry
970
1006
  if new_name and new_name != name:
971
1007
  delete_box(name)
972
1008
 
973
- add_box(updated_name, updated_ip, updated_user, updated_version)
1009
+ add_box(updated_name, updated_ip, updated_user, updated_version,
1010
+ python_port=python_port, platform=platform)
974
1011
 
975
1012
  changes_made = []
976
1013
  if new_name and new_name != name:
@@ -31,6 +31,11 @@ from . import _shim_verbs as verbs
31
31
  from ._host_ops import apt_install, sysctl_apply, udev_apply
32
32
  from ._mount_prep import ensure_host_path_owned, manual_fix_command
33
33
  from ._pip_validation import is_direct_ref, validate_on_pypi
34
+ from ._start_script import (
35
+ MANUAL_START_HINT,
36
+ SKIPPED_BUILD_MARKER,
37
+ start_box_command,
38
+ )
34
39
  from ._ssh import default_ssh_runner, resolve_box_user
35
40
 
36
41
  # How long we'll wait for the box's HTTP API to come up after start_box.sh
@@ -1257,7 +1262,7 @@ def restart_cmd(ctx: click.Context, box: Optional[str], yes: bool) -> None:
1257
1262
  if bounce_rc != _BOUNCE_OK:
1258
1263
  click.secho(
1259
1264
  "Container restart failed. SSH into the box and run "
1260
- "`~/box/start_box.sh` manually to inspect.",
1265
+ f"{MANUAL_START_HINT} manually to inspect.",
1261
1266
  fg="red", err=True,
1262
1267
  )
1263
1268
  ctx.exit(1)
@@ -1470,7 +1475,7 @@ def _apply_one(
1470
1475
  click.secho(
1471
1476
  "Container restart failed and rollback was not possible. The "
1472
1477
  "container can be down. SSH into the box, fix /etc/lager/box_config.json, "
1473
- "and run `~/box/start_box.sh` manually.",
1478
+ f"and run {MANUAL_START_HINT} manually.",
1474
1479
  fg="red",
1475
1480
  err=True,
1476
1481
  )
@@ -2062,9 +2067,12 @@ def _bounce_container_rc(
2062
2067
  networking. Only `apply` passes it, after its reachability check.
2063
2068
  """
2064
2069
  click.echo(f"Restarting lager container on {resolved_box} via SSH...")
2065
- command = "cd ~/box && ./start_box.sh"
2066
- if confirm_network_switch:
2067
- command = f"cd ~/box && {_NETWORK_SWITCH_CONFIRM_ENV}=1 ./start_box.sh"
2070
+ # Not a hardcoded `cd ~/box && ./start_box.sh`: on a box whose tracked tree
2071
+ # sits under ~/box/box, that path is an older copy (see _start_script).
2072
+ env = [(_NETWORK_SWITCH_CONFIRM_ENV, "1")] if confirm_network_switch else []
2073
+ # A bounce never changes what the image is built from, so the box skips
2074
+ # the rebuild when the image matches the tree (see skip_build_if_current).
2075
+ command = start_box_command(env, skip_build_when_current=True)
2068
2076
  try:
2069
2077
  rc, stdout, stderr = default_ssh_runner(
2070
2078
  resolved_box,
@@ -2092,6 +2100,9 @@ def _bounce_container_rc(
2092
2100
  return _BOUNCE_CONFIG_NOT_APPLIED
2093
2101
 
2094
2102
  if rc == 0:
2103
+ if SKIPPED_BUILD_MARKER in (stdout or ""):
2104
+ click.echo(" Image unchanged since the last install or update; "
2105
+ "reused it without rebuilding.")
2095
2106
  # Say what the container-side package steps did. Only [ERROR] lines were
2096
2107
  # ever relayed, and only on rc 3, so a successful apply printed nothing
2097
2108
  # about pip/cargo/npm at all -- which made "installed three crates" and
@@ -41,6 +41,7 @@ NET_ROLE_CHOICES = [
41
41
  'uart', 'webcam', 'adc', 'dac', 'gpio', 'thermocouple', 'i2c', 'spi',
42
42
  'watt-meter', 'energy-analyzer', 'router', 'rotation', 'arm', 'actuate',
43
43
  'power-supply-2q', 'wifi', 'analog', 'logic', 'waveform', 'hsm', 'dmm',
44
+ 'ble-sniffer',
44
45
  ]
45
46
 
46
47