changeset 62:16352bd395fa

Allow to ignore merge errors on files Add a request param ignore_file_errors to allow skipping invalid pdf files during merge.
author Björn Ricks <bjoern.ricks@intevation.de>
date Wed, 12 Nov 2014 14:02:50 +0100
parents d8fc52aceb9c
children 3918c3c69485
files odfcast/convert.py
diffstat 1 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/odfcast/convert.py	Wed Nov 12 12:41:38 2014 +0100
+++ b/odfcast/convert.py	Wed Nov 12 14:02:50 2014 +0100
@@ -198,12 +198,19 @@
         merger = PdfFileMerger()
         ffiles = request.files.getlist('files')
 
-        try:
-            for ffile in ffiles:
+        for ffile in ffiles:
+            try:
                 merger.append(ffile)
+            except Exception, e:
+                log.exception("Error merging file %s" % ffile)
+                if self.is_ignore_file_errors():
+                    continue
+                else:
+                    return MergeErrorResponse(details=str(e))
 
-            outfile = tempfile.NamedTemporaryFile()
+        outfile = tempfile.NamedTemporaryFile()
 
+        try:
             merger.write(outfile)
             merger.close()
             outfile.seek(0)
@@ -214,6 +221,10 @@
         log.debug("PDF documents merged")
         return Response(outfile, mimetype=PDF_MIMETYPE)
 
+    def is_ignore_file_errors(self):
+        return request.args.get("ignore_file_errors", False) or \
+            request.form.get("ignore_file_errors", False)
+
 
 class TemplateView(MethodView):
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)