From 75e834d8ab497a18e4e066c1084fd0e3077a10a3 Mon Sep 17 00:00:00 2001 From: Dana Lambert Date: Mon, 6 Dec 2021 10:27:35 +1300 Subject: [PATCH] Add helper svg processing script - Removes colons from inkcape svg export property names --- dev | 4 ++++ process_svg.py | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 process_svg.py diff --git a/dev b/dev index dc76aaa..2207222 100755 --- a/dev +++ b/dev @@ -133,6 +133,10 @@ cmd_renew_certifcate() { cmd_start_production } +cmd_process_svg_files() { + docker run -v $PWD/frontend/src/assets/:/app/assets -v $PWD/process_svg.py:/app/process_svg.py -w /app python:3.8-slim-bullseye python process_svg.py +} + # Run the command cmd="$1" "cmd_$cmd" "$@" diff --git a/process_svg.py b/process_svg.py new file mode 100644 index 0000000..8a33377 --- /dev/null +++ b/process_svg.py @@ -0,0 +1,24 @@ +import os + +find_and_replace_mappings = { + "inkscape:": "inkscape", + "rdf:": "rdf", + "dc:": "dc", + "cc:": "cc", + "xmlns:": "xmlns", + "sodipodi:": "sodipodi" +} + +SVG_PATH = "./assets/img/habitatSVG/" + +for filename in os.listdir(SVG_PATH): + if filename.endswith(".svg"): + print(f"Processing {filename}") + with open (f"{SVG_PATH}{filename}", "r") as myfile: + data=myfile.read() + + for find_val, replace_val in find_and_replace_mappings.items(): + data = data.replace(find_val, replace_val) + + with open (f"{SVG_PATH}{filename}", "w") as myfile: + myfile.write(data)