[Erp5-report] r40566 hugo.maia - in /erp5/trunk/utils/cloudooo/cloudooo: ./ interfaces/ tes...
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Nov 23 22:32:27 CET 2010
Author: hugo.maia
Date: Tue Nov 23 22:32:27 2010
New Revision: 40566
URL: http://svn.erp5.org?rev=40566&view=rev
Log:
Add OdfDocument
Added:
erp5/trunk/utils/cloudooo/cloudooo/tests/data/granulate_test.odt (with props)
erp5/trunk/utils/cloudooo/cloudooo/tests/testOdfDocument.py
Modified:
erp5/trunk/utils/cloudooo/cloudooo/CHANGES.txt
erp5/trunk/utils/cloudooo/cloudooo/document.py
erp5/trunk/utils/cloudooo/cloudooo/interfaces/document.py
erp5/trunk/utils/cloudooo/cloudooo/tests/testInterface.py
Modified: erp5/trunk/utils/cloudooo/cloudooo/CHANGES.txt
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/CHANGES.txt?rev=40566&r1=40565&r2=40566&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/CHANGES.txt [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/CHANGES.txt [utf8] Tue Nov 23 22:32:27 2010
@@ -1,5 +1,6 @@
1.0.10 (unreleased)
===================
+ - Add OdfDocument
- Add granulate interface.
1.0.9
@@ -13,9 +14,10 @@
=====
- Remove all attributes that works with cloudooo script paths.
- Use all scripts according to your python eggs.
- - Fixed problem when a spreadsheet will be converted to html.
+ - Fixed problem when a spreadsheet will be converted to html.
1.0.7
=====
- Remove entry points, treat those as ordinary files.
- Search all script files using pkg_resources.
+
Modified: erp5/trunk/utils/cloudooo/cloudooo/document.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/document.py?rev=40566&r1=40565&r2=40566&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/document.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/document.py [utf8] Tue Nov 23 22:32:27 2010
@@ -27,13 +27,14 @@
##############################################################################
import mimetypes
+import tempfile
from os.path import join, exists, curdir, abspath
from os import listdir, remove, chdir
from zope.interface import implements
-from interfaces.document import IDocument
from zipfile import ZipFile, is_zipfile
from shutil import rmtree
-import tempfile
+from StringIO import StringIO
+from interfaces.document import IDocument, IOdfDocument
class FileSystemDocument(object):
@@ -47,6 +48,7 @@ class FileSystemDocument(object):
Keyword arguments:
base_folder_url -- Full path to create a temporary folder
data -- Content of the document
+ source_format -- Document Extension
"""
self.base_folder_url = base_folder_url
self.directory_name = self._createDirectory()
@@ -136,3 +138,30 @@ class FileSystemDocument(object):
def __del__(self):
self.trash()
+
+
+class OdfDocument(object):
+ """Manipulates odf documents in memory"""
+
+ implements(IOdfDocument)
+
+ def __init__(self, data, source_format):
+ """Open the the file in memory.
+
+ Keyword arguments:
+ data -- Content of the document
+ source_format -- Document Extension
+ """
+ self._zipfile = ZipFile(StringIO(data))
+ self.source_format = source_format
+
+ def getContentXml(self):
+ """Returns the content.xml file as string"""
+ return self._zipfile.read('content.xml')
+
+ def getFile(self, path):
+ """If exists, returns file as string, else return None"""
+ try:
+ return self._zipfile.read(path)
+ except KeyError:
+ return None
Modified: erp5/trunk/utils/cloudooo/cloudooo/interfaces/document.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/interfaces/document.py?rev=40566&r1=40565&r2=40566&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/interfaces/document.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/interfaces/document.py [utf8] Tue Nov 23 22:32:27 2010
@@ -33,7 +33,8 @@ from zope.interface import Attribute
class IDocument(Interface):
"""Manipulates documents in file system"""
- base_folder_url = Attribute("Url of folder that is used to create temporary files")
+ base_folder_url = Attribute("Url of folder that is used to create temporary \
+ files")
directory_name = Attribute("String of directory name")
source_format = Attribute("Document Extension")
url = Attribute("Complete path of document in file system")
@@ -57,3 +58,16 @@ class IDocument(Interface):
def restoreOriginal():
"""Restore the document with the original document"""
+
+
+class IOdfDocument(Interface):
+ """Manipulates odf documents in memory"""
+
+ source_format = Attribute("Document Extension")
+
+ def getContentXml():
+ """Returns the content.xml file as string"""
+
+ def getFile(path):
+ """Returns, as string, the file located in the given path, inside de odf
+ file"""
Added: erp5/trunk/utils/cloudooo/cloudooo/tests/data/granulate_test.odt
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/tests/data/granulate_test.odt?rev=40566&view=auto
==============================================================================
Binary file - no diff available.
Propchange: erp5/trunk/utils/cloudooo/cloudooo/tests/data/granulate_test.odt
------------------------------------------------------------------------------
svn:executable = *
Propchange: erp5/trunk/utils/cloudooo/cloudooo/tests/data/granulate_test.odt
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: erp5/trunk/utils/cloudooo/cloudooo/tests/testInterface.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/tests/testInterface.py?rev=40566&r1=40565&r2=40566&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/tests/testInterface.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/tests/testInterface.py [utf8] Tue Nov 23 22:32:27 2010
@@ -27,7 +27,7 @@
##############################################################################
import unittest
-from cloudooo.document import FileSystemDocument
+from cloudooo.document import FileSystemDocument, OdfDocument
from cloudooo.handler.oohandler import OOHandler
from cloudooo.application.openoffice import OpenOffice
from cloudooo.manager import Manager
@@ -36,7 +36,7 @@ from cloudooo.filter import Filter
from cloudooo.application.xvfb import Xvfb
from cloudooo.monitor.request import MonitorRequest
from cloudooo.granulate.oogranulate import OOGranulate
-from cloudooo.interfaces.document import IDocument
+from cloudooo.interfaces.document import IDocument, IOdfDocument
from cloudooo.interfaces.lockable import ILockable
from cloudooo.interfaces.manager import IManager
from cloudooo.interfaces.application import IApplication
@@ -78,6 +78,14 @@ class TestInterface(unittest.TestCase):
"""Test if FileSystemDocument implements IDocument"""
self.assertEquals(IDocument.implementedBy(FileSystemDocument), True)
+ def testIOdfDocument(self):
+ """Test if OdfDocument implements IOdfDocument"""
+ self.assertEquals(IOdfDocument.implementedBy(OdfDocument), True)
+ method_list = ['getFile',
+ 'getContentXml',
+ 'source_format']
+ self.assertEquals(IOdfDocument.names(), method_list)
+
def testIFilter(self):
"""Test if Filter implements IDocument"""
self.assertEquals(IFilter.implementedBy(Filter), True)
Added: erp5/trunk/utils/cloudooo/cloudooo/tests/testOdfDocument.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/tests/testOdfDocument.py?rev=40566&view=auto
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/tests/testOdfDocument.py (added)
+++ erp5/trunk/utils/cloudooo/cloudooo/tests/testOdfDocument.py [utf8] Tue Nov 23 22:32:27 2010
@@ -0,0 +1,65 @@
+##############################################################################
+#
+# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
+# Hugo H. Maia Vieira <hugomaia at tiolive.com>
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsibility of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# guarantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+##############################################################################
+
+import unittest
+from zipfile import ZipFile
+from cloudoooTestCase import cloudoooTestCase, make_suite
+from cloudooo.document import OdfDocument
+
+class TestOdfDocument(cloudoooTestCase):
+
+ def setUp(self):
+ data = open('./data/granulate_test.odt').read()
+ self.oodocument = OdfDocument(data, 'odt')
+
+ def testReceivedGoodFile(self):
+ """Test if received path is from a good document returing an ZipFile"""
+ self.assertEquals(isinstance(self.oodocument._zipfile, ZipFile), True)
+
+ def testGetContentXml(self):
+ """Test if the getContentXml method returns the content.xml file"""
+ content_xml = self.oodocument.getContentXml()
+ self.assertEquals('The content of this file is just' in content_xml, True)
+
+ def testGetExistentFile(self):
+ """Test if the getFile method returns the requested file"""
+ requested_file = self.oodocument.getFile('content.xml')
+ self.assertEquals(requested_file, self.oodocument.getContentXml())
+
+ def testGetNotPresentFile(self):
+ """Test if the getFile method returns None for not present file request"""
+ requested_file = self.oodocument.getFile('not_present.xml')
+ self.assertEquals(requested_file, None)
+
+
+def test_suite():
+ return make_suite(TestOdfDocument)
+
+if __name__ == "__main__":
+ suite = unittest.TestLoader().loadTestsFromTestCase(TestOdfDocument)
+ unittest.TextTestRunner(verbosity=2).run(suite)
More information about the Erp5-report
mailing list