From 26ba7a6add4fe9ff8786b9494f3741d82c6f3bfc 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 05:37:23 +0900 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B0=D1=82=D1=87=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B3=D1=80=D0=B5=D1=81=D1=81=D0=B0=20=D0=BA=D0=BE=D0=BD=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D1=82=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B4=D0=B8=D1=81?= =?UTF-8?q?=D0=BA=D0=BE=D0=B2=20=D0=B1=D0=BE=D0=BB=D1=8C=D1=88=D0=B5=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D0=B2=D0=B0=D0=BB=D0=B8=D0=BB=20=D1=83=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D1=89=D0=B8=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/patch_disk_convert_progress.py | 28 ++++++++++++++++---------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/scripts/patch_disk_convert_progress.py b/scripts/patch_disk_convert_progress.py index 1e99bf8..441810a 100644 --- a/scripts/patch_disk_convert_progress.py +++ b/scripts/patch_disk_convert_progress.py @@ -4,10 +4,12 @@ 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}') + print(f'WARN: app.py not found: {app_path}') + raise SystemExit(0) text = app_path.read_text() changed = [] +warnings = [] old_progress = '''def progress_from_line(current: int, line: str) -> int: low = line.lower() @@ -23,10 +25,10 @@ old_progress = '''def progress_from_line(current: int, line: str) -> int: ''' new_progress = '''def progress_from_line(current: int, line: str) -> int: low = line.lower() - convert_match = re.search(r"\((\d+(?:\.\d+)?)\s*/\s*100%\)", line) + convert_match = re.search(r"\\((\\d+(?:\\.\\d+)?)\\s*/\\s*100%\\)", line) if convert_match: return max(1, min(99, int(float(convert_match.group(1))))) - percent_match = re.search(r"(\d+(?:\.\d+)?)%", line) + percent_match = re.search(r"(\\d+(?:\\.\\d+)?)%", line) if "qemu-img" in low and percent_match: return max(1, min(99, int(float(percent_match.group(1))))) if "allocating" in low or "creating storage" in low: @@ -45,7 +47,7 @@ if old_progress in text: elif 'convert_match = re.search' in text: changed.append('qemu-img percent parser already present') else: - raise SystemExit('progress_from_line marker not found') + warnings.append('progress_from_line marker not found, progress parser skipped') helpers = r''' @@ -84,10 +86,11 @@ def start_disk_image_convert_operation(source_path: Path, target_path: Path, sou ''' if 'def start_disk_image_convert_operation(' not in text: marker = '\n\ndef valid_vm_name(name: str) -> bool:' - if marker not in text: - raise SystemExit('valid_vm_name marker not found') - text = text.replace(marker, helpers + marker, 1) - changed.append('disk conversion operation helpers added') + if marker in text: + text = text.replace(marker, helpers + marker, 1) + changed.append('disk conversion operation helpers added') + else: + warnings.append('valid_vm_name marker not found, conversion helpers skipped') else: changed.append('disk conversion operation helpers already present') @@ -154,12 +157,15 @@ def disk_image_upload(request: Request, image_file: UploadFile = File(...)): if old_upload in text: text = text.replace(old_upload, new_upload, 1) changed.append('disk upload returns JSON and starts conversion operation') -elif 'mode": "converting"' in text and 'start_disk_image_convert_operation' in text: +elif 'mode": "converting"' in text and ('start_disk_image_convert_operation' in text or 'start_disk_convert_operation' in text): changed.append('disk upload conversion already present') else: - raise SystemExit('disk_image_upload marker not found') + warnings.append('disk_image_upload marker not found, upload conversion patch skipped') app_path.write_text(text) -print('disk convert progress patch applied:') +print('disk convert progress patch completed:') for item in changed: print(f'- {item}') +for item in warnings: + print(f'WARN: {item}') +raise SystemExit(0)