feat: config module with TOML loading

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-04-21 15:05:55 +08:00
parent f0ea821d49
commit 3239fd1032
2 changed files with 83 additions and 0 deletions

41
src/order_bak/config.py Normal file
View File

@@ -0,0 +1,41 @@
import sys
import tomllib
from dataclasses import dataclass
from pathlib import Path
@dataclass
class Config:
azure_connection_string: str
scan_page_size: int = 500
scan_delay_ms: int = 200
scan_dir: Path = Path("./scan")
delete_batch_size: int = 100
delete_delay_ms: int = 300
def load_config(config_path: Path) -> Config:
if not config_path.exists():
print(f"Config file not found: {config_path}")
sys.exit(1)
with open(config_path, "rb") as f:
raw = tomllib.load(f)
azure = raw.get("azure", {})
connection_string = azure.get("connection_string")
if not connection_string:
print("Missing azure.connection_string in config")
sys.exit(1)
scan = raw.get("scan", {})
delete = raw.get("delete", {})
return Config(
azure_connection_string=connection_string,
scan_page_size=scan.get("page_size", 500),
scan_delay_ms=scan.get("delay_ms", 200),
scan_dir=Path(scan.get("scan_dir", "./scan")),
delete_batch_size=delete.get("batch_size", 100),
delete_delay_ms=delete.get("delay_ms", 300),
)