2019-02-07 13:54:45 +01:00
|
|
|
from pathlib import Path
|
|
|
|
import re
|
2018-11-19 18:32:16 +01:00
|
|
|
import shlex
|
|
|
|
import subprocess
|
2020-07-15 18:50:14 +02:00
|
|
|
import threading
|
|
|
|
import queue
|
|
|
|
import sys
|
2018-11-19 18:32:16 +01:00
|
|
|
|
|
|
|
|
2021-03-07 19:29:02 +01:00
|
|
|
to_p = Path("svg2png")
|
2019-02-07 13:54:45 +01:00
|
|
|
to_p.mkdir(exist_ok=True)
|
2018-11-19 18:32:16 +01:00
|
|
|
|
2021-03-07 19:29:02 +01:00
|
|
|
images = [
|
|
|
|
f
|
|
|
|
for f in Path("_build/html/_images/").glob("*.svg")
|
|
|
|
if not re.match(r"^seg[0-9A-F]{2}$", f.stem)
|
|
|
|
]
|
2020-07-15 18:50:14 +02:00
|
|
|
q = queue.Queue()
|
2018-11-19 18:32:16 +01:00
|
|
|
|
2020-07-15 18:50:14 +02:00
|
|
|
|
|
|
|
def worker():
|
|
|
|
while True:
|
|
|
|
item = q.get()
|
|
|
|
if item is None:
|
|
|
|
break
|
|
|
|
|
2021-03-07 19:29:02 +01:00
|
|
|
to = to_p / item.with_suffix(".png").name
|
2021-11-16 03:19:33 +01:00
|
|
|
if to.is_file():
|
|
|
|
q.task_done()
|
|
|
|
continue
|
2021-03-07 19:29:02 +01:00
|
|
|
args = [
|
|
|
|
"inkscape",
|
2021-11-16 03:19:33 +01:00
|
|
|
f"--export-filename={to.absolute()}",
|
2021-03-07 19:29:02 +01:00
|
|
|
"-w",
|
|
|
|
"800",
|
2021-11-16 03:19:33 +01:00
|
|
|
"--export-background=white",
|
2021-03-07 19:29:02 +01:00
|
|
|
str(item.absolute()),
|
|
|
|
]
|
|
|
|
print("Running: {}".format(" ".join(shlex.quote(x) for x in args)))
|
2021-11-16 03:19:33 +01:00
|
|
|
subprocess.check_call(args)
|
2020-07-15 18:50:14 +02:00
|
|
|
|
|
|
|
q.task_done()
|
|
|
|
|
2021-03-07 19:29:02 +01:00
|
|
|
|
2020-07-15 18:50:14 +02:00
|
|
|
NUM_THREADS = 8
|
|
|
|
threads = []
|
|
|
|
for i in range(NUM_THREADS):
|
|
|
|
t = threading.Thread(target=worker)
|
|
|
|
t.start()
|
|
|
|
threads.append(t)
|
|
|
|
|
|
|
|
for img in sorted(images):
|
|
|
|
q.put(img)
|
|
|
|
|
|
|
|
q.join()
|
|
|
|
|
|
|
|
for i in range(NUM_THREADS):
|
|
|
|
q.put(None)
|
|
|
|
for t in threads:
|
|
|
|
t.join()
|