When creating from uploaded file (in ms-word for eg.), try libroffice in case abiword fails.
authorgibus
Tue, 22 Oct 2013 15:00:56 +0200
changeset 555 5d79dc4e50a3
parent 554 8e116b8ddbc3
child 557 6005880ca8c7
child 584 9be5aaedfe6a
When creating from uploaded file (in ms-word for eg.), try libroffice in case abiword fails.
src/cm/converters/__init__.py
src/cm/converters/abi_converters.py
--- a/src/cm/converters/__init__.py	Mon Oct 21 16:50:41 2013 +0200
+++ b/src/cm/converters/__init__.py	Tue Oct 22 15:00:56 2013 +0200
@@ -30,9 +30,18 @@
         if USE_ABI:
           from abi_converters import AbiFileConverter
           converter = AbiFileConverter()
-          html_input, attachs = converter.convert_to_html(input)
-          html_input = re.sub(r' awml:style="[^"]*"', '', html_input)
-          converted_input = pandoc_convert(html_input, 'html', format)
+          try:
+            html_input, attachs = converter.convert_to_html(input)
+            html_input = re.sub(r' awml:style="[^"]*"', '', html_input)
+            converted_input = pandoc_convert(html_input, 'html', format)
+          except:
+            # If Abiword fails for any reason, try libreoffice
+            html_input, xhtml_input, attachs = convert_oo_to_html_and_xhtml(input)
+            if format == 'html':
+                  _not_used_css, converted_input = extract_css_body(xhtml_input)
+                  #converted_input = xhtml_input
+  
+            converted_input = pandoc_convert(html_input, 'html', format)
         else:
           html_input, xhtml_input, attachs = convert_oo_to_html_and_xhtml(input)
           if format == 'html':
--- a/src/cm/converters/abi_converters.py	Mon Oct 21 16:50:41 2013 +0200
+++ b/src/cm/converters/abi_converters.py	Tue Oct 22 15:00:56 2013 +0200
@@ -102,7 +102,11 @@
             type or os.path.splitext(out_file)[1][1:], 'txt')
 
         # do the conversion
-        self._perform_conversion(in_file, out_file, type)
+        try:
+          self._perform_conversion(in_file, out_file, type)
+        except:
+          raise
+
 
         # return a byte string if no out_file is specified
         if return_bytes:
@@ -126,9 +130,14 @@
         self.child.sendline(cmd)
 
         # Check for errors
-        i = self.child.expect(['OK', pexpect.TIMEOUT])
-        if i != 0:
+        i = 1
+
+        try:
+          i = self.child.expect(['OK', pexpect.TIMEOUT])
+          if i != 0:
             raise AbiCommandError('Error performing AbiCommand: %s' %cmd)
+        except:
+          raise
 
     def convert_to_html(self, input):
         """ 
@@ -174,7 +183,10 @@
           os.chmod(outdir_name, 0777) # read / write
 
           # Do the job
-          self.convert_file(infile_name, outfile_name, 'html')
+          try:
+            self.convert_file(infile_name, outfile_name, 'html')
+          except:
+            raise
 
           out_f = open(outfile_name,'r')
           output = out_f.read()
@@ -191,6 +203,9 @@
             output = re.sub(r'<img(.+)style="width:[\d\.]+mm"', r'<img\1', output)
           return output,img_res
 
+        except Exception as inst:
+          pass
+
         finally:
           try:
             if out_f:
@@ -199,6 +214,8 @@
                 infile.close()
           except:
             pass
+          if inst:
+            raise inst
 
     def convert_from_html(self, input, format):
         """