From 9e3046e5444e9b2cecdfbfbe02d5de70d220c412 Mon Sep 17 00:00:00 2001 From: Stefan Riesenberger Date: Wed, 5 Jan 2022 13:49:19 +0100 Subject: [PATCH] [misc] implement subfolder handling for python tool --- gen_png.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/gen_png.py b/gen_png.py index 368c02b..33cb6f1 100755 --- a/gen_png.py +++ b/gen_png.py @@ -24,8 +24,15 @@ def raster_graphics(files): print('\n------------------------------\n'+ str(frogs) + ' remaining...\nRastering ' + str(name)+'\n') frogs = frogs - 1 for s in sizes: - subprocess.run(["inkscape", f, "-C", "-w", str(s), "--export-filename=./png/fixed_width/"+str(s)+"/"+name+".png"],timeout=30) - subprocess.run(["inkscape", f, "-C", "-h", str(s), "--export-filename=./png/fixed_height/"+str(s)+"/"+name+".png"],timeout=30) + # make sure the subdirectories exist + width_path = "./png/fixed_width/"+str(s)+"/"+str(os.path.dirname(f.removeprefix('svg/').removesuffix('.svg'))) + height_path = "./png/fixed_height/"+str(s)+"/"+str(os.path.dirname(f.removeprefix('svg/').removesuffix('.svg'))) + if not( os.path.exists(width_path) and os.path.exists(height_path) ): + os.makedirs(width_path ,exist_ok=True) + os.makedirs(height_path ,exist_ok=True) + # invoke Inkscape to raster the given vector graphics + subprocess.run(["inkscape", f, "-C", "-w", str(s), "--export-filename="+str(width_path)+"/"+name+".png"],timeout=30) + subprocess.run(["inkscape", f, "-C", "-h", str(s), "--export-filename="+str(height_path)+"/"+name+".png"],timeout=30) # git add given files def git_add_raster(files): @@ -92,10 +99,11 @@ if len(sys.argv) == 1: create_tag() else: if sys.argv[1] == 'all': - files = [f for f in glob.glob("./svg**/*.svg", recursive=True)] + files = [f for f in glob.glob("svg**/*.svg", recursive=True)] else: for f in sys.argv: - if os.path.exists("./svg/"+f+".svg"): - files.append("./svg/"+f+".svg") + f = f.removeprefix('svg/').removesuffix('.svg') + if os.path.exists("svg/"+f+".svg"): + files.append("svg/"+f+".svg") raster_graphics(files)