Fix export issue

PNG came out wrong because of concurrency (?) issues where the SVG file
was converted before being fully generated. The solution was to close
the temporary file between each operation.
master
Lertsenem 2020-09-02 09:09:35 +02:00
parent 4c6408bd61
commit f35d467a40
1 changed files with 43 additions and 38 deletions

View File

@ -51,11 +51,13 @@ def generate_outfile(
cachedir.mkdir(parents=True, exist_ok=True)
with tempfile.NamedTemporaryFile(
tmpsvg = tempfile.NamedTemporaryFile(
suffix=".svg",
mode = "w",
delete = False,
dir = str(cachedir),
) as tmpsvg:
)
tmpsvg.close()
try:
log.info(
"Exporting to {} using inkscape" \
@ -63,7 +65,7 @@ def generate_outfile(
)
import subprocess
jj2_tpl.stream(context).dump( tmpsvg )
jj2_tpl.stream(context).dump( tmpsvg.name )
inkscape_process = subprocess.Popen(
[
@ -97,6 +99,9 @@ def generate_outfile(
log.warning("Failed to export with inkscape")
log.debug(e, exc_info=True)
finally:
os.unlink(tmpsvg.name)
# To png, pdf or ps with cairosvg
# -------------------------------------------------------------------------
if outfilename.suffix in [ ".png", ".pdf", ".ps" ]: