27 lines
1.2 KiB
Python
27 lines
1.2 KiB
Python
import pathlib
|
|
|
|
from failure import Failure
|
|
from record_store.stores import goals_store
|
|
from project_config.main import located
|
|
from plan.goals_file import section
|
|
|
|
|
|
def read_premises(root: str, home: pathlib.Path) -> str | Failure:
|
|
"""Where the goals file is kept, then its ## Goals and ## Audience. The goals file is the one that the config of root's checkout, under home, names: a file or a Jira epic's description. A Failure where no config names the checkout, or the goals file cannot be read, is missing or empty, lacks a section, holds one twice or leaves one empty."""
|
|
config = located(root, home)
|
|
if isinstance(config, Failure):
|
|
return Failure(f"{config.reason} - no premises.")
|
|
goals = goals_store(config)
|
|
text = goals.read()
|
|
if isinstance(text, Failure):
|
|
return Failure(f"{text.reason} - no premises.")
|
|
if not text:
|
|
return Failure(f"{goals.label} is missing or empty - no premises.")
|
|
bodies: list[str] = []
|
|
for name in ("Goals", "Audience"):
|
|
body = section(text, name)
|
|
if isinstance(body, Failure):
|
|
return Failure(f"{goals.label} {body.reason} - no premises.")
|
|
bodies.append(body)
|
|
return f"{goals.label}:\n## Goals\n{bodies[0]}\n\n## Audience\n{bodies[1]}"
|