Commit 16bab6ca authored by Nicolas Delaby's avatar Nicolas Delaby

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.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@40595 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ef9e1ca2
......@@ -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:
......
......@@ -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,14 +160,25 @@ 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
......@@ -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 \
......
......@@ -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
......
......@@ -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,
......
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