setting up slop app
This commit is contained in:
54
aggregate.py
54
aggregate.py
@@ -24,7 +24,6 @@ def is_absolute_with_drive(entry: str) -> bool:
|
||||
def resolve_paths(base_dir: Path, entry: str) -> list[Path]:
|
||||
has_drive = is_absolute_with_drive(entry)
|
||||
is_wildcard = "*" in entry
|
||||
|
||||
if is_wildcard:
|
||||
root = Path(entry) if has_drive else base_dir / entry
|
||||
matches = [Path(p) for p in glob.glob(str(root), recursive=True) if Path(p).is_file()]
|
||||
@@ -34,7 +33,13 @@ def resolve_paths(base_dir: Path, entry: str) -> list[Path]:
|
||||
return [Path(entry)]
|
||||
return [(base_dir / entry).resolve()]
|
||||
|
||||
def build_markdown(base_dir: Path, files: list[str]) -> str:
|
||||
def build_discussion_section(history: list[str]) -> str:
|
||||
sections = []
|
||||
for i, paste in enumerate(history, start=1):
|
||||
sections.append(f"### Discussion Excerpt {i}\n\n{paste.strip()}")
|
||||
return "\n\n---\n\n".join(sections)
|
||||
|
||||
def build_files_section(base_dir: Path, files: list[str]) -> str:
|
||||
sections = []
|
||||
for entry in files:
|
||||
paths = resolve_paths(base_dir, entry)
|
||||
@@ -50,27 +55,56 @@ def build_markdown(base_dir: Path, files: list[str]) -> str:
|
||||
content = f"ERROR: file not found: {path}"
|
||||
except Exception as e:
|
||||
content = f"ERROR: {e}"
|
||||
original = entry if not ("*" in entry) else str(path)
|
||||
original = entry if "*" not in entry else str(path)
|
||||
sections.append(f"### `{original}`\n\n```{lang}\n{content}\n```")
|
||||
return "\n\n---\n\n".join(sections)
|
||||
|
||||
def main():
|
||||
config_path = Path("config.toml")
|
||||
with config_path.open("rb") as f:
|
||||
config = tomllib.load(f)
|
||||
def build_screenshots_section(base_dir: Path, screenshots: list[str]) -> str:
|
||||
sections = []
|
||||
for entry in screenshots:
|
||||
paths = resolve_paths(base_dir, entry)
|
||||
if not paths:
|
||||
sections.append(f"### `{entry}`\n\n_ERROR: no files matched: {entry}_")
|
||||
continue
|
||||
for path in paths:
|
||||
original = entry if "*" not in entry else str(path)
|
||||
if not path.exists():
|
||||
sections.append(f"### `{original}`\n\n_ERROR: file not found: {path}_")
|
||||
continue
|
||||
sections.append(f"### `{original}`\n\n})")
|
||||
return "\n\n---\n\n".join(sections)
|
||||
|
||||
def build_markdown(base_dir: Path, files: list[str], screenshot_base_dir: Path, screenshots: list[str], history: list[str]) -> str:
|
||||
parts = []
|
||||
if history:
|
||||
parts.append("## Discussion History\n\n" + build_discussion_section(history))
|
||||
if files:
|
||||
parts.append("## Files\n\n" + build_files_section(base_dir, files))
|
||||
if screenshots:
|
||||
parts.append("## Screenshots\n\n" + build_screenshots_section(screenshot_base_dir, screenshots))
|
||||
return "\n\n---\n\n".join(parts)
|
||||
|
||||
def run(config: dict) -> tuple[str, Path]:
|
||||
namespace = config["output"]["namespace"]
|
||||
output_dir = Path(config["output"]["output_dir"])
|
||||
base_dir = Path(config["files"]["base_dir"])
|
||||
files = config["files"].get("paths", [])
|
||||
screenshot_base_dir = Path(config.get("screenshots", {}).get("base_dir", "."))
|
||||
screenshots = config.get("screenshots", {}).get("paths", [])
|
||||
history = config.get("discussion", {}).get("history", [])
|
||||
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
increment = find_next_increment(output_dir, namespace)
|
||||
output_file = output_dir / f"{namespace}_{increment:03d}.md"
|
||||
|
||||
markdown = build_markdown(base_dir, files)
|
||||
markdown = build_markdown(base_dir, files, screenshot_base_dir, screenshots, history)
|
||||
output_file.write_text(markdown, encoding="utf-8")
|
||||
return markdown, output_file
|
||||
|
||||
def main():
|
||||
with open("config.toml", "rb") as f:
|
||||
import tomllib
|
||||
config = tomllib.load(f)
|
||||
markdown, output_file = run(config)
|
||||
print(f"Written: {output_file}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user