From 8a91a5b7a97378e8aa37b5474df9f9eb234aedb4 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 06:51:05 +0900 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B0=D1=82=D1=87=D0=B5=D1=80=20Update?= =?UTF-8?q?=20Center=20=D0=B1=D1=8B=D0=BB=20=D1=83=D0=BF=D1=80=D0=BE=D1=89?= =?UTF-8?q?=D1=91=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/patch_update_center.py | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/scripts/patch_update_center.py b/scripts/patch_update_center.py index 78bcd4c..75720bf 100644 --- a/scripts/patch_update_center.py +++ b/scripts/patch_update_center.py @@ -1,22 +1,21 @@ #!/usr/bin/env python3 from pathlib import Path -import runpy 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}') -script_dir = Path(__file__).resolve().parent - text = app_path.read_text() changed = [] if 'import update_core' not in text: if 'import network_core\n' in text: text = text.replace('import network_core\n', 'import network_core\nimport update_core\n', 1) - else: + elif 'from network_core import NetworkError\n' in text: text = text.replace('from network_core import NetworkError\n', 'from network_core import NetworkError\nimport update_core\n', 1) + else: + raise SystemExit('network_core import marker not found') changed.append('import update_core added') else: changed.append('import update_core already present') @@ -98,6 +97,7 @@ if '@app.get("/update"' not in text: text = text.replace(marker, routes + marker, 1) changed.append('update routes added') else: + changed.append('update route already present') if '@app.get("/update/status"' not in text: marker = '\n\n@app.post("/update/check")' if marker not in text: @@ -125,22 +125,3 @@ app_path.write_text(text) print('update center patch applied:') for item in changed: print(f'- {item}') - -# Extra feature patches are intentionally executed after Update Center routes are written. -# Some legacy patches can exit early; they must not block /update from being installed. -for optional_patch in ('patch_disk_images.py', 'patch_disk_convert_progress.py', 'patch_vm_architecture.py', 'patch_arm64_emulation_xml.py', 'patch_vm_disk_replace.py', 'patch_update_badge.py'): - patch_path = script_dir / optional_patch - if not patch_path.exists(): - continue - old_argv = sys.argv[:] - try: - sys.argv = [str(patch_path), str(app_path)] - try: - runpy.run_path(str(patch_path), run_name='__main__') - except SystemExit as exc: - code = exc.code - if code not in (None, 0): - raise - print(f'optional patch exited after successful run: {optional_patch}') - finally: - sys.argv = old_argv