From c6999ec19fdc00f29f5adcd37cb1e5e6b681a087 Mon Sep 17 00:00:00 2001
From: prndev <prndev@users.noreply.github.com>
Date: Fri, 27 Apr 2018 22:14:16 +0200
Subject: [PATCH] Automated vector art clothing suffix name aligner ready.

---
 artTools/align_suffixes.py | 35 +++++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 10 deletions(-)

diff --git a/artTools/align_suffixes.py b/artTools/align_suffixes.py
index 5709ae95cb8..1c4822e8948 100644
--- a/artTools/align_suffixes.py
+++ b/artTools/align_suffixes.py
@@ -3,14 +3,29 @@
 import sys
 import re
 
-svg = open(sys.argv[1]).read()
-outfits = re.findall('(?<=")[^"]*Outfit_[^"]+', svg)
-outfits = set(outfits)
-#re_suffix = re.compile('(?<=Outfit_).+')
-re_suffix = re.compile('(?<=Outfit_)[^_]+')
-mapping = {o : re_suffix.search(o).group(0) for o in outfits}
+def get(filename_svg):
+    svg = open(filename_svg).read()
+    outfits = re.findall('(?<=")[^"]*Outfit_[^"]+', svg)
+    outfits = set(outfits)
+    #re_suffix = re.compile('(?<=Outfit_).+')
+    re_suffix = re.compile('(?<=Outfit_)[^_]+')
+    mapping = {o : re_suffix.search(o).group(0) for o in outfits}
+    suffixes = set(mapping.values())
+    for v in sorted(suffixes):
+        print(v)
+    
+def apply(filename_svg, filename_csv):
+    pairs = [ tuple(l.strip().split(';')) for l in open(filename_csv).readlines() ]
+    pairs = [ p for p in pairs if p[0] and p[1] and p[0] != p[1] ]
+    pairs = [ ('_'+p[0],'_'+p[1]) for p in pairs ]
+    with open(filename_svg) as f:
+      svg = f.read()
+      for p in pairs:
+          svg = svg.replace(*p)
+    open(filename_svg,'w').write(svg)
 
-suffixes = set(mapping.values())
-
-for v in sorted(suffixes):
-  print(v)
+if __name__ == '__main__':
+    if (len(sys.argv) == 2):
+        get(sys.argv[1])
+    elif (len(sys.argv) == 3):
+        apply(sys.argv[1], sys.argv[2])
-- 
GitLab