[Erp5-report] r43143 gabriel - in /erp5/trunk/utils/cloudooo/cloudooo: ./ handler/ooo/ hand...

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Feb 7 21:06:04 CET 2011


Author: gabriel
Date: Mon Feb  7 21:06:04 2011
New Revision: 43143

URL: http://svn.erp5.org?rev=43143&view=rev
Log:
move Document to be used by all handlers and renamed this class to be more generic. Then, is not necessary create new way to store files, only extend this class, if needed.

Added:
    erp5/trunk/utils/cloudooo/cloudooo/file.py
    erp5/trunk/utils/cloudooo/cloudooo/interfaces/file.py
      - copied, changed from r43003, erp5/trunk/utils/cloudooo/cloudooo/interfaces/document.py
Removed:
    erp5/trunk/utils/cloudooo/cloudooo/interfaces/document.py
Modified:
    erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/document.py
    erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/tests/testInterface.py

Added: erp5/trunk/utils/cloudooo/cloudooo/file.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/file.py?rev=43143&view=auto
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/file.py (added)
+++ erp5/trunk/utils/cloudooo/cloudooo/file.py [utf8] Mon Feb  7 21:06:04 2011
@@ -0,0 +1,142 @@
+##############################################################################
+#
+# Copyright (c) 2009-2010 Nexedi SA and Contributors. All Rights Reserved.
+#                    Gabriel M. Monnerat <gabriel 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 mimetypes
+import tempfile
+from os.path import join, exists, curdir, abspath
+from os import listdir, remove, chdir
+from zope.interface import implements
+from zipfile import ZipFile, is_zipfile
+from shutil import rmtree
+from cloudooo.interfaces.file import IFile
+
+
+class File(object):
+  """File is used to manipulate one temporary file
+  stored into the filesystem.
+  """
+  implements(IFile)
+
+  def __init__(self, base_folder_url, data, source_format):
+    """Create an file into file system and store the URL.
+    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()
+    self.original_data = data
+    self.source_format = source_format
+    self.url = self.load()
+
+  def _createDirectory(self):
+     return tempfile.mkdtemp(dir=self.base_folder_url)
+
+  def load(self):
+    """Creates one Temporary Document and write data into it.
+    Return the url for the document.
+    """
+    # creates only the url of the file.
+    file_path = tempfile.mktemp(suffix=".%s" % self.source_format,
+                                dir=self.directory_name)
+    # stores the data in temporary file
+    open(file_path, 'wb').write(self.original_data)
+    # If is a zipfile is need extract all files from whitin the compressed file
+    if is_zipfile(file_path):
+      zipfile = ZipFile(file_path)
+      zip_filename_list = zipfile.namelist()
+      if 'mimetype' not in zip_filename_list and \
+          '[Content_Types].xml' not in zip_filename_list:
+        zipfile_path = file_path
+        zipfile.extractall(path=self.directory_name)
+        zipfile.close()
+        filename_list = listdir(self.directory_name)
+        if 'index.html' in filename_list:
+          file_path = join(self.directory_name, 'index.html')
+        else:
+          mimetype_list = ['text/html', 'application/xhtml+xml']
+          for filename in filename_list:
+            if mimetypes.guess_type(filename)[0] in mimetype_list:
+              file_path = join(self.directory_name, filename)
+              break
+        if zipfile_path != file_path:
+          remove(zipfile_path)
+    return file_path
+
+  def getContent(self, zip=False):
+    """Open the file and returns the content.
+    Keyword Arguments:
+    zip -- Boolean attribute. If True"""
+    if zip:
+      current_dir_url = abspath(curdir)
+      chdir(self.directory_name)
+      zip_path = tempfile.mktemp(suffix=".zip", dir=self.directory_name)
+      file_list = listdir(self.directory_name)
+      zipfile = ZipFile(zip_path, 'w')
+      try:
+        for file in iter(file_list):
+          zipfile.write(file)
+      finally:
+        zipfile.close()
+      opened_zip = open(zip_path, 'r').read()
+      remove(zip_path)
+      chdir(current_dir_url)
+      return opened_zip
+    else:
+      return open(self.url, 'r').read()
+
+  def getUrl(self):
+    """Returns full path."""
+    return self.url
+
+  def restoreOriginal(self):
+    """Remake the document with the original document"""
+    self.trash()
+    self.directory_name = self._createDirectory()
+    self.url = self.load()
+
+  def reload(self, url=None):
+    """If the first document is temporary and another document is created. Use
+    reload to load the new document.
+
+    Keyword Arguments:
+    url -- Full path of the new document(default None)
+    """
+    if self.url != url and url is not None:
+      remove(self.url)
+      self.url = url
+
+  def trash(self):
+    """Remove the file in file system."""
+    if exists(self.directory_name):
+      rmtree(self.directory_name)
+      self.url = None
+
+  def __del__(self):
+    self.trash()

Modified: erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/document.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/document.py?rev=43143&r1=43142&r2=43143&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/document.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/document.py [utf8] Mon Feb  7 21:06:04 2011
@@ -26,123 +26,16 @@
 #
 ##############################################################################
 
-import mimetypes
-import tempfile
-from os.path import join, exists, curdir, abspath
-from os import listdir, remove, chdir
 from zope.interface import implements
-from zipfile import ZipFile, is_zipfile
-from shutil import rmtree
+from zipfile import ZipFile
 from StringIO import StringIO
 from lxml import etree
-from cloudooo.interfaces.document import IDocument, IOdfDocument
+from cloudooo.interfaces.file import IOdfDocument
+from cloudooo.file import File
 
 
-class FileSystemDocument(object):
-  """Filesystem Document is used to manipulate one temporary document
-  stored into the filesystem.
-  """
-  implements(IDocument)
-
-  def __init__(self, base_folder_url, data, source_format):
-    """Create an document into file system and store the URL.
-    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()
-    self.original_data = data
-    self.source_format = source_format
-    self.url = self.load()
-
-  def _createDirectory(self):
-     return tempfile.mkdtemp(dir=self.base_folder_url)
-
-  def load(self):
-    """Creates one Temporary Document and write data into it.
-    Return the url for the document.
-    """
-    # creates only the url of the file.
-    file_path = tempfile.mktemp(suffix=".%s" % self.source_format,
-                                dir=self.directory_name)
-    # stores the data in temporary file
-    open(file_path, 'wb').write(self.original_data)
-    # If is a zipfile is need extract all files from whitin the compressed file
-    if is_zipfile(file_path):
-      zipfile = ZipFile(file_path)
-      zip_filename_list = zipfile.namelist()
-      if 'mimetype' not in zip_filename_list and \
-          '[Content_Types].xml' not in zip_filename_list:
-        zipfile_path = file_path
-        zipfile.extractall(path=self.directory_name)
-        zipfile.close()
-        filename_list = listdir(self.directory_name)
-        if 'index.html' in filename_list:
-          file_path = join(self.directory_name, 'index.html')
-        else:
-          mimetype_list = ['text/html', 'application/xhtml+xml']
-          for filename in filename_list:
-            if mimetypes.guess_type(filename)[0] in mimetype_list:
-              file_path = join(self.directory_name, filename)
-              break
-        if zipfile_path != file_path:
-          remove(zipfile_path)
-    return file_path
-
-  def getContent(self, zip=False):
-    """Open the file and returns the content.
-    Keyword Arguments:
-    zip -- Boolean attribute. If True"""
-    if zip:
-      current_dir_url = abspath(curdir)
-      chdir(self.directory_name)
-      zip_path = tempfile.mktemp(suffix=".zip", dir=self.directory_name)
-      file_list = listdir(self.directory_name)
-      zipfile = ZipFile(zip_path, 'w')
-      try:
-        for file in iter(file_list):
-          zipfile.write(file)
-      finally:
-        zipfile.close()
-      opened_zip = open(zip_path, 'r').read()
-      remove(zip_path)
-      chdir(current_dir_url)
-      return opened_zip
-    else:
-      return open(self.url, 'r').read()
-
-  def getUrl(self):
-    """Returns full path."""
-    return self.url
-
-  def restoreOriginal(self):
-    """Remake the document with the original document"""
-    self.trash()
-    self.directory_name = self._createDirectory()
-    self.url = self.load()
-
-  def reload(self, url=None):
-    """If the first document is temporary and another document is created. Use
-    reload to load the new document.
-
-    Keyword Arguments:
-    url -- Full path of the new document(default None)
-    """
-    if self.url != url and url is not None:
-      remove(self.url)
-      self.url = url
-
-  def trash(self):
-    """Remove the file in file system."""
-    if exists(self.directory_name):
-      rmtree(self.directory_name)
-      self.url = None
-
-  def __del__(self):
-    self.trash()
-
+class FileSystemDocument(File):
+  pass
 
 class OdfDocument(object):
   """Manipulates odf documents in memory"""

