Commit f1283b30 authored by Jérome Perrin's avatar Jérome Perrin

remove unused import and wrap some lines > 79 chars


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14991 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f87386c9
...@@ -25,24 +25,20 @@ ...@@ -25,24 +25,20 @@
# #
############################################################################## ##############################################################################
import xmlrpclib, base64, re, zipfile, cStringIO, socket import xmlrpclib, base64, re, zipfile, cStringIO
from warnings import warn from warnings import warn
from DateTime import DateTime
from xmlrpclib import Fault from xmlrpclib import Fault
from xmlrpclib import Transport from xmlrpclib import Transport
from xmlrpclib import SafeTransport from xmlrpclib import SafeTransport
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from OFS.Image import Pdata from OFS.Image import Pdata
from Products.CMFCore.utils import getToolByName, _setCacheHeaders from Products.CMFCore.utils import getToolByName, _setCacheHeaders
from Products.DCWorkflow.DCWorkflow import ValidationFailed
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5Type.Message import Message
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5.Document.File import File from Products.ERP5.Document.File import File
from Products.ERP5.Document.Document import ConversionCacheMixin, ConversionError from Products.ERP5.Document.Document import ConversionCacheMixin, ConversionError
from Products.ERP5.Document.File import _unpackData from Products.ERP5.Document.File import _unpackData
from zLOG import LOG, INFO, ERROR from zLOG import LOG, ERROR
enc=base64.encodestring enc=base64.encodestring
dec=base64.decodestring dec=base64.decodestring
...@@ -182,8 +178,8 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -182,8 +178,8 @@ class OOoDocument(File, ConversionCacheMixin):
address = preference_tool.getPreferredOoodocServerAddress() address = preference_tool.getPreferredOoodocServerAddress()
port = preference_tool.getPreferredOoodocServerPortNumber() port = preference_tool.getPreferredOoodocServerPortNumber()
if address in ('', None) or port in ('', None) : if address in ('', None) or port in ('', None) :
raise ConversionError('''[DMS] Can not proceed with conversion: raise ConversionError('[DMS] Can not proceed with conversion:'
conversion server host and port is not defined in preferences''') ' conversion server host and port is not defined in preferences')
return address, port return address, port
def _mkProxy(self): def _mkProxy(self):
...@@ -228,8 +224,9 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -228,8 +224,9 @@ class OOoDocument(File, ConversionCacheMixin):
else: else:
# This is very temporary code - XXX needs to be changed # This is very temporary code - XXX needs to be changed
# so that the system can retry # so that the system can retry
raise ConversionError("[DMS] Can not get list of allowed acceptable formats for conversion: %s (%s)" raise ConversionError("[DMS] Can not get list of allowed acceptable"
%(response_code, response_message)) " formats for conversion: %s (%s)" % (
response_code, response_message))
except Fault, f: except Fault, f:
allowed = server_proxy.getAllowedTargets(content_type) allowed = server_proxy.getAllowedTargets(content_type)
...@@ -248,21 +245,24 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -248,21 +245,24 @@ class OOoDocument(File, ConversionCacheMixin):
return cached_getTargetFormatItemList(self.getBaseContentType()) return cached_getTargetFormatItemList(self.getBaseContentType())
security.declareProtected(Permissions.AccessContentsInformation, 'getTargetFormatTitleList') security.declareProtected(Permissions.AccessContentsInformation,
'getTargetFormatTitleList')
def getTargetFormatTitleList(self): def getTargetFormatTitleList(self):
""" """
Returns a list of acceptable formats for conversion Returns a list of acceptable formats for conversion
""" """
return map(lambda x: x[0], self.getTargetFormatItemList()) return map(lambda x: x[0], self.getTargetFormatItemList())
security.declareProtected(Permissions.AccessContentsInformation, 'getTargetFormatList') security.declareProtected(Permissions.AccessContentsInformation,
'getTargetFormatList')
def getTargetFormatList(self): def getTargetFormatList(self):
""" """
Returns a list of acceptable formats for conversion Returns a list of acceptable formats for conversion
""" """
return map(lambda x: x[1], self.getTargetFormatItemList()) return map(lambda x: x[1], self.getTargetFormatItemList())
security.declareProtected(Permissions.ModifyPortalContent,'isTargetFormatAllowed') security.declareProtected(Permissions.ModifyPortalContent,
'isTargetFormatAllowed')
def isTargetFormatAllowed(self, format): def isTargetFormatAllowed(self, format):
""" """
Checks if the current document can be converted Checks if the current document can be converted
...@@ -307,10 +307,10 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -307,10 +307,10 @@ class OOoDocument(File, ConversionCacheMixin):
# Conversion API # Conversion API
security.declareProtected(Permissions.View, 'convert') security.declareProtected(Permissions.View, 'convert')
def convert(self, format, display=None, **kw): def convert(self, format, display=None, **kw):
""" """Convert the document to the given format.
Implementation of thGet file in a given format.
Runs makeFile to make sure we have the requested version cached, If a conversion is already stored for this format, it is returned
then returns from cache. directly, otherwise the conversion is stored for the next time.
""" """
# Make sure we can support html and pdf by default # Make sure we can support html and pdf by default
is_html = 0 is_html = 0
...@@ -319,13 +319,16 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -319,13 +319,16 @@ class OOoDocument(File, ConversionCacheMixin):
if not self.hasBaseData(): self.convertToBaseFormat() if not self.hasBaseData(): self.convertToBaseFormat()
return self.getBaseContentType(), self.getBaseData() return self.getBaseContentType(), self.getBaseData()
if format == 'pdf': if format == 'pdf':
format_list = [x for x in self.getTargetFormatList() if x.endswith('pdf')] format_list = [x for x in self.getTargetFormatList()
if x.endswith('pdf')]
format = format_list[0] format = format_list[0]
elif format in STANDARD_IMAGE_FORMAT_LIST: elif format in STANDARD_IMAGE_FORMAT_LIST:
format_list = [x for x in self.getTargetFormatList() if x.endswith(format)] format_list = [x for x in self.getTargetFormatList()
if x.endswith(format)]
format = format_list[0] format = format_list[0]
elif format == 'html': elif format == 'html':
format_list = [x for x in self.getTargetFormatList() if x.startswith('html') or x.endswith('html')] format_list = [x for x in self.getTargetFormatList()
if x.startswith('html') or x.endswith('html')]
format = format_list[0] format = format_list[0]
is_html = 1 is_html = 1
elif format in ('txt', 'text', 'text-content'): elif format in ('txt', 'text', 'text-content'):
...@@ -390,14 +393,16 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -390,14 +393,16 @@ class OOoDocument(File, ConversionCacheMixin):
""" """
return self._convert(format='text-content') return self._convert(format='text-content')
security.declareProtected(Permissions.ModifyPortalContent, 'populateContent') security.declareProtected(Permissions.ModifyPortalContent,
'populateContent')
def populateContent(self, zip_file=None): def populateContent(self, zip_file=None):
""" """
Extract content from the ODF zip file and populate the document. Extract content from the ODF zip file and populate the document.
Optional parameter zip_file prevents from converting content twice. Optional parameter zip_file prevents from converting content twice.
""" """
if zip_file is None: if zip_file is None:
format_list = [x for x in self.getTargetFormatList() if x.startswith('html')] format_list = [x for x in self.getTargetFormatList()
if x.startswith('html')]
format = format_list[0] format = format_list[0]
mime, data = self._convert(format) mime, data = self._convert(format)
archive_file = cStringIO.StringIO() archive_file = cStringIO.StringIO()
...@@ -428,7 +433,8 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -428,7 +433,8 @@ class OOoDocument(File, ConversionCacheMixin):
on the object. Update metadata information. on the object. Update metadata information.
""" """
server_proxy = self._mkProxy() server_proxy = self._mkProxy()
response_code, response_dict, response_message = server_proxy.run_convert(self.getSourceReference() or self.getId(), response_code, response_dict, response_message = server_proxy.run_convert(
self.getSourceReference() or self.getId(),
enc(_unpackData(self.getData()))) enc(_unpackData(self.getData())))
if response_code == 200: if response_code == 200:
# sucessfully converted document # sucessfully converted document
...@@ -438,12 +444,17 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -438,12 +444,17 @@ class OOoDocument(File, ConversionCacheMixin):
if metadata.get('MIMEType', None) is not None: if metadata.get('MIMEType', None) is not None:
self._setBaseContentType(metadata['MIMEType']) self._setBaseContentType(metadata['MIMEType'])
else: else:
# log and raise errors with converting server.Explicitly raise the exception! # log and raise errors with converting server.
LOG('[DMS]', ERROR, 'Error converting document to base format %s:%s' %(response_code, response_message)) LOG('ERP5OOo', ERROR,
raise ConversionError("[DMS] Error converting document to base format %s:%s:" '[DMS] Error converting document to base format %s:%s'
% (response_code, response_message))
# Explicitly raise the exception!
raise ConversionError(
"[DMS] Error converting document to base format %s:%s:"
%(response_code, response_message)) %(response_code, response_message))
security.declareProtected(Permissions.AccessContentsInformation, 'getContentInformation') security.declareProtected(Permissions.AccessContentsInformation,
'getContentInformation')
def getContentInformation(self): def getContentInformation(self):
""" """
Returns the metadata extracted by the conversion Returns the metadata extracted by the conversion
...@@ -451,7 +462,8 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -451,7 +462,8 @@ class OOoDocument(File, ConversionCacheMixin):
""" """
return self._base_metadata return self._base_metadata
security.declareProtected(Permissions.ModifyPortalContent, 'updateBaseMetadata') security.declareProtected(Permissions.ModifyPortalContent,
'updateBaseMetadata')
def updateBaseMetadata(self, *arg, **kw): def updateBaseMetadata(self, *arg, **kw):
""" """
Updates metadata information in the converted OOo document Updates metadata information in the converted OOo document
...@@ -459,13 +471,18 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -459,13 +471,18 @@ class OOoDocument(File, ConversionCacheMixin):
through the invocation of the conversion server. through the invocation of the conversion server.
""" """
server_proxy = self._mkProxy() server_proxy = self._mkProxy()
response_code, response_dict, response_message = server_proxy.run_setmetadata(self.getId(), response_code, response_dict, response_message = \
server_proxy.run_setmetadata(self.getId(),
enc(_unpackData(self.getBaseData())), enc(_unpackData(self.getBaseData())),
kw) kw)
if response_code == 200: if response_code == 200:
# successful meta data extraction # successful meta data extraction
self._setBaseData(dec(response_dict['data'])) self._setBaseData(dec(response_dict['data']))
else: else:
# log and raise errors with converting server.Explicitly raise the exception! # log and raise errors with converting server.
LOG('[DMS]', ERROR, "Error getting document's metadata %s:%s" %(response_code, response_message)) LOG('ERP5OOo', ERROR, "[DMS] Error getting document's metadata %s:%s"
raise ConversionError("[DMS] Error getting document's metadata %s:%s" %(response_code, response_message)) % (response_code, response_message))
# Explicitly raise the exception!
raise ConversionError("[DMS] Error getting document's metadata %s:%s"
% (response_code, response_message))
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