Commit a6e911b6 authored by Nicolas Delaby's avatar Nicolas Delaby

Update Interfaces to improve API and support of multiple backends.

 * replace format by mimetype and avoid ambiguity in parameter names
 * remove specific method of ooo handler
 * improve consistency and reuse same parameter names


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@44989 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f9457dfe
...@@ -30,44 +30,57 @@ from zope.interface import Interface ...@@ -30,44 +30,57 @@ from zope.interface import Interface
class ITableGranulator(Interface): class ITableGranulator(Interface):
"""Provides methods to granulate a document into tables.""" """Provides methods to granulate a document into tables.
"""
def getTableItemList(data, source_format): def getTableItemList(content, source_mimetype):
"""Returns the list of table IDs in the form of (id, title).""" """Returns the list of table IDs in the form of (id, title).
"""
def getTable(data, table_id, source_format): def getTable(content, source_mimetype, table_id ):
"""Returns the table into a new 'format' file.""" """Returns the table into a new 'format' file.
"""
def getColumnItemList(data, table_id, source_format): def getColumnItemList(content, source_mimetype, table_id):
"""Return the list of columns in the form of (id, title).""" """Return the list of columns in the form of (id, title).
"""
def getLineItemList(data, table_id, source_format): def getLineItemList(content, source_mimetype, table_id):
"""Returns the lines of a given table as (key, value) pairs.""" """Returns the lines of a given table as (key, value) pairs.
"""
class IImageGranulator(Interface): class IImageGranulator(Interface):
"""Provides methods to granulate a document into images.""" """Provides methods to granulate a document into images.
"""
def getImageItemList(data, source_format): def getImageItemList(content, source_mimetype):
"""Return the list of images in the form of (id, title).""" """Return the list of images in the form of (id, title).
"""
def getImage(data, image_id, source_format, def getImage(content, filename, source_mimetype,
format=None, resolution=None, **kw): destination_mimetype=None, **kw):
"""Return the given image.""" """Return the given image.
"""
class ITextGranulator(Interface): class ITextGranulator(Interface):
"""Provides methods to granulate a document into chapters and paragraphs.""" """Provides methods to granulate a document into chapters and paragraphs.
"""
def getParagraphItemList(data, source_format): def getParagraphItemList(content, source_mimetype):
"""Returns the list of paragraphs in the form of (id, class) where class """Returns the list of paragraphs in the form of (id, class) where class
may have special meaning to define TOC/TOI.""" may have special meaning to define TOC/TOI.
"""
def getParagraph(data, paragraph_id, source_format): def getParagraph(content, source_mimetype, paragraph_id):
"""Returns the paragraph in the form of (text, class).""" """Returns the paragraph in the form of (text, class).
"""
def getChapterItemList(data, source_format): def getChapterItemList(content, source_mimetype):
"""Returns the list of chapters in the form of (id, level).""" """Returns the list of chapters in the form of (id, level).
"""
def getChapterItem(data, chapter_id, source_format): def getChapterItem(content, source_mimetype, chapter_id):
"""Return the chapter in the form of (title, level).""" """Return the chapter in the form of (title, level).
"""
...@@ -28,16 +28,18 @@ ...@@ -28,16 +28,18 @@
from zope.interface import Interface from zope.interface import Interface
class IHandler(Interface): class IHandler(Interface):
"""Handles connections with the openoffice by socket""" """Handles communications between manager and specific backends
"""
def convert(destination_format): def convert(destination_mimetype):
"""Convert document to ODF""" """Convert to expected format
"""
def getMetadata(converted_data): def getMetadata():
"""Returns a dictionary with all metadata of document. If converted_data is """Returns a dictionary with all metadata of document.
True, the document is added in dictionary.""" """
def setMetadata(metadata_dict): def setMetadata(metadata_dict):
"""Returns a document with the new metadata""" """Returns a document with the new metadata
"""
...@@ -30,33 +30,83 @@ from zope.interface import Interface ...@@ -30,33 +30,83 @@ from zope.interface import Interface
class IManager(Interface): class IManager(Interface):
"""Provides method to manipulate documents and metadatas using OOo""" """Provides public method to communicate with Cloudooo clients
"""
def convertFile(file, source_format, destination_format, zip, refresh): def convertFile(content, source_mimetype, destination_mimetype, **kw):
"""Returns the converted file in the given format. """Returns the converted file in the given format.
zip parameter can be specified to return the result of conversion content : binary data to convert
in the form of a zip archive (which may contain multiple parts). source_mimetype : mimetype of given content
This can be useful to convert a single ODF file to HTML destination_mimetype : expected output conversion mimetype
and png images.
**kw holds specific parameters for the conversion
""" """
def getFileMetadataItemList(file, source_format, base_document): def convertBundle(content, filename, source_mimetype, destination_mimetype,
**kw):
"""The content must be a zip archive with multiples files.
filename is the authority file to convert inside archive.
All other files are embedded object usefull to perform the conversion
like css, images, videos, audio files, ...
It returns the converted data.
content : zip bundle
filename: filename of authority file to extract from the bundle.
source_mimetype : mimetype of given authority file
destination_mimetype : expected output conversion mimetype
**kw holds specific parameters for the conversion
"""
def getFileMetadataItemList(content, source_mimetype):
"""Returns a list key, value pairs representing the """Returns a list key, value pairs representing the
metadata values for the document. The structure of this metadata values for the document. The structure of this
list is "unpredictable" and follows the convention of each file. list is "unpredictable" and follows the convention of each file.
content : binary data where to reads metadata
source_mimetype : mimetype of given content
"""
def convertFileAndGetMetadataItemList(content, source_mimetype,
destination_mimetype, **kw):
"""returns a converted version of provided content plus a
dictionary of extracted metadata.
signature of method is same as convertFile
result is a json dictionary with 'conversion' and
'metadata' entries.
""" """
def updateFileMetadata(file, source_format, metadata_dict): def updateFileMetadata(content, source_mimetype, metadata_dict):
"""Updates the file in the given source_format with provided metadata and """Updates the content with provided metadata and
return the resulting new file.""" return the new file.
content : binary data to convert
source_mimetype : mimetype of given content
metadata_dict : Metadatas to include in content
"""
def getAllowedExtensionList(request_dict): def getAllowedConversionFormatList(source_mimetype):
"""Returns a list extension which can be generated from given extension or """Returns a list content_type and their titles which are supported
document type.""" by enabled handlers.
[('application/vnd.oasis.opendocument.text', 'ODF Text Document'),
('application/pdf', 'PDF - Portable Document Format'),
...
]
"""
def granulateFile(file, source_format, zip): def getAllowedConversionFormatInfoList(source_mimetype):
"""Returns a zip file with parts of an document splited by grains.""" """Returns a list content_type and list of parameter which are supported
by enabled handlers.
(see IMimemapper.getAllowedExtensionInfoList)
"""
def granulateFile(content, source_mimetype):
"""Returns a zip file with parts of an document splited by grains.
"""
class IERP5Compatibility(Interface): class IERP5Compatibility(Interface):
......
...@@ -30,24 +30,24 @@ from zope.interface import Interface ...@@ -30,24 +30,24 @@ from zope.interface import Interface
class IMimemapper(Interface): class IMimemapper(Interface):
"""Provide methods to manipulate filters of OOo.""" """Provide methods to manipulate conversion abilities of
handlers
"""
def isLoaded(): def isLoaded():
"""Returns if the filters were loaded.""" """Returns if mimemapper is bootstraped
"""
def getDocumentTypeDict():
"""Returns document type dict."""
def getFilterName(extension, document_type):
"""Returns the name of filter according to parematers passed."""
def loadFilterList(**kwargs):
"""Load all filters of openoffice."""
def getFilterList(extension, **kwargs): def loadMimemapper():
"""Returns a filter list according to extension or other parameters passed. """bootstrap mimemapper of handler
""" """
def getAllowedExtensionList(document_type, **kwargs): def getAllowedExtensionInfoList(mimetype):
"""Returns a list with extensions which can be used to export according to """Return a detailed list of output mimetypes with a list of
document type passed.""" accepted parameter to perform the conversion:
application/pdf: [('text/plain', ()),
('image/png', ('frame', 'resolution', 'width', 'height',
'colorspace',)),
...
]
"""
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