Closed justmars closed 1 year ago
See former implementation:
...
def get_path(self, path: Path) -> Path | None:
target = path / self.statute_category / self.statute_serial_id
if target.exists():
return target
return None
def get_paths(self, path: Path) -> list[Path]:
"""The serial id isn't enough since the variant of a `StatuteRow.id` includes a `-<digit>` where the digit is the variant."""
targets = []
target = path / self.statute_category
paths = target.glob(f"{self.statute_serial_id}-*/details.yaml")
for variant_path in paths:
if variant_path.exists():
targets.append(variant_path.parent)
return targets
def extract_folders(self, statute_path: Path) -> Iterator[Path]:
"""Using the `category` and `id` of the object, get the possible folder paths."""
if folder := self.get_path(statute_path):
yield folder
else:
if folders := self.get_paths(statute_path):
yield from folders
else:
logger.error(f"No statute path/s detected for {self=}")
def units_path(self, folder: Path) -> Path | None:
"""There are two kinds of unit files: the preferred / customized
variant and the one scraped (the default in the absence of a preferred
variant)."""
text = f"{self.statute_category}{self.statute_serial_id}.yaml"
preferred = folder / text
if preferred.exists():
return preferred
default = folder / "units.yaml"
if default.exists():
return default
return None