From 97f702fab210852782ba6e1f376fb2b4cfbe8b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80?= <78488229+viktor138irk@users.noreply.github.com> Date: Thu, 7 May 2026 01:53:20 +0900 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BF=D0=B0=D1=82=D1=87=20=D1=83=D0=B2=D0=B5=D0=B4?= =?UTF-8?q?=D0=BE=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BE=D0=B1=20?= =?UTF-8?q?=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/patch_update_badge.py | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 scripts/patch_update_badge.py diff --git a/scripts/patch_update_badge.py b/scripts/patch_update_badge.py new file mode 100644 index 0000000..61941c7 --- /dev/null +++ b/scripts/patch_update_badge.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +from pathlib import Path +import sys + +app_path = Path(sys.argv[1]) if len(sys.argv) > 1 else Path('/opt/virtuality/web/app.py') +if not app_path.exists(): + raise SystemExit(f'app.py not found: {app_path}') + +text = app_path.read_text() +changed = [] + +if 'import update_core' not in text: + text = text.replace('import network_core\n', 'import network_core\nimport update_core\n', 1) + changed.append('import update_core added') + +helper = r''' + +def dashboard_update_notice() -> dict[str, Any]: + try: + info = update_core.check_updates(fetch=False) + if info.get("has_update"): + return { + "has_update": True, + "current_version": info.get("current_version", "unknown"), + "latest_version": info.get("latest_version", "unknown"), + "missing_count": len(info.get("missing_versions", [])), + "commit_count": len(info.get("commits", [])), + } + except Exception: + pass + return {"has_update": False} +''' + +if 'def dashboard_update_notice() -> dict[str, Any]:' not in text: + marker = '\n\ndef update_operation(operation: dict[str, Any], **changes: Any) -> None:' + if marker not in text: + raise SystemExit('update_operation marker not found') + text = text.replace(marker, helper + marker, 1) + changed.append('dashboard update notice helper added') +else: + changed.append('dashboard update notice helper already present') + +old_fragment = '"operations": list_operations(5), "operation_css": operation_css})' +new_fragment = '"operations": list_operations(5), "operation_css": operation_css, "update_notice": dashboard_update_notice()})' +if old_fragment in text: + text = text.replace(old_fragment, new_fragment, 1) + changed.append('dashboard context gets update_notice') +elif '"update_notice": dashboard_update_notice()' in text: + changed.append('dashboard context already has update_notice') +else: + raise SystemExit('dashboard context marker not found') + +app_path.write_text(text) +print('update badge patch applied:') +for item in changed: + print(f'- {item}')