From 5d96de132a222bb669fb154d1d56a5911666fb08 Mon Sep 17 00:00:00 2001 From: Alexandre Courbot Date: Fri, 6 Nov 2009 08:43:23 +0900 Subject: [PATCH] harmonize-svg now accepts command-line arguments to avoid processing the entire set --- harmonize-svg.py | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/harmonize-svg.py b/harmonize-svg.py index 0c1772276..b62e2a20f 100755 --- a/harmonize-svg.py +++ b/harmonize-svg.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . from xml.etree.ElementTree import XMLID, tostring -import re, codecs, os, string, kanjivg, os.path +import re, codecs, os, string, kanjivg, os.path, sys def findText(elt): if elt.text: return elt.text @@ -79,14 +79,25 @@ class TemplateParser(Parser): strs.append('' % (d,)) return "\n\t\t".join(strs) -for f in os.listdir("SVG"): - if not f.endswith(".svg"): continue - if f[4] in "0123456789abcdef": - kanji = kanjivg.realchr(int(f[:5], 16)) - else: kanji = kanjivg.realchr(int(f[:4], 16)) +if __name__ == "__main__": + # Only process files given as argument... + if len(sys.argv) > 1: + filesToProceed = sys.argv[1:] + # Or do the whole SVG set if no argument is given + else: + filesToProceed = [] + for f in os.listdir("SVG"): + if not f.endswith(".svg"): continue + filesToProceed.append(os.path.join("SVG", f)) - document, groups = XMLID(open(os.path.join("SVG", f)).read()) - tpp = TemplateParser(open("template.svg").read(), kanji, document, groups) - tpp.parse() - out = codecs.open(os.path.join("SVG", f), "w", "utf-8") - out.write(tpp.content) + for f in filesToProceed: + fname = f.split(os.path.sep)[-1] + if fname[4] in "0123456789abcdef": + kanji = kanjivg.realchr(int(fname[:5], 16)) + else: kanji = kanjivg.realchr(int(fname[:4], 16)) + + document, groups = XMLID(open(f).read()) + tpp = TemplateParser(open("template.svg").read(), kanji, document, groups) + tpp.parse() + out = codecs.open(f, "w", "utf-8") + out.write(tpp.content)