Modified: erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/tests/testInterface.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/tests/testInterface.py?rev=43143&r1=43142&r2=43143&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/tests/testInterface.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/tests/testInterface.py [utf8] Mon Feb  7 21:06:04 2011
@@ -35,7 +35,7 @@ from cloudooo.handler.ooo.mimemapper imp
 from cloudooo.handler.ooo.filter import Filter
 from cloudooo.handler.ooo.monitor.request import MonitorRequest
 from cloudooo.handler.ooo.granulator import OOGranulator
-from cloudooo.interfaces.document import IDocument, IOdfDocument
+from cloudooo.interfaces.file import IFile, IOdfDocument
 from cloudooo.interfaces.lockable import ILockable
 from cloudooo.interfaces.manager import IManager
 from cloudooo.interfaces.application import IApplication
@@ -77,9 +77,9 @@ class TestInterface(unittest.TestCase):
     method_list = ['getImageItemList', 'getImage']
     self.assertEquals(IImageGranulator.names(), method_list)
 
-  def testIDocument(self):
-    """Test if FileSystemDocument implements IDocument"""
-    self.assertTrue(IDocument.implementedBy(FileSystemDocument))
+  def testIFile(self):
+    """Test if FileSystemDocument implements IFile"""
+    self.assertTrue(IFile.implementedBy(FileSystemDocument))
 
   def testIOdfDocument(self):
     """Test if OdfDocument implements IOdfDocument"""
