Commit 8322cec2 authored by Arnaud Fontaine's avatar Arnaud Fontaine

WIP: Migrate Transforms

You may have to either restart your instance or call portal_transforms/manage_reloadAllTransforms
for this change to take effect.
parent a84dac8a
...@@ -5,9 +5,8 @@ from Products.ERP5.Document.Document import ConversionError ...@@ -5,9 +5,8 @@ from Products.ERP5.Document.Document import ConversionError
from Acquisition import aq_base from Acquisition import aq_base
from zope.interface import implements from zope.interface import implements
from OFS.Image import Image as OFSImage from OFS.Image import Image as OFSImage
from zLOG import LOG
from Products.ERP5OOo.OOoUtils import OOoBuilder from erp5.component.module.OOoUtils import OOoBuilder
import re import re
from lxml import etree from lxml import etree
from lxml import html from lxml import html
...@@ -134,15 +133,15 @@ class OOOdCommandTransform(commandtransform): ...@@ -134,15 +133,15 @@ class OOOdCommandTransform(commandtransform):
if image is not None: if image is not None:
odt_content_modified = True odt_content_modified = True
content_type = image.getContentType() content_type = image.getContentType()
format = image_parameter_dict.pop('format', None) format_ = image_parameter_dict.pop('format', None)
# convert API accepts only a certail range of arguments # convert API accepts only a certail range of arguments
for key, value in image_parameter_dict.items(): for key, _ in image_parameter_dict.items():
if key not in ('format', 'display', 'quality', 'resolution',): if key not in ('format', 'display', 'quality', 'resolution',):
image_parameter_dict.pop(key) image_parameter_dict.pop(key)
if getattr(image, 'convert', None) is not None: if getattr(image, 'convert', None) is not None:
# The document support conversion so perform conversion # The document support conversion so perform conversion
# according given parameters # according given parameters
mime, image_data = image.convert(format, **image_parameter_dict) _, image_data = image.convert(format_, **image_parameter_dict)
# wrapp converted data into OFSImage in order to compute metadatas # wrapp converted data into OFSImage in order to compute metadatas
# on converted result # on converted result
image = OFSImage(image.getId(), image.getTitle(), image_data) image = OFSImage(image.getId(), image.getTitle(), image_data)
...@@ -155,17 +154,17 @@ class OOOdCommandTransform(commandtransform): ...@@ -155,17 +154,17 @@ class OOOdCommandTransform(commandtransform):
frame.attrib.update({'{%s}height' % SVG_NAMESPACE: '%.3fcm' % (height * ratio_px_cm)}) frame.attrib.update({'{%s}height' % SVG_NAMESPACE: '%.3fcm' % (height * ratio_px_cm)})
if width: if width:
frame.attrib.update({'{%s}width' % SVG_NAMESPACE: '%.3fcm' % (width * ratio_px_cm)}) frame.attrib.update({'{%s}width' % SVG_NAMESPACE: '%.3fcm' % (width * ratio_px_cm)})
if not format: if not format_:
mimetype_list = self.context.getPortalObject().mimetypes_registry.lookup(content_type) mimetype_list = self.context.getPortalObject().mimetypes_registry.lookup(content_type)
# guess a format with help of mimetypes_registry # guess a format with help of mimetypes_registry
for mimetype_object in mimetype_list: for mimetype_object in mimetype_list:
if mimetype_object.extensions: if mimetype_object.extensions:
format = mimetype_object.extensions[0] format_ = mimetype_object.extensions[0]
break break
elif mimetype_object.globs: elif mimetype_object.globs:
format = mimetype_object.globs[0].strip('*.') format_ = mimetype_object.globs[0].strip('*.')
break break
new_path = builder.addImage(data, format=format) new_path = builder.addImage(data, format=format_)
image_tag.attrib.update({'{%s}href' % XLINK_NAMESPACE: new_path}) image_tag.attrib.update({'{%s}href' % XLINK_NAMESPACE: new_path})
if odt_content_modified: if odt_content_modified:
builder.replace('content.xml', etree.tostring(xml_doc, encoding='utf-8', builder.replace('content.xml', etree.tostring(xml_doc, encoding='utf-8',
...@@ -181,7 +180,7 @@ class OOOdCommandTransform(commandtransform): ...@@ -181,7 +180,7 @@ class OOOdCommandTransform(commandtransform):
""" """
try: try:
xml_doc = etree.XML(data) xml_doc = etree.XML(data)
except ParseError: except ParseError: # pylint: disable=catching-non-exception
#If not valid xhtml do nothing #If not valid xhtml do nothing
return data return data
xpath = '//*[local-name() = "link"][@type = "text/css"]' xpath = '//*[local-name() = "link"][@type = "text/css"]'
...@@ -219,13 +218,12 @@ class OOOdCommandTransform(commandtransform): ...@@ -219,13 +218,12 @@ class OOOdCommandTransform(commandtransform):
return xml_output return xml_output
def convertTo(self, format): def convertTo(self, format): # pylint: disable=redefined-builtin
server_proxy = DocumentConversionServerProxy(self.context) server_proxy = DocumentConversionServerProxy(self.context)
response_code, response_dict, message = \ _, response_dict, _ = server_proxy.getAllowedTargetItemList(self.mimetype)
server_proxy.getAllowedTargetItemList(self.mimetype)
allowed_extension_list = response_dict['response_data'] allowed_extension_list = response_dict['response_data']
if format in dict(allowed_extension_list): if format in dict(allowed_extension_list):
response_code, response_dict, message = server_proxy.run_generate( _, response_dict, _ = server_proxy.run_generate(
'', '',
enc(self.data), enc(self.data),
None, None,
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Module Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>OOOdCommandTransform</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5OOo.transforms.oood_commandtransform</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>module.erp5.OOOdCommandTransform</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Module Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from Products.PortalTransforms.interfaces import itransform from Products.PortalTransforms.interfaces import itransform
from zope.interface import implements from zope.interface import implements
from oood_commandtransform import OOOdCommandTransform, OOoDocumentDataStream from erp5.component.module.OOOdCommandTransform import OOOdCommandTransform, OOoDocumentDataStream, includeMetaContentType
from oood_commandtransform import includeMetaContentType
from zLOG import LOG
from lxml import etree, html from lxml import etree, html
from lxml.etree import Element, SubElement
html_parser = etree.HTMLParser(remove_blank_text=True, encoding='utf-8') html_parser = etree.HTMLParser(remove_blank_text=True, encoding='utf-8')
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Module Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>TransformHtmlToOdt</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5OOo.transforms.html_to_odt</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>module.erp5.TransformHtmlToOdt</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Module Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from Products.PortalTransforms.interfaces import itransform from Products.PortalTransforms.interfaces import itransform
from zope.interface import implements from zope.interface import implements
from oood_commandtransform import OOOdCommandTransform, OOoDocumentDataStream from erp5.component.module.OOOdCommandTransform import OOOdCommandTransform, OOoDocumentDataStream
from zLOG import LOG
class OdtToDoc: class OdtToDoc:
"""Transforms ODT to Doc by using oood""" """Transforms ODT to Doc by using oood"""
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Module Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>TransformOdtToDoc</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5OOo.transforms.odt_to_doc</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>module.erp5.TransformOdtToDoc</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Module Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from Products.PortalTransforms.interfaces import itransform from Products.PortalTransforms.interfaces import itransform
from zope.interface import implements from zope.interface import implements
from oood_commandtransform import OOOdCommandTransform, OOoDocumentDataStream from erp5.component.module.OOOdCommandTransform import OOOdCommandTransform, OOoDocumentDataStream
from zLOG import LOG
class OdtToPdf: class OdtToPdf:
"""Transforms ODT to PDF by using oood""" """Transforms ODT to PDF by using oood"""
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Module Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>TransformOdtToPdf</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5OOo.transforms.odt_to_pdf</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>module.erp5.TransformOdtToPdf</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Module Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from Products.PortalTransforms.interfaces import itransform from Products.PortalTransforms.interfaces import itransform
from zope.interface import implements from zope.interface import implements
from oood_commandtransform import OOOdCommandTransform, OOoDocumentDataStream from erp5.component.module.OOOdCommandTransform import OOOdCommandTransform, OOoDocumentDataStream
from zLOG import LOG from erp5.component.module.OOoUtils import OOoBuilder
from Products.ERP5OOo.OOoUtils import OOoBuilder
import re
class OdtToXml: class OdtToXml:
"""Transforms ODT to Doc by using oood""" """Transforms ODT to Doc by using oood"""
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Module Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>TransformOdtToXml</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5OOo.transforms.odt_to_xml</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>module.erp5.TransformOdtToXml</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Module Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
module.erp5.OOOdCommandTransform
module.erp5.TransformDocToDocx module.erp5.TransformDocToDocx
module.erp5.TransformDocToHtml module.erp5.TransformDocToHtml
module.erp5.TransformDocxToDocy module.erp5.TransformDocxToDocy
module.erp5.TransformDocxToOdt module.erp5.TransformDocxToOdt
module.erp5.TransformDocyToDocx module.erp5.TransformDocyToDocx
module.erp5.TransformHtmlToOdt
module.erp5.TransformOdpToHtml module.erp5.TransformOdpToHtml
module.erp5.TransformOdpToPdf module.erp5.TransformOdpToPdf
module.erp5.TransformOdpToPptx module.erp5.TransformOdpToPptx
...@@ -10,6 +12,9 @@ module.erp5.TransformOdpToSxi ...@@ -10,6 +12,9 @@ module.erp5.TransformOdpToSxi
module.erp5.TransformOdsToHtml module.erp5.TransformOdsToHtml
module.erp5.TransformOdsToPdf module.erp5.TransformOdsToPdf
module.erp5.TransformOdsToXlsx module.erp5.TransformOdsToXlsx
module.erp5.TransformOdtToDoc
module.erp5.TransformOdtToPdf
module.erp5.TransformOdtToXml
module.erp5.TransformOdtToDocx module.erp5.TransformOdtToDocx
module.erp5.TransformOdtToHtml module.erp5.TransformOdtToHtml
module.erp5.TransformPdfToBmp module.erp5.TransformPdfToBmp
......
### Register Transforms
### This is interesting because we don't expect all transforms to be
### available on all platforms. To do this we allow things to fail at
### two levels
### 1) Imports
### If the import fails the module is removed from the list and
### will not be processed/registered
### 2) Registration
### A second phase happens when the loaded modules register method
### is called and this produces an instance that will used to
### implement the transform, if register needs to fail for now it
### should raise an ImportError as well (dumb, I know)
from logging import DEBUG, ERROR
from Products.PortalTransforms.utils import log
from Products.PortalTransforms.libtransforms.utils import MissingBinary
modules = (
'html_to_odt',
'odt_to_doc',
'odt_to_pdf',
)
g = globals()
transforms = []
for m in modules:
try:
ns = __import__(m, g, g, None)
transforms.append(ns.register())
except ImportError, e:
msg = "Problem importing module %s : %s" % (m, e)
log(msg, severity=ERROR)
except MissingBinary, e:
log(str(e), severity=DEBUG)
except Exception, e:
import traceback
traceback.print_exc()
log("Raised error %s for %s" % (e, m), severity=ERROR)
def initialize(engine):
for transform in transforms:
engine.registerTransform(transform)
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