Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions devstats/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import requests

from .query import GithubGrabber
from .publish import publisher
from .publish import publish


@click.group()
Expand Down Expand Up @@ -62,8 +62,4 @@ def query(repo_owner, repo_name):
data.dump(f"{repo_name}_{ftype.get(qtype, qtype)}.json")


@cli.command("publish")
@click.argument("project")
def publish(project):
"""Generate myst report for `repo_owner`/`repo_name`."""
publisher(project)
cli.add_command(publish)
27 changes: 21 additions & 6 deletions devstats/publish.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import os
import sys
from glob import glob
import click


def publisher(project):
os.makedirs("_generated", exist_ok=True)
@click.command()
@click.argument("project")
@click.option(
"-o", "--outdir", default="build", help="Output directory", show_default=True
)
def publish(project, outdir):
"""Generate myst report for `repo_owner`/`repo_name`."""
os.makedirs(outdir, exist_ok=True)
os.makedirs(os.path.join(outdir, project), exist_ok=True)

report_files = glob(os.path.join(os.path.dirname(__file__), "reports/*.md"))

variables = {"project": project}

print(f"Generating [{project}] report in [{outdir}]...", end="", flush=True)

for report in report_files:
print(f"Generating {project} report...", end="")
with open(report) as fh:
template = fh.read()
with open(f"_generated/{project}.md", "w") as fh:
fh.write(template.replace("{{ project }}", project))
print("OK")
with open(f"{outdir}/{project}/{os.path.basename(report)}", "w") as fh:
for v in variables:
template = template.replace("{{ " + v + " }}", variables[v])
fh.write(template)

print("OK")
Loading