From 68ce1505f1e877ffef93993bfd97c12d597341f6 Mon Sep 17 00:00:00 2001 From: jaseg Date: Sun, 26 Jun 2022 17:38:55 +0200 Subject: protoboards: WIP --- export_previews.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 export_previews.py (limited to 'export_previews.py') diff --git a/export_previews.py b/export_previews.py new file mode 100644 index 0000000..68c895e --- /dev/null +++ b/export_previews.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +import multiprocessing as mp +import subprocess +import pathlib + +import click +from tqdm import tqdm + +def process_file(indir, outdir, inpath): + outpath = outdir / inpath.relative_to(indir).with_suffix('.png') + outpath.parent.mkdir(parents=True, exist_ok=True) + subprocess.run(['resvg', '--export-id', 'g-top-copper', '--width', '1000', inpath, outpath], + check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + +@click.command() +@click.argument('indir', type=click.Path(exists=True, file_okay=False, dir_okay=True, path_type=pathlib.Path)) +def export(indir): + jobs = list(indir.glob('svg/**/*.svg')) + with tqdm(total = len(jobs)) as tq: + with mp.Pool() as pool: + results = [ pool.apply_async(process_file, (indir / 'svg', indir / 'png', path), callback=lambda _res: tq.update(1)) for path in jobs ] + results = [ res.get() for res in results ] + +if __name__ == '__main__': + export() -- cgit