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('