Commit 1dedfbb8 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update view/lists/index.odt to make it more robust

parent cc33b7b2
......@@ -5,21 +5,15 @@
import os
from subprocess import call, check_output
from subprocess import run, PIPE, STDOUT
from uuid import uuid4
#
# go to the /tmp directory
#
cwd = os.getcwd()
os.chdir('/tmp')
#
# file names
#
froot = str(uuid4())
fhtml = '%s.html' % froot
fodt = '%s.odt' % froot
fhtml = f"/tmp/{froot}.html"
fodt = f"/tmp/{froot}.odt"
#
# create the HTML file in /tmp
......@@ -41,8 +35,13 @@
#
try:
cmd = "export HOME=/tmp && libreoffice --headless --convert-to odt %s"
sout = check_output(cmd % fhtml, shell=True)
cmd = ["libreoffice",
"--headless",
"--convert-to", "odt",
"--outdir", "/tmp",
fhtml]
proc = run(cmd, stdout=PIPE, stderr=STDOUT)
if os.path.exists(fodt):
fi = open(fodt, 'rb')
......@@ -51,13 +50,12 @@
else:
msg = T("The generation of the ODT file failed:<br><br>")
msg += sout
msg += proc.stdout.decode()
raise HTTP(500, msg)
pass
finally:
call(["rm", "-f", "/tmp/%s.*" % froot])
os.chdir(cwd)
run(["rm", "-f", f"/tmp/{froot}.*"])
pass
#
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment