boneIO 1.5.0.dev6__py3-none-any.whl → 1.5.0.dev7__py3-none-any.whl

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.
@@ -14,6 +14,7 @@ Flow:
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
+ import hashlib
17
18
  import importlib
18
19
  import importlib.util
19
20
  import json
@@ -155,6 +156,7 @@ class MigrationRunner:
155
156
  self.status = MigrationStatus.BOOTSTRAP_REQUIRED
156
157
  return self.status
157
158
 
159
+ self._ensure_helper_up_to_date()
158
160
  self._apply_pending(pending)
159
161
 
160
162
  except Exception as exc:
@@ -184,6 +186,7 @@ class MigrationRunner:
184
186
  self.status = MigrationStatus.OK
185
187
  return True
186
188
 
189
+ self._ensure_helper_up_to_date()
187
190
  return self._apply_pending(pending, progress_callback=progress_callback)
188
191
 
189
192
  def get_status_dict(self) -> dict[str, Any]:
@@ -282,6 +285,85 @@ class MigrationRunner:
282
285
  """Return True when the helper binary exists and is executable."""
283
286
  return os.path.isfile(HELPER_PATH) and os.access(HELPER_PATH, os.X_OK)
284
287
 
288
+ def _ensure_helper_up_to_date(self) -> None:
289
+ """Auto-update /usr/sbin/boneio-migrate if the bundled version differs.
290
+
291
+ Compares SHA256 of the installed helper vs the one shipped in the
292
+ package. If they differ, sends an ``install_file`` action to the
293
+ currently installed helper to overwrite itself with the new version.
294
+ This works because ``sudo -n /usr/sbin/boneio-migrate`` is already
295
+ allowed in sudoers on all systems.
296
+ """
297
+ if not BOOTSTRAP_HELPER_SRC.exists():
298
+ return
299
+ if not self._helper_installed():
300
+ return
301
+
302
+ try:
303
+ installed_hash = hashlib.sha256(
304
+ Path(HELPER_PATH).read_bytes()
305
+ ).hexdigest()
306
+ bundled_hash = hashlib.sha256(
307
+ BOOTSTRAP_HELPER_SRC.read_bytes()
308
+ ).hexdigest()
309
+
310
+ if installed_hash == bundled_hash:
311
+ _LOGGER.debug("boneio-migrate helper is up to date.")
312
+ return
313
+
314
+ _LOGGER.info(
315
+ "boneio-migrate helper outdated (installed=%s, bundled=%s). Updating...",
316
+ installed_hash[:12],
317
+ bundled_hash[:12],
318
+ )
319
+
320
+ # Copy the new helper to assets dir so install_file can find it
321
+ update_asset = ASSETS_DIR / "_helper_update"
322
+ update_asset.mkdir(parents=True, exist_ok=True)
323
+ update_src = update_asset / "boneio-migrate"
324
+ update_src.write_bytes(BOOTSTRAP_HELPER_SRC.read_bytes())
325
+
326
+ # Send install_file action to the old helper to overwrite itself
327
+ plan_payload = {
328
+ "version": "_helper_update",
329
+ "actions": [
330
+ {
331
+ "action": "install_file",
332
+ "src": "_helper_update/boneio-migrate",
333
+ "dst": HELPER_PATH,
334
+ "mode": 0o755,
335
+ "owner": "root",
336
+ "group": "root",
337
+ "template_vars": {},
338
+ "expected_sha256": bundled_hash,
339
+ }
340
+ ],
341
+ "assets_base": str(ASSETS_DIR),
342
+ }
343
+
344
+ result = subprocess.run(
345
+ ["sudo", "-n", HELPER_PATH],
346
+ input=json.dumps(plan_payload),
347
+ capture_output=True,
348
+ text=True,
349
+ timeout=15,
350
+ )
351
+
352
+ # Clean up temp asset
353
+ update_src.unlink(missing_ok=True)
354
+ update_asset.rmdir()
355
+
356
+ if result.returncode == 0:
357
+ _LOGGER.info("boneio-migrate helper updated successfully.")
358
+ else:
359
+ _LOGGER.warning(
360
+ "Helper self-update failed (rc=%d): %s",
361
+ result.returncode,
362
+ result.stderr.strip(),
363
+ )
364
+ except Exception as exc:
365
+ _LOGGER.warning("Could not check/update boneio-migrate helper: %s", exc)
366
+
285
367
  def _load_manifest(self) -> None:
286
368
  """Load MANIFEST.sha256 from the assets directory."""
287
369
  if not MANIFEST_PATH.exists():
boneio/version.py CHANGED
@@ -1,2 +1,2 @@
1
1
  # flake8: noqa
2
- __version__ = "1.5.0dev6"
2
+ __version__ = "1.5.0dev7"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: boneio
3
- Version: 1.5.0.dev6
3
+ Version: 1.5.0.dev7
4
4
  Summary: Python App for BoneIO
5
5
  Author-email: Paweł Szafer <pszafer@gmail.com>
6
6
  License: GNU General Public License v3.0
