Commit 9f9e7abd authored by Tristan Cavelier's avatar Tristan Cavelier

xxx workaround 4 wip

parent 59f66814
...@@ -111,7 +111,13 @@ class OOoServerProxy(ServerProxy): ...@@ -111,7 +111,13 @@ class OOoServerProxy(ServerProxy):
or OOO_SERVER_PROXY_TIMEOUT or OOO_SERVER_PROXY_TIMEOUT
transport = TimeoutTransport(timeout=timeout, scheme=scheme) transport = TimeoutTransport(timeout=timeout, scheme=scheme)
ServerProxy.__init__(self, uri, allow_none=True, transport=transport) #ServerProxy.__init__(self, uri, allow_none=True, transport=transport)
from xmlrpclib import SafeTransport
import ssl
host = "[2001:67c:1254:9c::e1f]:8000" # cloudooo3 - CloudoooTest
ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) # allow invalid/autosigned certs
ssl_context.verify_mode = ssl.CERT_NONE
ServerProxy.__init__(self, "https://" + host, allow_none=True, transport=SafeTransport(context=ssl_context))
def __getattr__(self, attr): def __getattr__(self, attr):
obj = ServerProxy.__getattr__(self, attr) obj = ServerProxy.__getattr__(self, attr)
...@@ -214,6 +220,7 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi ...@@ -214,6 +220,7 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi
def cached_getTargetFormatItemList(content_type): def cached_getTargetFormatItemList(content_type):
server_proxy = OOoServerProxy(self) server_proxy = OOoServerProxy(self)
# XXX cloudooo3 needed to have allowed target list given by x2t + ooo
try: try:
allowed_target_item_list = server_proxy.getAllowedTargetItemList( allowed_target_item_list = server_proxy.getAllowedTargetItemList(
content_type) content_type)
...@@ -242,7 +249,13 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi ...@@ -242,7 +249,13 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi
DeprecationWarning) DeprecationWarning)
# tuple order is reversed to be compatible with ERP5 Form # tuple order is reversed to be compatible with ERP5 Form
return [(y, x) for x, y in allowed] return [(y, x) for x, y in allowed] + (
##### BEGIN hack - handle yformat (which should not be OOoDocument) XXX##
{"Text": [("OnlyOffice Text Document", "docy")],
"Spreadsheet": [("OnlyOffice Spreadsheet", "xlsy")],
"Presentation": [("OnlyOffice Presentation", "ppty")]}.get(self.getPortalType(), [])
##### END hack #####
)
# Cache valid format list # Cache valid format list
cached_getTargetFormatItemList = CachingMethod( cached_getTargetFormatItemList = CachingMethod(
...@@ -271,7 +284,24 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi ...@@ -271,7 +284,24 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi
z.close() z.close()
return 'text/plain', s return 'text/plain', s
server_proxy = OOoServerProxy(self) server_proxy = OOoServerProxy(self)
# XXX cloudooo3 needed to convert with x2t
orig_format = self.getBaseContentType() orig_format = self.getBaseContentType()
##### BEGIN hack - handle yformat (should not be OOoDocument) XXX##
# XXX public cloudooo.erp5.net cannot handle x2t because of an OSError
__traceback_info__ = ("orig_format", orig_format, "format", format)
if format in ("docy", "application/x-asc-text"):
encdata = server_proxy.convertFile(enc(str(self.getBaseData())), "odt", "docx")
#orig_format = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
return "application/x-asc-text", Pdata(dec(server_proxy.convertFile(encdata, "docx", "docy")))
if format in ("xsly", "application/x-asc-spreadsheet"):
encdata = server_proxy.convertFile(enc(str(self.getBaseData())), "ods", "xlsx")
#orig_format = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
return "application/x-asc-spreadsheet", Pdata(dec(server_proxy.convertFile(encdata, "xlsx", "xlsy")))
if format in ("ppty", "application/x-asc-presentation"):
encdata = server_proxy.convertFile(enc(str(self.getBaseData())), "odp", "pptx")
#orig_format = "application/vnd.openxmlformats-officedocument.presentationml.presentation"
return "application/x-asc-presentation", Pdata(dec(server_proxy.convertFile(encdata, "pptx", "ppty")))
##### END hack #####
generate_result = server_proxy.run_generate(self.getId(), generate_result = server_proxy.run_generate(self.getId(),
enc(str(self.getBaseData())), enc(str(self.getBaseData())),
None, None,
...@@ -354,6 +384,12 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi ...@@ -354,6 +384,12 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi
self.setConversion(data, mime, format=original_format) self.setConversion(data, mime, format=original_format)
return mime, data return mime, data
return self.getConversion(format=original_format) return self.getConversion(format=original_format)
try:
__traceback_info__ = repr(self), repr(self.getTargetFormatItemList())
except ConflictError, e:
raise e
except Exception, e:
__traceback_info__ = str(e)
# Raise an error if the format is not supported # Raise an error if the format is not supported
if not self.isTargetFormatAllowed(format): if not self.isTargetFormatAllowed(format):
raise ConversionError("OOoDocument: target format %s is not supported" % format) raise ConversionError("OOoDocument: target format %s is not supported" % format)
...@@ -446,12 +482,31 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi ...@@ -446,12 +482,31 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi
on the object. Update metadata information. on the object. Update metadata information.
""" """
server_proxy = OOoServerProxy(self) server_proxy = OOoServerProxy(self)
# XXX cloudooo3 needed to have x2t convert available
##### BEGIN hack - handle yformat (which should not be OOoDocument) XXX##
content_type = self.getContentType()
filename = self.getFilename() or self.getId()
if content_type == "application/x-asc-text":
encdata = server_proxy.convertFile(enc(str(self.getData())), "docy", "docx")
content_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
filename += ".docx"
elif content_type == "application/x-asc-spreadsheet":
encdata = server_proxy.convertFile(enc(str(self.getData())), "xlsy", "xlsx")
content_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
filename += ".xlsx"
elif content_type == "application/x-asc-presentation":
encdata = server_proxy.convertFile(enc(str(self.getData())), "ppty", "pptx")
content_type = "application/vnd.openxmlformats-officedocument.presentationml.presentation"
filename += ".pptx"
else:
encdata = enc(str(self.getData()))
##### END hack #####
response_code, response_dict, response_message = server_proxy.run_convert( response_code, response_dict, response_message = server_proxy.run_convert(
self.getFilename() or self.getId(), filename,
enc(str(self.getData())), encdata,
None, None,
None, None,
self.getContentType()) content_type)
if response_code == 200: if response_code == 200:
# sucessfully converted document # sucessfully converted document
self._setBaseData(dec(response_dict['data'])) self._setBaseData(dec(response_dict['data']))
...@@ -485,6 +540,7 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi ...@@ -485,6 +540,7 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi
raise NotConvertedError() raise NotConvertedError()
server_proxy = OOoServerProxy(self) server_proxy = OOoServerProxy(self)
# XXX cloudooo3 needed to have setMetadata on x2t
response_code, response_dict, response_message = \ response_code, response_dict, response_message = \
server_proxy.run_setmetadata(self.getId(), server_proxy.run_setmetadata(self.getId(),
enc(str(self.getBaseData())), enc(str(self.getBaseData())),
......
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