from functools import cache from pathlib import Path from database.connect import BACKEND_DIR class EquipmentRegistry: def __init__(self, equipment_cls): self.equipment_cls = equipment_cls @cache def get(self, version: str = '0'): normalized = version or '0' if not self._version_exists(normalized): if normalized == '0': return self.equipment_cls(normalized) return self.get('0') return self.equipment_cls(normalized) def _version_exists(self, version: str) -> bool: db_path = Path(BACKEND_DIR) / 'dataFiles' / f'dcalc_{version}.db' return db_path.exists()