From 3d7964bce6499304f441714ef23bb93d35c10c59 Mon Sep 17 00:00:00 2001 From: Dmitry T Date: Tue, 10 Apr 2018 23:14:09 +0300 Subject: [PATCH 1/3] Fix Windows file write permission issue (fixes #9) --- export_layers.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/export_layers.py b/export_layers.py index 786de21..3f1b785 100644 --- a/export_layers.py +++ b/export_layers.py @@ -2,6 +2,7 @@ import sys sys.path.append('/usr/share/inkscape/extensions') +import contextlib import inkex import os import subprocess @@ -34,15 +35,15 @@ def effect(self): if not os.path.exists(os.path.join(output_path)): os.makedirs(os.path.join(output_path)) - with tempfile.NamedTemporaryFile() as fp_svg: - layer_dest_svg_path = fp_svg.name + with _make_temp_directory() as tmp_dir: + layer_dest_svg_path = os.path.join(tmp_dir, "export.svg") self.export_layers(layer_dest_svg_path, show_layer_ids) if self.options.filetype == "jpeg": - with tempfile.NamedTemporaryFile() as fp_png: - self.exportToPng(layer_dest_svg_path, fp_png.name) - layer_dest_jpg_path = os.path.join(output_path, "%s_%s.jpg" % (str(counter).zfill(3), layer_label)) - self.convertPngToJpg(fp_png.name, layer_dest_jpg_path) + tmp_dest_png_path = os.path.join(tmp_dir, "export.png") + self.exportToPng(layer_dest_svg_path, tmp_dest_png_path) + layer_dest_jpg_path = os.path.join(output_path, "%s_%s.jpg" % (str(counter).zfill(3), layer_label)) + self.convertPngToJpg(tmp_dest_png_path, layer_dest_jpg_path) else: layer_dest_png_path = os.path.join(output_path, "%s_%s.png" % (str(counter).zfill(3), layer_label)) self.exportToPng(layer_dest_svg_path, layer_dest_png_path) @@ -103,6 +104,15 @@ def convertPngToJpg(self, png_path, output_path): p.wait() +@contextlib.contextmanager +def _make_temp_directory(): + temp_dir = tempfile.mkdtemp(prefix="tmp-inkscape") + try: + yield temp_dir + finally: + shutil.rmtree(temp_dir) + + def _main(): e = PNGExport() e.affect() From ff802c12155a0f92bd79fae2209f207784c133e1 Mon Sep 17 00:00:00 2001 From: Dmitry T Date: Wed, 11 Apr 2018 00:32:11 +0300 Subject: [PATCH 2/3] Fix export operation hanging on Windows --- export_layers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/export_layers.py b/export_layers.py index 3f1b785..d6f5d12 100644 --- a/export_layers.py +++ b/export_layers.py @@ -115,8 +115,8 @@ def _make_temp_directory(): def _main(): e = PNGExport() - e.affect() - exit() + e.affect(output=False) + if __name__ == "__main__": _main() From e500307ce55a42618aabb6f1398c71f47148d307 Mon Sep 17 00:00:00 2001 From: Dmitry T Date: Sun, 22 Apr 2018 21:18:37 +0300 Subject: [PATCH 3/3] Fix hanging export on Windows. Fix picture export ("-C" option), issue #12 --- export_layers.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/export_layers.py b/export_layers.py index d6f5d12..5b8eef6 100644 --- a/export_layers.py +++ b/export_layers.py @@ -92,10 +92,17 @@ def get_layers(self, src): return layers def exportToPng(self, svg_path, output_path): - area_param = '-D' if self.options.crop else 'C' - command = "inkscape %s -d %s -e \"%s\" \"%s\"" % (area_param, self.options.dpi, output_path, svg_path) - - p = subprocess.Popen(command.encode("utf-8"), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + command = [ + "inkscape", + "-D" if self.options.crop else "-C", + "-d", str(self.options.dpi), + "-e", output_path.encode("utf-8"), + svg_path.encode("utf-8") + ] + p = subprocess.Popen( + command, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) p.wait() def convertPngToJpg(self, png_path, output_path):