def _ensure_expected_dirs(expected_dirs: list[PathStr]) -> None:
"""Ensure existance of expected_dirs _as_ directories."""
for dir_name in expected_dirs:
- if not path_exists(dir_name):
+ if not isdir(dir_name):
+ if path_exists(dir_name):
+ raise CantWriteException('at expected directory path '
+ f'{dir_name} found non-directory')
print(f'creating expected directory: {dir_name}')
makedirs(dir_name)
- elif not isdir(dir_name):
- msg = f'at expected directory path {dir_name} found non-directory'
- raise CantWriteException(msg)
class DatabaseConnection:
def __init__(self, path: PathStr = PATH_DB) -> None:
self._path = path
- if not path_exists(self._path):
+ if not isfile(self._path):
+ if path_exists(self._path):
+ raise CantWriteException(f'no DB at {self._path}; would create'
+ ', but something\'s already there?')
with sql_connect(self._path) as conn:
conn.executescript(SCRIPT_INIT_DB)
self._conn = sql_connect(self._path)