Commit 3b7bbafa authored by Gabriel Monnerat's avatar Gabriel Monnerat

fixed Bug #2014. refactor code to convert data to base64. With this, is...

fixed Bug #2014. refactor code to convert data to base64. With this, is possible send data with quotes

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@38939 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9c7e088f
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
############################################################################## ##############################################################################
import jsonpickle, pkg_resources import jsonpickle, pkg_resources
from base64 import decodestring, encodestring
from os import environ, path from os import environ, path
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from cloudooo.application.openoffice import openoffice from cloudooo.application.openoffice import openoffice
...@@ -38,7 +39,6 @@ from cloudooo.document import FileSystemDocument ...@@ -38,7 +39,6 @@ from cloudooo.document import FileSystemDocument
from cloudooo.monitor.timeout import MonitorTimeout from cloudooo.monitor.timeout import MonitorTimeout
from cloudooo.utils import logger from cloudooo.utils import logger
from psutil import pid_exists from psutil import pid_exists
from sys import executable as python_path
class OOHandler: class OOHandler:
"""OOHandler is used to access the one Document and OpenOffice. """OOHandler is used to access the one Document and OpenOffice.
...@@ -79,9 +79,9 @@ class OOHandler: ...@@ -79,9 +79,9 @@ class OOHandler:
, "--document_url='%s'" % self.document.getUrl() , "--document_url='%s'" % self.document.getUrl()
, "--jsonpickle_path='%s'" % jsonpickle_path] , "--jsonpickle_path='%s'" % jsonpickle_path]
for arg in args: for arg in args:
command_list.insert(3, "'--%s'" % arg) command_list.insert(3, "--%s" % arg)
for k, v in kw.iteritems(): for k, v in kw.iteritems():
command_list.append("'--%s=%s'" % (k,v)) command_list.append("--%s='%s'" % (k,v))
return ' '.join(command_list) return ' '.join(command_list)
...@@ -194,8 +194,7 @@ class OOHandler: ...@@ -194,8 +194,7 @@ class OOHandler:
openoffice.release() openoffice.release()
if self.monitor.is_alive(): if self.monitor.is_alive():
self._stopTimeout() self._stopTimeout()
metadata={} metadata=jsonpickle.decode(decodestring(stdout))
exec("metadata=%s" % stdout)
if metadata.get("Data"): if metadata.get("Data"):
self.document.reload(metadata['Data']) self.document.reload(metadata['Data'])
metadata['Data'] = self.document.getContent() metadata['Data'] = self.document.getContent()
...@@ -213,7 +212,7 @@ class OOHandler: ...@@ -213,7 +212,7 @@ class OOHandler:
openoffice.acquire() openoffice.acquire()
metadata_pickled = jsonpickle.encode(metadata) metadata_pickled = jsonpickle.encode(metadata)
logger.debug("setMetadata") logger.debug("setMetadata")
kw = dict(metadata=metadata_pickled) kw = dict(metadata=encodestring(metadata_pickled))
try: try:
stdout, stderr = self._callUnoConverter(*['setmetadata'], **kw) stdout, stderr = self._callUnoConverter(*['setmetadata'], **kw)
finally: finally:
......
...@@ -33,6 +33,7 @@ from types import UnicodeType, InstanceType ...@@ -33,6 +33,7 @@ from types import UnicodeType, InstanceType
from os import environ, putenv from os import environ, putenv
from os.path import dirname, exists from os.path import dirname, exists
from tempfile import mktemp from tempfile import mktemp
from base64 import decodestring, encodestring
from getopt import getopt, GetoptError from getopt import getopt, GetoptError
__doc__ = """ __doc__ = """
...@@ -298,6 +299,7 @@ def main(): ...@@ -298,6 +299,7 @@ def main():
elif opt == '--source_format': elif opt == '--source_format':
source_format = arg source_format = arg
elif opt == '--metadata': elif opt == '--metadata':
arg = decodestring(arg)
metadata = jsonpickle.decode(arg) metadata = jsonpickle.decode(arg)
elif opt == '--mimemapper': elif opt == '--mimemapper':
mimemapper = jsonpickle.decode(arg) mimemapper = jsonpickle.decode(arg)
...@@ -319,10 +321,12 @@ def main(): ...@@ -319,10 +321,12 @@ def main():
elif '--convert' in param_list and 'destination_format' in locals(): elif '--convert' in param_list and 'destination_format' in locals():
output = unoconverter.convert(destination_format) output = unoconverter.convert(destination_format)
elif '--getmetadata' in param_list and not '--convert' in param_list: elif '--getmetadata' in param_list and not '--convert' in param_list:
output = unoconverter.getMetadata() metadata_dict = unoconverter.getMetadata()
output = encodestring(jsonpickle.encode(metadata_dict))
elif '--getmetadata' in param_list and '--convert' in param_list: elif '--getmetadata' in param_list and '--convert' in param_list:
output = unoconverter.getMetadata() metadata_dict = unoconverter.getMetadata()
output['Data'] = unoconverter.convert() metadata_dict['Data'] = unoconverter.convert()
output = encodestring(jsonpickle.encode(metadata_dict))
elif '--setmetadata' in param_list: elif '--setmetadata' in param_list:
unoconverter.setMetadata(metadata) unoconverter.setMetadata(metadata)
output = document_url output = document_url
......
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