[Erp5-report] r42232 gabriel.oliveira - in /experimental/bt5/erp5_dms_media: DocumentTempla...

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Jan 11 18:54:48 CET 2011


Author: gabriel.oliveira
Date: Tue Jan 11 18:54:48 2011
New Revision: 42232

URL: http://svn.erp5.org?rev=42232&view=rev
Log:
2011-01-11 gabriel.oliveira
* Try to create new portal type Video, that will handle Video files.

2010-12-09 gabriel.oliveira
* Initial build

Added:
    experimental/bt5/erp5_dms_media/DocumentTemplateItem/
    experimental/bt5/erp5_dms_media/DocumentTemplateItem/Video.py
    experimental/bt5/erp5_dms_media/bt/template_document_id_list
Modified:
    experimental/bt5/erp5_dms_media/PortalTypeTemplateItem/portal_types/Video.xml
    experimental/bt5/erp5_dms_media/SkinTemplateItem/portal_skins/erp5_dms_media/VideoModule_viewVideoList.xml
    experimental/bt5/erp5_dms_media/bt/revision

Added: experimental/bt5/erp5_dms_media/DocumentTemplateItem/Video.py
URL: http://svn.erp5.org/experimental/bt5/erp5_dms_media/DocumentTemplateItem/Video.py?rev=42232&view=auto
==============================================================================
--- experimental/bt5/erp5_dms_media/DocumentTemplateItem/Video.py (added)
+++ experimental/bt5/erp5_dms_media/DocumentTemplateItem/Video.py [utf8] Tue Jan 11 18:54:48 2011
@@ -0,0 +1,282 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Copyright (c) 2002-2006 Nexedi SARL and Contributors. All Rights Reserved.
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability 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
+# garantees 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 tempfile, os
+
+from AccessControl import ClassSecurityInfo
+#from Products.CMFCore.utils import getToolByName, _setCacheHeaders,\
+#    _ViewEmulator
+
+from Products.ERP5Type import Permissions, PropertySheet
+from Products.ERP5.Document.Image import Image
+#from Products.ERP5.Document.Document import ConversionError,\
+#                                            VALID_TEXT_FORMAT_LIST
+#from subprocess import Popen, PIPE
+#import errno
+
+class Video(Image):
+  """
+  FIXME
+  TODO: Video is a subclass of Image which is able to
+  extract text? I think it isn't.
+  """
+  # CMF Type Definition
+  meta_type = 'ERP5 Video'
+  portal_type = 'Video'
+
+  # Declarative security
+  security = ClassSecurityInfo()
+  security.declareObjectProtected(Permissions.AccessContentsInformation)
+
+  # Default Properties
+  property_sheets = ( PropertySheet.Base
+                    , PropertySheet.XMLObject
+                    , PropertySheet.CategoryCore
+                    , PropertySheet.DublinCore
+                    , PropertySheet.Version
+                    , PropertySheet.Reference
+                    , PropertySheet.Document
+                    , PropertySheet.Data
+                    , PropertySheet.ExternalDocument
+                    , PropertySheet.Url
+                    , PropertySheet.Periodicity
+                    )
+
+  # Conversion API
+  def _convert(self, format, **kw):
+    """
+    Implementation of conversion for Video files
+    """
+##    if format == 'html':
+##      try:
+##        return self.getConversion(format=format)
+##      except KeyError:
+##        mime = 'text/html'
+##        data = self._convertToHTML()
+##        self.setConversion(data, mime=mime, format=format)
+##        return (mime, data)
+##    elif format in ('txt', 'text'):
+##      try:
+##        return self.getConversion(format='txt')
+##      except KeyError:
+##        mime = 'text/plain'
+##        data = self._convertToText()
+##        self.setConversion(data, mime=mime, format='txt')
+##        return (mime, data)
+##    elif format is None:
+##      return self.getContentType(), self.getData()
+##    else:
+##      if kw.get('frame', None) is None:
+##        # when converting to image from PDF we care for first page only
+##        # this will make sure that only first page is used and not whole content of
+##        # PDF file read & converted which is a performance issue
+##        kw['frame'] = 0
+##      return Image._convert(self, format, **kw)
+    raise NotImplementedError
+
+##  security.declareProtected(Permissions.ModifyPortalContent, 'populateContent')
+##  def populateContent(self):
+##    """
+##      Convert each page to an Image and populate the
+##      PDF directory with converted images. May be useful
+##      to provide online PDF reader
+##    """
+##    raise NotImplementedError
+
+  security.declarePrivate('_convertToText')
+  def _convertToText(self):
+##    """
+##      Convert the PDF text content to text with pdftotext
+##    """
+##    if not self.hasData():
+##      return ''
+##    tmp = tempfile.NamedTemporaryFile()
+##    tmp.write(self.getData())
+##    tmp.seek(0)
+##    try:
+##      command = ['pdftotext', '-layout', '-enc', 'UTF-8',
+##                 '-nopgbrk', tmp.name, '-']
+##      try:
+##        command_result = Popen(command, stdout=PIPE).communicate()[0]
+##      except OSError, e:
+##        if e.errno == errno.ENOENT:
+##          raise ConversionError('pdftotext was not found')
+##        raise
+##    finally:
+##      tmp.close()
+##    if command_result:
+##      return command_result
+##    else:
+##      # Try to use OCR
+##      # As high dpi images are required, it may take some times to convert the
+##      # pdf.
+##      # It may be required to use activities to fill the cache and at the end,
+##      # to calculate the final result
+##      text = ''
+##      content_information = self.getContentInformation()
+##      page_count = int(content_information.get('Pages', 0))
+##      for page_number in range(page_count):
+##        src_mimetype, png_data = self.convert(
+##            'png', quality=100, resolution=300,
+##            frame=page_number, display='identical')
+##        if not src_mimetype.endswith('png'):
+##          continue
+##        content = '%s' % png_data
+##        mime_type = 'text/plain'
+##        if content is not None:
+##          portal_transforms = getToolByName(self, 'portal_transforms')
+##          result = portal_transforms.convertToData(mime_type, content,
+##                                                   context=self,
+##                                                   filename=self.getTitleOrId(),
+##                                                   mimetype=src_mimetype)
+##          if result is None:
+##            raise ConversionError('PDFDocument conversion error. '
+##                                  'portal_transforms failed to convert to %s: %r' % (mime_type, self))
+##          text += result
+##      return text
+    raise NotImplementedError
+
+##  security.declareProtected(Permissions.View, 'getSizeFromImageDisplay')
+##  def getSizeFromImageDisplay(self, image_display):
+##    """
+##    Return the size for this image display, or None if this image display name
+##    is not known. If the preference is not set, (0, 0) is returned.
+##    """
+##    # identical parameter can be considered as a hack, in order not to
+##    # resize the image to prevent text distorsion when using OCR.
+##    # A cleaner API is required.
+##    if image_display == 'identical':
+##      return (self.getWidth(), self.getHeight())
+##    else:
+##      return Image.getSizeFromImageDisplay(self, image_display)
+
+##  security.declarePrivate('_convertToHTML')
+##  def _convertToHTML(self):
+##    """
+##    Convert the PDF text content to HTML with pdftohtml
+
+##    NOTE: XXX check that command exists and was executed
+##    successfully
+##    """
+##    if not self.hasData():
+##      return ''
+##    tmp = tempfile.NamedTemporaryFile()
+##    tmp.write(self.getData())
+##    tmp.seek(0)
+
+##    command_result = None
+##    try:
+##      command = ['pdftohtml', '-enc', 'UTF-8', '-stdout',
+##                 '-noframes', '-i', tmp.name]
+##      try:
+##        command_result = Popen(command, stdout=PIPE).communicate()[0]
+##      except OSError, e:
+##        if e.errno == errno.ENOENT:
+##          raise ConversionError('pdftohtml was not found')
+##        raise
+
+##    finally:
+##      tmp.close()
+##    # Quick hack to remove bg color - XXX
+##    h = command_result.replace('<BODY bgcolor="#A0A0A0"', '<BODY ')
+##    # Make links relative
+##    h = h.replace('href="%s.html' % tmp.name.split(os.sep)[-1],
+##                                                          'href="asEntireHTML')
+##    return h
+
+  security.declareProtected(Permissions.AccessContentsInformation, 'getContentInformation')
+  def getContentInformation(self):
+##    """
+##    Returns the information about the PDF document with
+##    pdfinfo.
+
+##    NOTE: XXX check that command exists and was executed
+##    successfully
+##    """
+##    try:
+##      return self._content_information.copy()
+##    except AttributeError:
+##      pass
+##    tmp = tempfile.NamedTemporaryFile()
+##    tmp.write(self.getData())
+##    tmp.seek(0)
+##    command_result = None
+##    try:
+
+##      # First, we use pdfinfo to get standard metadata
+##      command = ['pdfinfo', '-meta', '-box', tmp.name]
+##      try:
+##        command_result = Popen(command, stdout=PIPE).communicate()[0]
+##      except OSError, e:
+##        if e.errno == errno.ENOENT:
+##          raise ConversionError('pdfinfo was not found')
+##        raise
+
+##      result = {}
+##      for line in command_result.splitlines():
+##        item_list = line.split(':')
+##        key = item_list[0].strip()
+##        value = ':'.join(item_list[1:]).strip()
+##        result[key] = value
+
+##      # Then we use pdftk to get extra metadata
+##      try:
+##        command = ['pdftk', tmp.name, 'dump_data', 'output']
+##        command_result = Popen(command, stdout=PIPE).communicate()[0]
+##      except OSError, e:
+##        # if pdftk not found, pass
+##        if e.errno != errno.ENOENT:
+##          raise
+##      else:
+##        line_list = (line for line in command_result.splitlines())
+##        while True:
+##          try:
+##            line = line_list.next()
+##          except StopIteration:
+##            break
+##          if line.startswith('InfoKey'):
+##            key = line[len('InfoKey: '):]
+##            line = line_list.next()
+##            assert line.startswith('InfoValue: '),\
+##                "Wrong format returned by pdftk dump_data"
+##            value = line[len('InfoValue: '):]
+##            result.setdefault(key, value)
+##    finally:
+##      tmp.close()
+
+##    self._content_information = result
+##    return result.copy()
+    raise NotImplementedError
+
+  def _setFile(self, data, precondition=None):
+##    try:
+##      del self._content_information
+##    except (AttributeError, KeyError):
+##      pass
+    Image._setFile(self, data, precondition=precondition)
+

