1
0

more robust and future-proof architecture

This commit is contained in:
Ninjananas
2024-09-03 20:05:42 +02:00
parent 7bdea04111
commit 677906b5a7
18 changed files with 416 additions and 84 deletions

View File

@@ -0,0 +1,60 @@
from typing import *
import os
import subprocess
import re
import sys
OUTPUT_DIR: str = "._graphics"
ID_REGEX: re.Pattern = re.compile("rbk_.*")
def get_all_ids(svg_file_name: str) -> List[str]:
objects: bytes = subprocess.check_output([
"inkscape",
"--query-all",
svg_file_name,
])
return [
obj.split(b",")[0].decode("utf-8")
for obj in
objects.splitlines()
]
def id_filter(svg_id: str) -> bool:
return ID_REGEX.match(svg_id) is not None
def export_objects(svg_file: str, object_ids: Iterable[str]) -> None:
for obj in object_ids:
command = [
"inkscape",
"--export-type=svg",
"--export-plain-svg",
"--vacuum-defs",
"--export-id-only",
"--export-id",
obj,
"-o",
OUTPUT_DIR + "/" + obj[4:],
svg_file,
]
print(f"exporting {obj[4:]}...", end="")
res = subprocess.check_output(command)
if res:
print(f" An error might have occurred:\n{res}")
else:
print(" done")
if __name__ == "__main__":
if not os.path.isdir(OUTPUT_DIR):
os.mkdir(OUTPUT_DIR)
for graphics_file in sys.argv[1:]:
export_objects(
graphics_file,
filter(id_filter, get_all_ids(graphics_file)),
)