@@ -3,7 +3,7 @@ boneio/bonecli.py,sha256=MfkiiMkoIZ98davH3L7IrBvugQbiIpAidWEabn5GZmQ,13160
3
3
  boneio/const.py,sha256=M981R2gwfjDX3lcoufWOyGlNxvGMESWgXOjVkmJfX60,7208
4
4
  boneio/exceptions.py,sha256=cBph-TsLF7FSz6p4wYeMs3pjVmVRaNQRJP82JgYYV-c,810
5
5
  boneio/runner.py,sha256=HmvHh_sijUyUMq9128bDaGiNs2nLPMtFSFNEHFStkEg,18572
6
- boneio/version.py,sha256=7l63FEkl3m-y_bSilWmyBeDDj7en6skiLBLPQuYNW1o,41
6
+ boneio/version.py,sha256=6umRhYjSMA503CEbEF0-jxgJUv4ZN9LcuEVg7VHBcY0,41
7
7
  boneio/boards/0.2/input.yaml,sha256=K5EcB44BZ8PxbPnH1izYwJ-ePo8gs4qZttMXhnMnfQ8,1259
8
8
  boneio/boards/0.2/output_24_16.yaml,sha256=GQGM3gUK7UobdGL-Ejt9UKdCs1HLPgZ7kziVZ1tjQlA,1462
9
9
  boneio/boards/0.2/output_32_10.yaml,sha256=169ubuzRqFLGiOr7zgB1xL1tKdQyOx2FJZvTCkxCA4U,1920
@@ -239,7 +239,7 @@ boneio/integration/interlock.py,sha256=P1-uPamm3yMRz7LuZrvV34lmj2xAUxMGHtzRp0ecv
239
239
  boneio/integration/lox_template.py,sha256=Kfr8yzuEFP21QARijJOkI-L4Qsdyukhns1fgN_n6JDM,13067
240
240
  boneio/migrations/__init__.py,sha256=ymImsxVT2PF3lfiqqANJSBugMT8IW9gSSUqWcDDaYrk,349
241
241
  boneio/migrations/actions.py,sha256=E5TIqdIshfIaSX48qu6ubxhtAT8_eRPfIdB6hU2x51g,7826
242
- boneio/migrations/runner.py,sha256=FL5Td8DAJSFQimNcWwXtul7VckUkYZfar_m2CmT2cqE,17611
242
+ boneio/migrations/runner.py,sha256=SxI7oSNZYw5lzykmkMyu4H-dpo0kFX4SnpkIigvq2g8,20723
243
243
  boneio/migrations/assets/MANIFEST.sha256,sha256=cFLOV42PFZsOCioeDgNDYNevPwPMN_sFeEUqlQAf_6g,1839
244
244
  boneio/migrations/assets/docker/daemon.json,sha256=8u0FxvWTShXxJXETm9wiWAT2e4yDVhzDmGj3siltJpc,96
245
245
  boneio/migrations/assets/docker/nodered/docker-compose.yaml,sha256=zZDhvLZIhmkXnI56QKYmWSPg_qBFzHnVt1WeuzCRMbY,1114
@@ -455,9 +455,9 @@ boneio/webui/schema/virtual_energy_sensor.schema.json,sha256=BN6Egh-CAnXSa80bQ6Y
455
455
  boneio/webui/schema/web.schema.json,sha256=cactLq1MVwDL5hu8bLeuq5yiz49BWVS4OtjWLmhbw2M,2592
456
456
  boneio/webui/services/__init__.py,sha256=l_L3YUPhc0ZbrWqKH1RurC7UQ4q0k-5ABGTwOSS-YFQ,282
457
457
  boneio/webui/services/logs.py,sha256=rKx-7jbNXNuQpuqJHtIHBCXZ3ELguDJL82RySAUT38Y,11980
458
- boneio-1.5.0.dev6.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
459
- boneio-1.5.0.dev6.dist-info/METADATA,sha256=pvxln27QK0OX_RqYEcmBPxoq0k8Sv7x6w4V4nBj8zDw,1961
460
- boneio-1.5.0.dev6.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
461
- boneio-1.5.0.dev6.dist-info/entry_points.txt,sha256=JX7gluDIkQ6MBlzzxGHMItnBjciiJ73tsXwYcazMW_U,47
462
- boneio-1.5.0.dev6.dist-info/top_level.txt,sha256=ag9S5n1_KXZfyk9tN8R0YUDYbdA--e5a2w2FOD_yMdg,7
463
- boneio-1.5.0.dev6.dist-info/RECORD,,
458
+ boneio-1.5.0.dev7.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
459
+ boneio-1.5.0.dev7.dist-info/METADATA,sha256=Vi-VjciKf_mdGlq4bDyDpEKLJvE_P03C9OD1N3xHJ9o,1961
460
+ boneio-1.5.0.dev7.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
461
+ boneio-1.5.0.dev7.dist-info/entry_points.txt,sha256=JX7gluDIkQ6MBlzzxGHMItnBjciiJ73tsXwYcazMW_U,47
462
+ boneio-1.5.0.dev7.dist-info/top_level.txt,sha256=ag9S5n1_KXZfyk9tN8R0YUDYbdA--e5a2w2FOD_yMdg,7
463
+ boneio-1.5.0.dev7.dist-info/RECORD,,