diff options
| author | Lex Neva <github.com@lexneva.name> | 2018-06-13 20:10:22 -0400 |
|---|---|---|
| committer | Lex Neva <github.com@lexneva.name> | 2018-06-15 21:44:52 -0400 |
| commit | 4c46c2eec1fb7cf9e85617030214bcb170b8b533 (patch) | |
| tree | e3f21dfc5627a9a80ea3deb5d3f8322e508661cc /lib/extensions | |
| parent | f9a5e4c03a073d403222f0d5b7810cdaab90145a (diff) | |
fix zip file corruption
Diffstat (limited to 'lib/extensions')
| -rw-r--r-- | lib/extensions/output.py | 4 | ||||
| -rw-r--r-- | lib/extensions/zip.py | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/extensions/output.py b/lib/extensions/output.py index 72bbe37d..924c2d3a 100644 --- a/lib/extensions/output.py +++ b/lib/extensions/output.py @@ -35,12 +35,14 @@ class Output(InkstitchExtension): # in windows, failure to close here will keep the file locked temp_file.close() + # libembroidery likes to debug log things to stdout. No way to disable it. + save_stdout() write_embroidery_file(temp_file.name, stitch_plan, self.document.getroot()) # inkscape will read the file contents from stdout and copy # to the destination file that the user chose with open(temp_file.name) as output_file: - sys.stdout.write(output_file.read()) + sys.real_stdout.write(output_file.read()) # clean up the temp file os.remove(temp_file.name) diff --git a/lib/extensions/zip.py b/lib/extensions/zip.py index a7616536..ca12efdd 100644 --- a/lib/extensions/zip.py +++ b/lib/extensions/zip.py @@ -11,6 +11,7 @@ from ..i18n import _ from ..output import write_embroidery_file from ..stitch_plan import patches_to_stitch_plan from ..svg import render_stitch_plan, PIXELS_PER_MM +from ..utils.io import save_stdout class Zip(InkstitchExtension): @@ -48,12 +49,19 @@ class Zip(InkstitchExtension): files = [] + # libembroidery likes to debug log things to stdout. No way to disable it. + save_stdout() for format in self.formats: if getattr(self.options, format): output_file = os.path.join(path, "%s.%s" % (base_file_name, format)) write_embroidery_file(output_file, stitch_plan, self.document.getroot()) files.append(output_file) + # I'd love to do restore_stderr() here, but if I do, libembroidery's + # stuff still prints out and corrupts the zip! That's because it uses + # C's buffered stdout, so it hasn't actually written anything to the + # real standard output yet. + if not files: self.errormsg(_("No embroidery file formats selected.")) @@ -69,7 +77,7 @@ class Zip(InkstitchExtension): # inkscape will read the file contents from stdout and copy # to the destination file that the user chose with open(temp_file.name) as output_file: - sys.stdout.write(output_file.read()) + sys.real_stdout.write(output_file.read()) os.remove(temp_file.name) for file in files: |
