Skip to content

Instantly share code, notes, and snippets.

@Harduim
Last active January 14, 2022 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Harduim/f0db6bfcb297898ab91afe927467f00b to your computer and use it in GitHub Desktop.
Save Harduim/f0db6bfcb297898ab91afe927467f00b to your computer and use it in GitHub Desktop.
Prepare PatternFly Design-Kit SVGs to Lucidchart
"""
The PatternFly design-kit symbols are organized is a deep nested folder structure.
In order to create a custom Lucidchart shapes library, one must have all SVG files in a single directory.
This script copies all SVGs to a new folder called "svg" appending the original path to the new filename.
PatternFly design-kit => https://github.com/patternfly/patternfly-design-kit
Linux and Mac only.
"""
import os
import re
from glob import glob
from os.path import basename, exists, isdir, join
from shutil import copyfile
ROOT_FOLDER = "Symbols-SVGs"
DEST_FOLDER = "svgs"
PATTERN = r"(Symbols-SVGs/)|(\d+.?\s)|(?<=\w)(\s)(?=\w)|(\s-\s)|\s"
if not exists(DEST_FOLDER):
os.mkdir(DEST_FOLDER)
for origin_name in glob(join(ROOT_FOLDER, "**"), recursive=True):
if isdir(origin_name):
continue
clear_name = re.sub(PATTERN, "", origin_name).strip()
if basename(clear_name) == clear_name:
copyfile(origin_name, join(DEST_FOLDER, clear_name))
continue
category = clear_name.split("/")[0]
categ_folder = join(DEST_FOLDER, category)
if not exists(categ_folder):
os.mkdir(categ_folder)
dest_name = " ".join(clear_name.split("/")[1:])
copyfile(origin_name, join(categ_folder, dest_name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment