Resolve which DB file to use based on the lock path. - Paths under ~/.fastled/ or ~/.platformio/ -> ~/.fastled/locks.db - Everything else -> /.cache/locks.db Env override: FASTLED_LOCK_DB_PATH (for test isolation) Args: lock_path: Optional path hint for choos
(lock_path: Path | None = None)
| 413 | |
| 414 | |
| 415 | def get_lock_database(lock_path: Path | None = None) -> LockDatabase: |
| 416 | """Resolve which DB file to use based on the lock path. |
| 417 | |
| 418 | - Paths under ~/.fastled/ or ~/.platformio/ -> ~/.fastled/locks.db |
| 419 | - Everything else -> <project_root>/.cache/locks.db |
| 420 | |
| 421 | Env override: FASTLED_LOCK_DB_PATH (for test isolation) |
| 422 | |
| 423 | Args: |
| 424 | lock_path: Optional path hint for choosing DB location |
| 425 | |
| 426 | Returns: |
| 427 | LockDatabase instance (cached per DB path) |
| 428 | """ |
| 429 | # Check env override first |
| 430 | env_path = os.environ.get("FASTLED_LOCK_DB_PATH") |
| 431 | if env_path: |
| 432 | db_path_str = env_path |
| 433 | else: |
| 434 | home = Path.home() |
| 435 | fastled_dir = home / ".fastled" |
| 436 | platformio_dir = home / ".platformio" |
| 437 | |
| 438 | use_global = False |
| 439 | if lock_path is not None: |
| 440 | try: |
| 441 | lock_str = str(lock_path.resolve()) |
| 442 | if str(fastled_dir) in lock_str or str(platformio_dir) in lock_str: |
| 443 | use_global = True |
| 444 | except (OSError, ValueError): |
| 445 | pass |
| 446 | |
| 447 | if use_global: |
| 448 | db_path = fastled_dir / "locks.db" |
| 449 | else: |
| 450 | project_root = Path(__file__).parent.parent.parent |
| 451 | db_path = project_root / ".cache" / "locks.db" |
| 452 | |
| 453 | db_path_str = str(db_path) |
| 454 | |
| 455 | if db_path_str not in _db_cache: |
| 456 | _db_cache[db_path_str] = LockDatabase(Path(db_path_str)) |
| 457 | |
| 458 | return _db_cache[db_path_str] |