|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import csv |
| 3 | +import json |
| 4 | +import subprocess |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | +REPOS = { |
| 8 | + "cpg": "comp-physics", |
| 9 | + "mfc": "mflowcode", |
| 10 | + "imr": "InertialMicrocavitationRheometry", |
| 11 | +} |
| 12 | + |
| 13 | +IGNORE_NAMES = { |
| 14 | + ".github", |
| 15 | + "comp-physics.github.io", |
| 16 | + "MFlowCode.github.io", |
| 17 | + "benchmark", |
| 18 | + "stats", |
| 19 | +} |
| 20 | + |
| 21 | +FIELDNAMES = ["name", "description", "url"] |
| 22 | + |
| 23 | + |
| 24 | +def run(cmd): |
| 25 | + subprocess.run(cmd, check=True) |
| 26 | + |
| 27 | + |
| 28 | +def capture_json(cmd): |
| 29 | + result = subprocess.run(cmd, check=True, capture_output=True, text=True) |
| 30 | + return json.loads(result.stdout) |
| 31 | + |
| 32 | + |
| 33 | +def escape_latex(value): |
| 34 | + if value is None: |
| 35 | + return "" |
| 36 | + s = str(value) |
| 37 | + s = s.replace("_", r"\_") |
| 38 | + s = s.replace("@", "at") |
| 39 | + return s |
| 40 | + |
| 41 | + |
| 42 | +def write_csv_atomic(path: Path, rows, fieldnames): |
| 43 | + tmp_path = path.with_suffix(path.suffix + ".tmp") |
| 44 | + with tmp_path.open("w", newline="", encoding="utf-8") as f: |
| 45 | + writer = csv.DictWriter(f, fieldnames=fieldnames) |
| 46 | + writer.writeheader() |
| 47 | + for row in rows: |
| 48 | + writer.writerow(row) |
| 49 | + tmp_path.replace(path) |
| 50 | + |
| 51 | + |
| 52 | +def fetch_repos(org_name): |
| 53 | + return capture_json([ |
| 54 | + "gh", "repo", "list", org_name, |
| 55 | + "--visibility", "public", |
| 56 | + "--source", |
| 57 | + "--json", "name,description,url", |
| 58 | + ]) |
| 59 | + |
| 60 | + |
| 61 | +def build_csv_rows(repos): |
| 62 | + repos = [repo for repo in repos if repo.get("name") not in IGNORE_NAMES] |
| 63 | + return [ |
| 64 | + {key: escape_latex(repo.get(key, "")) for key in FIELDNAMES} |
| 65 | + for repo in repos |
| 66 | + ] |
| 67 | + |
| 68 | + |
| 69 | +def csv_paths(): |
| 70 | + return [Path(f"github-{group}.csv") for group in REPOS] |
| 71 | + |
| 72 | + |
| 73 | +def remove_csv_outputs(): |
| 74 | + for path in csv_paths(): |
| 75 | + path.unlink(missing_ok=True) |
| 76 | + |
| 77 | + |
| 78 | +def main(): |
| 79 | + remove_csv_outputs() |
| 80 | + |
| 81 | + try: |
| 82 | + for group, org in REPOS.items(): |
| 83 | + repos = fetch_repos(org) |
| 84 | + rows = build_csv_rows(repos) |
| 85 | + write_csv_atomic(Path(f"github-{group}.csv"), rows, FIELDNAMES) |
| 86 | + |
| 87 | + run(["latexmk", "-c", "cv.tex"]) |
| 88 | + run(["latexmk", "-pdf", "cv.tex"]) |
| 89 | + finally: |
| 90 | + remove_csv_outputs() |
| 91 | + |
| 92 | + |
| 93 | +if __name__ == "__main__": |
| 94 | + main() |
0 commit comments