diff --git a/integrator/interfaces.py b/integrator/interfaces.py index 4d2a4bd..afde0de 100644 --- a/integrator/interfaces.py +++ b/integrator/interfaces.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2011 Helmut Merz helmutm@cy55.de +# Copyright (c) 2014 Helmut Merz helmutm@cy55.de # # 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 @@ -18,8 +18,6 @@ """ Integrator interfaces. - -$Id$ """ from zope.interface import Interface, Attribute @@ -133,3 +131,5 @@ class IOfficeFile(IExternalFile): It provides access to the document content and properties. """ + documentPropertiesAccessible = Attribute( + 'Are document properties accessible?') diff --git a/integrator/office/base.py b/integrator/office/base.py index 542aa0a..3e0cb9f 100644 --- a/integrator/office/base.py +++ b/integrator/office/base.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013 Helmut Merz helmutm@cy55.de +# Copyright (c) 2014 Helmut Merz helmutm@cy55.de # # 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 @@ -26,7 +26,7 @@ from lxml import etree import os import shutil from time import strptime -from zipfile import ZipFile +from zipfile import ZipFile, BadZipfile from zope.cachedescriptors.property import Lazy from zope import component from zope.component import adapts @@ -52,12 +52,22 @@ class OfficeFile(ExternalFileAdapter): implements(IOfficeFile) + _adapterAttributes = (ExternalFileAdapter._adapterAttributes + + ('documentPropertiesAccessible',)) + propertyMap = {u'Revision:': 'version'} propFileName = 'docProps/custom.xml' corePropFileName = 'docProps/core.xml' fileExtensions = ('.docm', '.docx', 'dotm', 'dotx', 'pptx', 'potx', 'ppsx', '.xlsm', '.xlsx', '.xltm', '.xltx') + def getDocumentPropertiesAccessible(self): + return getattr(self.context, '_documentPropertiesAccessible', True) + def setDocumentPropertiesAccessible(self, value): + self.context._documentPropertiesAccessible = value + documentPropertiesAccessible = property( + getDocumentPropertiesAccessible, setDocumentPropertiesAccessible) + @Lazy def logger(self): return getLogger('loops.integrator.office.base.OfficeFile') @@ -84,9 +94,10 @@ class OfficeFile(ExternalFileAdapter): return result try: zf = ZipFile(fn, 'r') - except IOError, e: + except (IOError, BadZipfile), e: from logging import getLogger self.logger.warn(e) + self.documentPropertiesAccessible = False return result if self.corePropFileName not in zf.namelist(): self.logger.warn('Core properties not found in file %s.' % @@ -123,6 +134,8 @@ class OfficeFile(ExternalFileAdapter): attributes = {} # get dc:description from core.xml desc = self.getCoreProperty('description') + if not self.documentPropertiesAccessible: + return if desc is not None: attributes['comments'] = desc dom = self.docPropertyDom['custom']