Commit b5313ced authored by Hugo H. Maia Vieira's avatar Hugo H. Maia Vieira

Add granulateFile to manager interface


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@40747 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a244fe57
...@@ -55,6 +55,9 @@ class IManager(Interface): ...@@ -55,6 +55,9 @@ class IManager(Interface):
"""Returns a list extension which can be generated from given extension or """Returns a list extension which can be generated from given extension or
document type.""" document type."""
def granulateFile(file, source_format, zip):
"""Returns a zip file with parts of an document splited by grains."""
class IERP5Compatibility(Interface): class IERP5Compatibility(Interface):
""" Provides compatibility interface with ERP5 Project. """ Provides compatibility interface with ERP5 Project.
......
...@@ -67,25 +67,23 @@ class Manager(object): ...@@ -67,25 +67,23 @@ class Manager(object):
return encodestring(decode_data) return encodestring(decode_data)
def granulateFile(self, file, source_format, zip=False): def granulateFile(self, file, source_format, zip=False):
"""Returns an zip file? with parts of an document splited by grains. """Returns the parts of an document splited by grains.
Keywords arguments: Keywords arguments:
file -- File as string in base64 file -- File as string in base64
source_format -- Format of original file as string source_format -- Format of original file as string
zip -- Boolean Attribute. If true, returns the file in the form of a zip -- Boolean Attribute. If true, returns the grains in the form of a
zip archive zip archive
""" """
raise NotImplemented raise NotImplemented
# Pseudo Implementation done by rafael
GRANULATABLE_FORMAT_LIST = ("odt",) GRANULATABLE_FORMAT_LIST = ("odt",)
if source_format not in GRANULATABLE_FORMAT_LIST: if source_format not in GRANULATABLE_FORMAT_LIST:
file = self.convertFile(file, source_format, GRANULATABLE_FORMAT_LIST[0], zip=False) file = self.convertFile(file, source_format, GRANULATABLE_FORMAT_LIST[0], zip=False)
from granulate.oogranulate import OOGranulate from granulate.oogranulate import OOGranulate
document = OOGranulate(self._path_tmp_dir, document = OOGranulate(decodestring(file),
decodestring(file),
source_format) source_format)
grain_zip = document.granulate(zip=True) # Return a zip with all grains grains = document.granulate(zip)
# zip = content of a zip file.
return encodestring(grain_zip) return encodestring(grains)
def updateFileMetadata(self, file, source_format, metadata_dict): def updateFileMetadata(self, file, source_format, metadata_dict):
"""Receives the string of document and a dict with metadatas. The metadata """Receives the string of document and a dict with metadatas. The metadata
......
...@@ -98,7 +98,8 @@ class TestInterface(unittest.TestCase): ...@@ -98,7 +98,8 @@ class TestInterface(unittest.TestCase):
method_list = ['convertFile', method_list = ['convertFile',
'getFileMetadataItemList', 'getFileMetadataItemList',
'updateFileMetadata', 'updateFileMetadata',
'getAllowedExtensionList'] 'getAllowedExtensionList',
'granulateFile']
for method in method_list: for method in method_list:
self.assertEquals(method in IManager.names(), True) self.assertEquals(method in IManager.names(), True)
......
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