From c1dfb3368ee6a56bcbaf969b0ceb25fdbfa0458d 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 04:19:36 +0900 Subject: [PATCH] =?UTF-8?q?=D0=A6=D0=B5=D0=BD=D1=82=D1=80=20=D0=B6=D1=83?= =?UTF-8?q?=D1=80=D0=BD=D0=B0=D0=BB=D0=BE=D0=B2=20=D0=B8=20=D0=B4=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=D0=BC=D0=B8=D0=BA=D0=B0=20=D0=B8=D0=BD=D1=82=D0=B5?= =?UTF-8?q?=D1=80=D1=84=D0=B5=D0=B9=D1=81=D0=B0=20=D0=B1=D1=8B=D0=BB=D0=B8?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/patch_logs_center.py | 90 ++++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 13 deletions(-) diff --git a/scripts/patch_logs_center.py b/scripts/patch_logs_center.py index 65dfca5..cd318b3 100644 --- a/scripts/patch_logs_center.py +++ b/scripts/patch_logs_center.py @@ -6,6 +6,8 @@ app_path = Path(sys.argv[1]) if len(sys.argv) > 1 else Path('/opt/virtuality/web if not app_path.exists(): raise SystemExit(f'app.py not found: {app_path}') +templates_dir = app_path.parent / 'templates' +static_dir = app_path.parent / 'static' text = app_path.read_text() changed = [] @@ -60,11 +62,19 @@ def read_log_source(source: str, lines: int = 220) -> dict[str, Any]: ''' if 'LOG_SOURCES = {' not in text: - marker = '\n\ndef parse_virsh_list() -> list[dict[str, str]]:' - if marker not in text: - raise SystemExit('parse_virsh_list marker not found') - text = text.replace(marker, helpers + marker, 1) - changed.append('log center helpers added') + markers = [ + '\n\ndef parse_virsh_list() -> list[dict[str, str]]:', + '\n\ndef list_recent_operations(limit: int = 20) -> list[dict[str, Any]]:', + '\n\ndef safe_iso_filename(filename: str) -> str | None:', + ] + for marker in markers: + if marker in text: + text = text.replace(marker, helpers + marker, 1) + changed.append('log center helpers added') + break + else: + print('WARN: log helper marker not found, skip helper injection') + changed.append('log center helpers skipped') else: changed.append('log center helpers already present') @@ -93,17 +103,71 @@ def api_logs(request: Request, source: str = "web", lines: int = 220): ''' if '@app.get("/logs"' not in text: - marker = '\n\n@app.get("/vm/create", response_class=HTMLResponse)' - if marker not in text: - marker = '\n\n@app.get("/api/operations")' - if marker not in text: - raise SystemExit('route insert marker not found') - text = text.replace(marker, route + marker, 1) - changed.append('logs routes added') + markers = ['\n\n@app.get("/vm/create", response_class=HTMLResponse)', '\n\n@app.get("/api/operations")', '\n\n@app.get("/iso", response_class=HTMLResponse)'] + for marker in markers: + if marker in text: + text = text.replace(marker, route + marker, 1) + changed.append('logs routes added') + break + else: + print('WARN: logs route insert marker not found, skip route injection') + changed.append('logs routes skipped') else: changed.append('logs routes already present') app_path.write_text(text) -print('logs center patch applied:') + +sidebar_html = '''{% set path = request.url.path %} + +''' + +if templates_dir.exists(): + sidebar_path = templates_dir / '_sidebar.html' + sidebar_path.write_text(sidebar_html) + changed.append('_sidebar.html ensured') + + for path in sorted(templates_dir.glob('*.html')): + if path.name in {'login.html', 'console.html', '_sidebar.html'}: + continue + html = path.read_text() + if '' not in html: + html = html.replace('', ' \n', 1) + changed.append(f'{path.name} panel.js attached') + if '{% include "_sidebar.html" %}' not in html and '
' not in html and '
' in html: + html = html.replace('\n
', '\n
\n {% include "_sidebar.html" %}\n
\n
', 1) + script_marker = '\n\n