feat: 只保留管理入口,缓存小区信息表解析,连接中显示提示,移除脚本管理打包方式
This commit is contained in:
+23
-12
@@ -7,11 +7,11 @@ from pathlib import Path
|
||||
|
||||
import main
|
||||
|
||||
from .config import SettingsStore
|
||||
from .config import Settings, SettingsStore
|
||||
from .connectors import build_client, build_storage, build_store, close_quietly
|
||||
|
||||
|
||||
def run(settings_path: Path, output_dir: Path, dry_run: bool) -> int:
|
||||
def run(settings_path: Path, output_dir: Path, dry_run: bool, cache_dir: Path | None = None) -> int:
|
||||
settings = SettingsStore(settings_path).get()
|
||||
print(f"storage_mode={settings.storage_mode}")
|
||||
print(f"database_mode={'none' if dry_run else settings.database_mode}")
|
||||
@@ -23,28 +23,39 @@ def run(settings_path: Path, output_dir: Path, dry_run: bool) -> int:
|
||||
history = None
|
||||
if store is not None and settings.history_enabled:
|
||||
history = main.StorageHistoryStore(storage, settings.history_root)
|
||||
if not dry_run and settings.history_keep_days > 0:
|
||||
try:
|
||||
removed = main.StorageHistoryStore(storage, settings.history_root).prune(settings.history_keep_days)
|
||||
except main.ProcessingError as exc:
|
||||
print(f"history_prune_error={exc}")
|
||||
else:
|
||||
for path in removed:
|
||||
print(f"history_removed={path}")
|
||||
main.process(source, output_dir, settings.lookback_days, store=store, history=history)
|
||||
cell_cache = main.CellDataCache(cache_dir) if cache_dir is not None else None
|
||||
output = main.process(
|
||||
source, output_dir, settings.lookback_days, store=store, history=history, cell_cache=cell_cache
|
||||
)
|
||||
if output is not None and not dry_run:
|
||||
prune_history(storage, settings)
|
||||
finally:
|
||||
close_quietly(storage)
|
||||
return 0
|
||||
|
||||
|
||||
def prune_history(storage: main.FileStorage, settings: Settings) -> None:
|
||||
"""Apply history retention after a new group was stored. The data is already saved, so a failure is only reported."""
|
||||
if settings.history_keep_days <= 0:
|
||||
return
|
||||
try:
|
||||
removed = main.StorageHistoryStore(storage, settings.history_root).prune(settings.history_keep_days)
|
||||
except Exception as exc:
|
||||
print(f"history_prune_error={type(exc).__name__}: {exc}")
|
||||
return
|
||||
for path in removed:
|
||||
print(f"history_removed={path}")
|
||||
|
||||
|
||||
def entry(argv: list[str] | None = None) -> int:
|
||||
parser = argparse.ArgumentParser(description="Run one InterferenceETL pass with the saved app settings")
|
||||
parser.add_argument("--settings", type=Path, required=True)
|
||||
parser.add_argument("--output", type=Path, required=True)
|
||||
parser.add_argument("--cache", type=Path, help="directory for parsed CellData workbooks")
|
||||
parser.add_argument("--dry-run", action="store_true")
|
||||
args = parser.parse_args(argv)
|
||||
try:
|
||||
return run(args.settings, args.output, args.dry_run)
|
||||
return run(args.settings, args.output, args.dry_run, args.cache)
|
||||
except main.ProcessingError as exc:
|
||||
print(f"error={exc}", file=sys.stderr, flush=True)
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user