diff --git a/scripts/patch_remove_legacy_boot_order_card.py b/scripts/patch_remove_legacy_boot_order_card.py new file mode 100644 index 0000000..e5c67a9 --- /dev/null +++ b/scripts/patch_remove_legacy_boot_order_card.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 +from pathlib import Path +import re +import sys + +app_path = Path(sys.argv[1]) if len(sys.argv) > 1 else Path('/opt/virtuality/web/app.py') +app_dir = app_path.resolve().parent if app_path.exists() else Path('/opt/virtuality/web') +template_path = app_dir / 'templates' / 'vm_detail.html' +changed = [] + +if not template_path.exists(): + print(f'legacy boot order cleanup skipped: vm_detail.html not found: {template_path}') + raise SystemExit(0) + +tpl = template_path.read_text() +original = tpl + +legacy_pattern = re.compile( + r'\n\s*
\s*\n' + r'\s*
\s*\n' + r'\s*

Порядок загрузки

\s*\n' + r'\s*boot order\s*\n' + r'.*?' + r'\s*
\s*\n', + re.DOTALL, +) + +tpl, count = legacy_pattern.subn('\n', tpl) +if count: + changed.append(f'legacy select boot-order card removed: {count}') + +# Safety cleanup for any accidental duplicated plain select card without the old pill text. +plain_select_pattern = re.compile( + r'\n\s*
\s*\n' + r'\s*
\s*\n' + r'\s*

Порядок загрузки

.*?' + r'