@@ -91,7 +91,7 @@ class TestInterface(unittest.TestCase):
     self.assertEquals(IOdfDocument.names(), method_list)
 
   def testIFilter(self):
-    """Test if Filter implements IDocument"""
+    """Test if Filter implements IFile"""
     self.assertTrue(IFilter.implementedBy(Filter))
     self.assertEquals(IFilter.names(), ['getLabel', 'getName', 'getSortIndex',
       'isPreferred', 'getDocumentService', 'getExtension', 'getMimetype'])

Removed: erp5/trunk/utils/cloudooo/cloudooo/interfaces/document.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/interfaces/document.py?rev=43142&view=auto
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/interfaces/document.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/interfaces/document.py (removed)
@@ -1,74 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2009-2010 Nexedi SA and Contributors. All Rights Reserved.
-#                    Gabriel M. Monnerat <gabriel 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.
-#
-##############################################################################
-
-from zope.interface import Interface
-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")
-  directory_name = Attribute("String of directory name")
-  source_format = Attribute("Document Extension")
-  url = Attribute("Complete path of document in file system")
-  original_data = Attribute("Original data")
-
-  def load():
-    """From the data creates one archive into file system using original data"""
-
-  def reload(url):
-    """In the case of another file with the same content be created, pass the
-    url to load the new file"""
-
-  def getContent(zip):
-    """Returns data of document"""
-
-  def getUrl():
-    """Get the url of temporary file in file system"""
-
-  def trash():
-    """Remove the file in file system"""
-
-  def restoreOriginal():
-    """Restore the document with the original document"""
-
-
-class IOdfDocument(Interface):
-  """Manipulates odf documents in memory"""
-
-  source_format = Attribute("Document Extension")
-  parsed_content = Attribute("Content.xml parsed with lxml")
-
-  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"""

Copied: erp5/trunk/utils/cloudooo/cloudooo/interfaces/file.py (from r43003, erp5/trunk/utils/cloudooo/cloudooo/interfaces/document.py)
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/interfaces/file.py?p2=erp5/trunk/utils/cloudooo/cloudooo/interfaces/file.py&p1=erp5/trunk/utils/cloudooo/cloudooo/interfaces/document.py&r1=43003&r2=43143&rev=43143&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/interfaces/document.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/interfaces/file.py [utf8] Mon Feb  7 21:06:04 2011
@@ -30,7 +30,7 @@ from zope.interface import Interface
 from zope.interface import Attribute
 
 
-class IDocument(Interface):
+class IFile(Interface):
   """Manipulates documents in file system"""
 
   base_folder_url = Attribute("Url of folder that is used to create temporary \



More information about the Erp5-report mailing list