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,51 +51,56 @@ 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:
|
)
|
||||||
try:
|
tmpsvg.close()
|
||||||
log.info(
|
try:
|
||||||
"Exporting to {} using inkscape" \
|
log.info(
|
||||||
.format(outfilename.suffix),
|
"Exporting to {} using inkscape" \
|
||||||
|
.format(outfilename.suffix),
|
||||||
|
)
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
jj2_tpl.stream(context).dump( tmpsvg.name )
|
||||||
|
|
||||||
|
inkscape_process = subprocess.Popen(
|
||||||
|
[
|
||||||
|
"inkscape",
|
||||||
|
tmpsvg.name,
|
||||||
|
"--export-filename",
|
||||||
|
str(outfilename),
|
||||||
|
],
|
||||||
|
stdout = subprocess.PIPE,
|
||||||
|
stderr = subprocess.STDOUT,
|
||||||
|
universal_newlines = True,
|
||||||
|
)
|
||||||
|
|
||||||
|
for line_out in iter(inkscape_process.stdout.readline, ""):
|
||||||
|
log.debug(line_out)
|
||||||
|
|
||||||
|
inkscape_process.stdout.close()
|
||||||
|
|
||||||
|
rv = inkscape_process.wait()
|
||||||
|
|
||||||
|
if rv != 0:
|
||||||
|
raise Exception(
|
||||||
|
"Bad inkscape return code '{}'" \
|
||||||
|
.format(inkscape_process.returncode)
|
||||||
)
|
)
|
||||||
import subprocess
|
|
||||||
|
|
||||||
jj2_tpl.stream(context).dump( tmpsvg )
|
|
||||||
|
|
||||||
inkscape_process = subprocess.Popen(
|
|
||||||
[
|
|
||||||
"inkscape",
|
|
||||||
tmpsvg.name,
|
|
||||||
"--export-filename",
|
|
||||||
str(outfilename),
|
|
||||||
],
|
|
||||||
stdout = subprocess.PIPE,
|
|
||||||
stderr = subprocess.STDOUT,
|
|
||||||
universal_newlines = True,
|
|
||||||
)
|
|
||||||
|
|
||||||
for line_out in iter(inkscape_process.stdout.readline, ""):
|
|
||||||
log.debug(line_out)
|
|
||||||
|
|
||||||
inkscape_process.stdout.close()
|
|
||||||
|
|
||||||
rv = inkscape_process.wait()
|
|
||||||
|
|
||||||
if rv != 0:
|
|
||||||
raise Exception(
|
|
||||||
"Bad inkscape return code '{}'" \
|
|
||||||
.format(inkscape_process.returncode)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
return outfilename
|
return outfilename
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
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
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue