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