[Checkins] SVN: zopyx.convert2/trunk/src/zopyx/convert2/xfc.py adjusted to new converter API

Andreas Jung andreas at andreas-jung.com
Sat Oct 4 05:20:05 EDT 2008


Log message for revision 91729:
  adjusted to new converter API
  

Changed:
  U   zopyx.convert2/trunk/src/zopyx/convert2/xfc.py

-=-
Modified: zopyx.convert2/trunk/src/zopyx/convert2/xfc.py
===================================================================
--- zopyx.convert2/trunk/src/zopyx/convert2/xfc.py	2008-10-04 08:51:21 UTC (rev 91728)
+++ zopyx.convert2/trunk/src/zopyx/convert2/xfc.py	2008-10-04 09:20:04 UTC (rev 91729)
@@ -7,7 +7,8 @@
 import os
 import sys
 
-from util import newTempfile, runcmd, which, win32, checkEnvironment
+from convert import BaseConverter
+from util import runcmd, which, win32, checkEnvironment
 from logger import LOG
 
 from zope.interface import implements
@@ -18,6 +19,14 @@
 def _check_xfc():
     if not checkEnvironment('XFC_DIR'):
         return False
+
+    # check only for fo2rtf (we expect that all other fo2XXX
+    # converters are also installed properly)
+    full_exe_name = os.path.join(xfc_dir, 'fo2rtf')
+    if not os.path.exists(full_exe_name):
+        LOG.debug('%s does not exist' % full_exe_name)
+        return False
+
     return True
 
 
@@ -40,32 +49,50 @@
     status, output = runcmd(cmd)
     if status != 0:
         raise RuntimeError('Error executing: %s' % cmd)
-
     return output_filename
 
+class RTFConverter(BaseConverter):
 
-class RTFConverter(object):
+    name = 'rtf-xfc'
+    output_format = 'rtf'
+    visible_name = 'RTF (XINC)'
+    visible = True
 
-    implements(IFOConverter)
-    def convert(self, fo_filename, output_filename=None):
-        return fo2xfc(fo_filename, 'rtf', output_filename)
+    @staticmethod
+    def available():
+        return xfc_available
 
-class ODTConverter(object):
+    def convert(self, output_filename=None, **options):
 
-    implements(IFOConverter)
-    def convert(self, fo_filename, output_filename=None):
-        return fo2xfc(fo_filename, 'odt', output_filename)
+        self.convert2FO(**options)
+        return fo2xfc(self.fo_filename, self.output_format, output_filename)
 
-class WMLConverter(object):
+class WMLConverter(RTFConverter):
 
-    implements(IFOConverter)
-    def convert(self, fo_filename, output_filename=None):
-        return fo2xfc(fo_filename, 'wml', output_filename)
+    name = 'wml-xfc'
+    output_format = 'wml'
+    visible_name = 'WML (XINC)'
+    visible = True
 
-class DOCXConverter(object):
+class DOCXConverter(RTFConverter):
 
-    implements(IFOConverter)
-    def convert(self, fo_filename, output_filename=None):
-        return fo2xfc(fo_filename, 'docx', output_filename)
+    name = 'ooxml-xfc'
+    output_format = 'docx'
+    visible_name = 'OOXML (XINC)'
+    visible = True
 
+class ODTConverter(RTFConverter):
+
+    name = 'odt-xfc'
+    output_format = 'odt'
+    visible_name = 'ODT (XINC)'
+    visible = True
+
+
 xfc_available = _check_xfc()
+
+from registry import registerConverter
+registerConverter(RTFConverter)
+registerConverter(WMLConverter)
+registerConverter(DOCXConverter)
+registerConverter(ODTConverter)



More information about the Checkins mailing list