feat: professionalize control plane and standalone delivery
This commit is contained in:
@ -2,18 +2,27 @@ from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
ALLOWED_LOG_FILES = {
|
||||
"monitor.log": Path("/home/theshy/biliup/logs/system/monitor.log"),
|
||||
"monitorSrt.log": Path("/home/theshy/biliup/logs/system/monitorSrt.log"),
|
||||
"monitorSongs.log": Path("/home/theshy/biliup/logs/system/monitorSongs.log"),
|
||||
"upload.log": Path("/home/theshy/biliup/logs/system/upload.log"),
|
||||
"session_top_comment.py.log": Path("/home/theshy/biliup/logs/system/session_top_comment.py.log"),
|
||||
"add_to_collection.py.log": Path("/home/theshy/biliup/logs/system/add_to_collection.py.log"),
|
||||
}
|
||||
|
||||
|
||||
class LogReader:
|
||||
def __init__(self, root_dir: Path | None = None):
|
||||
self.root_dir = (root_dir or Path(__file__).resolve().parents[3]).resolve()
|
||||
self.log_dirs = [
|
||||
self.root_dir / "logs",
|
||||
self.root_dir / "runtime" / "logs",
|
||||
self.root_dir / "data" / "workspace" / "logs",
|
||||
]
|
||||
|
||||
def _allowed_log_files(self) -> dict[str, Path]:
|
||||
items: dict[str, Path] = {}
|
||||
for log_dir in self.log_dirs:
|
||||
if not log_dir.exists():
|
||||
continue
|
||||
for path in sorted(p for p in log_dir.rglob("*.log") if p.is_file()):
|
||||
items.setdefault(path.name, path.resolve())
|
||||
return items
|
||||
|
||||
def list_logs(self) -> dict[str, object]:
|
||||
allowed_log_files = self._allowed_log_files()
|
||||
return {
|
||||
"items": [
|
||||
{
|
||||
@ -21,14 +30,15 @@ class LogReader:
|
||||
"path": str(path),
|
||||
"exists": path.exists(),
|
||||
}
|
||||
for name, path in sorted(ALLOWED_LOG_FILES.items())
|
||||
for name, path in sorted(allowed_log_files.items())
|
||||
]
|
||||
}
|
||||
|
||||
def tail(self, name: str, lines: int = 200, contains: str | None = None) -> dict[str, object]:
|
||||
if name not in ALLOWED_LOG_FILES:
|
||||
allowed_log_files = self._allowed_log_files()
|
||||
if name not in allowed_log_files:
|
||||
raise ValueError(f"unsupported log: {name}")
|
||||
path = ALLOWED_LOG_FILES[name]
|
||||
path = allowed_log_files[name]
|
||||
if not path.exists():
|
||||
return {"name": name, "path": str(path), "exists": False, "content": ""}
|
||||
content = path.read_text(encoding="utf-8", errors="replace").splitlines()
|
||||
|
||||
Reference in New Issue
Block a user