[Erp5-report] r40595 nicolas - in /erp5/trunk/utils/cloudooo/cloudooo: ./ handler/ helper/ ...

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Nov 24 14:17:24 CET 2010


Author: nicolas
Date: Wed Nov 24 14:17:24 2010
New Revision: 40595

URL: http://svn.erp5.org?rev=40595&view=rev
Log:
Add new option to convertFile: refresh
This new option is able to recompute dynamics properties inside OOo documents
Like cells, variables, fields, charts. (disable by default)

This is useful for hacked documents.


Modified:
    erp5/trunk/utils/cloudooo/cloudooo/handler/oohandler.py
    erp5/trunk/utils/cloudooo/cloudooo/helper/unoconverter.py
    erp5/trunk/utils/cloudooo/cloudooo/interfaces/manager.py
    erp5/trunk/utils/cloudooo/cloudooo/manager.py

Modified: erp5/trunk/utils/cloudooo/cloudooo/handler/oohandler.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/handler/oohandler.py?rev=40595&r1=40594&r2=40595&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/handler/oohandler.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/handler/oohandler.py [utf8] Wed Nov 24 14:17:24 2010
@@ -59,6 +59,7 @@ class OOHandler:
     self.uno_path = kw.get("uno_path", None)
     self.office_binary_path = kw.get("office_binary_path", None)
     self.timeout = kw.get("timeout", 600)
+    self.refresh = kw.get('refresh', False)
     self.source_format = source_format
     if not self.uno_path:
       self.uno_path = environ.get("uno_path")
@@ -164,6 +165,7 @@ class OOHandler:
     if destination_format:
       kw['destination_format'] = destination_format
     kw['mimemapper'] = self._serializeMimemapper()
+    kw['refresh'] = jsonpickle.encode(self.refresh)
     try:
       stdout, stderr = self._callUnoConverter(*['convert'], **kw)
     finally:

Modified: erp5/trunk/utils/cloudooo/cloudooo/helper/unoconverter.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/helper/unoconverter.py?rev=40595&r1=40594&r2=40595&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/helper/unoconverter.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/helper/unoconverter.py [utf8] Wed Nov 24 14:17:24 2010
@@ -77,6 +77,7 @@ class UnoConverter(object):
     self.document_url = document_url
     self.document_dir_path = dirname(document_url)
     self.source_format = kw.get('source_format')
+    self.refresh = kw.get('refresh')
     self._setUpUnoEnvironment(kw.get("uno_path"), 
                               kw.get("office_binary_path"))
     self._load()
@@ -159,17 +160,28 @@ class UnoConverter(object):
       return ()
 
   def _load(self):
-    """Create one document with basic properties"""
+    """Create one document with basic properties
+    refresh argument tells to uno environment to
+    replace dynamic properties of document before conversion
+    """
     service_manager = helper_utils.getServiceManager(self.hostname, self.port)
     desktop = service_manager.createInstance("com.sun.star.frame.Desktop")
     uno_url = self.systemPathToFileUrl(self.document_url)
     uno_document = desktop.loadComponentFromURL(uno_url, "_blank", 0, ())
-    module_manager = service_manager.createInstance("com.sun.star.frame.ModuleManager")
     if not uno_document:
       raise AttributeError, "This document can not be loaded or is empty"
+    if self.refresh:
+      # Before converting to expected format, refresh dynamic
+      # value inside document.
+      dispatcher = service_manager.createInstance("com.sun.star.frame.DispatchHelper")
+      for uno_command in ('UpdateFields', 'UpdateAll', 'UpdateInputFields',
+                          'UpdateAllLinks', 'UpdateCharts',):
+        dispatcher.executeDispatch(uno_document.getCurrentController().getFrame(),
+                                   '.uno:%s' % uno_command, '', 0, ())
+    module_manager = service_manager.createInstance("com.sun.star.frame.ModuleManager")
     self.document_type = module_manager.identify(uno_document)
     self.document_loaded = uno_document
-  
+
   def systemPathToFileUrl(self, path):
     """Returns a path in uno library patterns"""
     from unohelper import systemPathToFileUrl
@@ -266,7 +278,7 @@ def main():
       "uno_path=", "office_binary_path=", 
       "hostname=", "port=", "source_format=",
       "document_url=", "destination_format=", 
-      "mimemapper=", "metadata=",
+      "mimemapper=", "metadata=", "refresh=",
       "unomimemapper_bin=", "jsonpickle_path="])
   except GetoptError, msg:
     msg = msg.msg + help_msg
@@ -281,7 +293,7 @@ def main():
       break
 
   import jsonpickle
-
+  refresh = None
   for opt, arg in iter(opt_list):
     if opt in ('-h', '--help'):
       help()
@@ -301,6 +313,8 @@ def main():
       destination_format = arg
     elif opt == '--source_format':
       source_format = arg
+    elif opt == '--refresh':
+      refresh = jsonpickle.decode(arg)
     elif opt == '--metadata':
       arg = decodestring(arg)
       metadata = jsonpickle.decode(arg)
@@ -316,6 +330,8 @@ def main():
  
   if 'source_format' in locals():
     kw['source_format'] = source_format
+  if refresh:
+    kw['refresh'] = refresh
   
   unoconverter = UnoConverter(hostname, port, document_url, **kw)
   if "--convert" in param_list and not '--getmetadata' in param_list \

Modified: erp5/trunk/utils/cloudooo/cloudooo/interfaces/manager.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/interfaces/manager.py?rev=40595&r1=40594&r2=40595&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/interfaces/manager.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/interfaces/manager.py [utf8] Wed Nov 24 14:17:24 2010
@@ -32,7 +32,7 @@ from zope.interface import Interface
 class IManager(Interface):
   """Provides method to manipulate documents and metadatas using OOo"""
 
-  def convertFile(file, source_format, destination_format, zip):
+  def convertFile(file, source_format, destination_format, zip, refresh):
     """Returns the converted file in the given format.
 
     zip parameter can be specified to return the result of conversion

Modified: erp5/trunk/utils/cloudooo/cloudooo/manager.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/manager.py?rev=40595&r1=40594&r2=40595&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/manager.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/manager.py [utf8] Wed Nov 24 14:17:24 2010
@@ -45,7 +45,8 @@ class Manager(object):
     self._path_tmp_dir = path_tmp_dir
     self.kw = kw
 
-  def convertFile(self, file, source_format, destination_format, zip=False):
+  def convertFile(self, file, source_format, destination_format, zip=False,
+                  refresh=False):
     """Returns the converted file in the given format.
     Keywords arguments:
       file -- File as string in base64
@@ -57,6 +58,7 @@ class Manager(object):
     if not mimemapper.getFilterList(destination_format):
       raise ValueError, "This format is not supported or is invalid"
     self.kw['zip'] = zip
+    self.kw['refresh'] = refresh
     document = OOHandler(self._path_tmp_dir,
                         decodestring(file),
                         source_format,




More information about the Erp5-report mailing list