Modified: experimental/bt5/erp5_dms_media/PortalTypeTemplateItem/portal_types/Video.xml
URL: http://svn.erp5.org/experimental/bt5/erp5_dms_media/PortalTypeTemplateItem/portal_types/Video.xml?rev=42232&r1=42231&r2=42232&view=diff
==============================================================================
--- experimental/bt5/erp5_dms_media/PortalTypeTemplateItem/portal_types/Video.xml [utf8] (original)
+++ experimental/bt5/erp5_dms_media/PortalTypeTemplateItem/portal_types/Video.xml [utf8] Tue Jan 11 18:54:48 2011
@@ -105,7 +105,7 @@
         </item>
         <item>
             <key> <string>type_class</string> </key>
-            <value> <string>File</string> </value>
+            <value> <string>Video</string> </value>
         </item>
         <item>
             <key> <string>type_mixin</string> </key>

Modified: experimental/bt5/erp5_dms_media/SkinTemplateItem/portal_skins/erp5_dms_media/VideoModule_viewVideoList.xml
URL: http://svn.erp5.org/experimental/bt5/erp5_dms_media/SkinTemplateItem/portal_skins/erp5_dms_media/VideoModule_viewVideoList.xml?rev=42232&r1=42231&r2=42232&view=diff
==============================================================================
--- experimental/bt5/erp5_dms_media/SkinTemplateItem/portal_skins/erp5_dms_media/VideoModule_viewVideoList.xml [utf8] (original)
+++ experimental/bt5/erp5_dms_media/SkinTemplateItem/portal_skins/erp5_dms_media/VideoModule_viewVideoList.xml [utf8] Tue Jan 11 18:54:48 2011
@@ -7,6 +7,27 @@
     <pickle>
       <dictionary>
         <item>
+            <key> <string>_bind_names</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>_asgns</string> </key>
+                        <value>
+                          <dictionary/>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
             <key> <string>_objects</string> </key>
             <value>
               <tuple/>

Modified: experimental/bt5/erp5_dms_media/bt/revision
URL: http://svn.erp5.org/experimental/bt5/erp5_dms_media/bt/revision?rev=42232&r1=42231&r2=42232&view=diff
==============================================================================
--- experimental/bt5/erp5_dms_media/bt/revision [utf8] (original)
+++ experimental/bt5/erp5_dms_media/bt/revision [utf8] Tue Jan 11 18:54:48 2011
@@ -1 +1 @@
-4
\ No newline at end of file
+8
\ No newline at end of file

Added: experimental/bt5/erp5_dms_media/bt/template_document_id_list
URL: http://svn.erp5.org/experimental/bt5/erp5_dms_media/bt/template_document_id_list?rev=42232&view=auto
==============================================================================
--- experimental/bt5/erp5_dms_media/bt/template_document_id_list (added)
+++ experimental/bt5/erp5_dms_media/bt/template_document_id_list [utf8] Tue Jan 11 18:54:48 2011
@@ -0,0 +1 @@
+Video
\ No newline at end of file



More information about the Erp5-report mailing list