Commit 34e49256 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Raise an error when the pdf generation failed.

parent 95e55662
......@@ -88,7 +88,7 @@
"Can't delete this record since several publications refer to it.": 'Impossible de détruire cet enregistrement car des publications lui font référence.',
"Can't insert the article.": 'Impossible de créer cet article.',
"Can't insert the harvester.": 'Impossible de créer ce moissonneur.',
"Can't insert the harvester. ": "Impossible de créer ce moissonneur. ",
"Can't insert the harvester. ": 'Impossible de créer ce moissonneur. ',
"Can't insert the report.": 'Impossible de créer ce rapport.',
"Can't insert the talk/proceeding.": 'Impossible de créer cet acte ou présentation.',
"Can't updated a publication marked OK.": "Impossible d'actualiser une publication marquée OK.",
......@@ -633,6 +633,7 @@
'The <i>record id</i> is not well formed.': 'Le <i>record id</i> est mal formé.',
'The category is used twice !': 'La catégorie est utilisée deux fois !',
'The field "%s" is missing ...': 'Le champ "%s" est manquant ...',
'The generation of the PDF file failed.<br>Please, check the LaTeX file.': 'La génération du fichier PDF a échoué.<br>Vérifier le fichier LaTeX...',
'The graph can be rendered as line or stacked chart. The latter is used when the stacked fields are defined. ': 'The graph can be rendered as line or stacked chart. The latter is used when the stacked fields are defined. ',
'The identifier of the record in the invenio store': 'The identifier of the record in the invenio store',
'The institute authors contains the team name?': "Le champ, autheurs du laboratoire, contiens le nom de l'équipe ?",
......
{{
#--------------------------------------------------------------------------
#
# Converte to transform a tex file generate by a view as a pdf file
# Convert latex file into pdf
#
#--------------------------------------------------------------------------
import base64
......@@ -16,8 +16,7 @@
# Get the latex string generate by the latex view
# and remove it from the response object
#
latex = response.body.getvalue()
response.body = cStringIO.StringIO()
slatex = response.body.getvalue()
#
# go to the private directory and create a latex file
......@@ -32,38 +31,45 @@
os.chdir(wd)
pass
fn = str(uuid4())
fi = open('%s.tex' % fn, 'wb')
fi.write(latex)
froot = str(uuid4())
ftex = '%s.tex' % froot
fi = open(ftex, 'wb')
fi.write(slatex)
fi.close()
#
# Launch a subprocess to convert the latex file into pdf
#
cmd = ['pdflatex', '-interaction', 'nonstopmode', '%s.tex' % fn]
cmd = ['pdflatex', '-interaction', 'nonstopmode', ftex]
call(cmd, stdout=TemporaryFile())
#
# copy the pdf into a base64 string
#
fn_pdf = '%s.pdf' % fn
if os.path.exists(fn_pdf):
fi = open(fn_pdf, 'rb')
fpdf = '%s.pdf' % froot
if os.path.exists(fpdf):
fi = open(fpdf, 'rb')
data = fi.read()
fi.close()
else:
data = "\nThe generation of the PDF file failed."
data += "\nPlease, check the LaTeX file."
call("rm -f %s.*" % froot, shell=True)
msg = "The generation of the PDF file failed.<br>"
msg += "Please, check the LaTeX file."
os.chdir(cwd)
raise HTTP(500, T(msg))
pass
s64 = base64.b64encode(data)
#
# cleaning
#
for ext in ('aux', 'log', 'out', 'pdf', 'tex'):
f = '%s.%s' % (fn, ext)
f = '%s.%s' % (froot, ext)
if os.path.exists(f):
os.remove(f)
pass
......@@ -75,5 +81,9 @@
# Prepare the response
#
response.headers['Content-Type']='application/pdf'
response.body = cStringIO.StringIO()
s64 = base64.b64encode(data)
response.write(s64, escape=False)
}}
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