Re: Pb lors de la réindexation des documents

Yves Bastide <[email protected]>
Newsgroups gmane.comp.web.zope.cps.general.french
Message-ID <[email protected]>
Christophe Otton wrote:
> Bonjour,
> 
> J'ai toujours mon pb de réindexation et quelques difficultés à savoir 
> d'où ça vient.
> 
> Mon premier souci serait de comprendre les messages d'erreur du 
> event.log / est-ce que quelqu'un peut m'aider à déchiffrer ce type de 
> message :
> 
>> 2006-10-16T21:15:09 PROBLEM(100) FilteredSet eval() failed
>> Object: document.html, expr: getattr(o, 'portal_type', None) not in 
>> ('Section', 'Workspace')
>> Traceback (most recent call last):
>>   File 
>> "/home/zope/Zope-2.7.6-final/lib/python/Products/PluginIndexes/TopicIndex/FilteredSet.py", 
>> line 73, in index_object
>>     if RestrictionCapableEval(self.expr).eval({'o': o}):
>>   File 
>> "/home/zope/Zope-2.7.6-final/lib/python/RestrictedPython/Eval.py", 
>> line 112, in eval
>>     return eval(code, d)
>>   File "<string>", line 1, in <expression>
>> Unauthorized: You are not allowed to access 'portal_type' in this context

Littéralement, que l'utilisateur qui demande d'afficher document.html n'en a 
pas le droit... Mais c'est plus sûrement que ledit document.html est corrompu. 
D'autant plus avec tes autres messages d'erreur.

Tu peux peut-être essayer ceci :

1. supprimer les documents Word qui ont lancé la cascade d'erreurs

2. installer le patch pour PortalTransforms que j'ai mis hier dans le Trac : 
http://svn.nuxeo.org/trac/pub/ticket/1760. Il accélère notamment word_to_html. 
Au point de les rendre utilisables. Deux bémols :

* il nécessite une version récente de lxml (au moins 1.0, je pense)

* il est faux :-) (supprimant les parties du document HTML sous les balises 
inconnues, au lieu de supprimer les balises seules ; il faut au minimum 
ajouter 'font' aux balises reconnues)

2b. j'attache aussi un word_to_text.py utilisant wvware : le mettre dans 
PortalTransforms/transforms, modifier transforms/__init__.py pour qu'il 
l'appelle, et l'ajouter sous la ZMI

3. Réimporter les documents Word

4. Supprimer et recréer les index

> Ch Otton
> Poyry Environment.

yves

_______________________________________________
cps-users-fr 
Adresse de la liste : [email protected]
Gestion de l'abonnement : <http://lists.nuxeo.com/mailman/listinfo/cps-users-fr>
word_to_text.py (text/x-python, 1.8 KB)
# $Id$

import os
import sys
from lxml import etree
from Products.PortalTransforms.interfaces import itransform
from Products.PortalTransforms.transforms import office_wvware

ENCODING = "iso-8859-15"

# This could go in libtransforms/utils
def getBodyTextFromHTML( html_fd, encoding ):
    """Return the body, as text, of an HTML document.
    """
    parser = etree.HTMLParser()
    tree = etree.parse(html_fd, parser)
    body = []
    body_elt = tree.getroot().find('body')
    if not body_elt:
        return ''
    for event, elem in etree.iterwalk(body_elt, events=('start', 'end')):
        if VALID_TAGS.get(elem.tag, 0):
            if elem.text:
                txt = elem.text.strip()
                if isinstance(txt, unicode):
                    txt = txt.encode(encoding, 'xmlcharrefreplace')
                if txt:
                    body.append(txt)
            if elem.tail:
                txt = elem.tail.strip()
                if isinstance(txt, unicode):
                    txt = txt.encode(encoding, 'xmlcharrefreplace')
                if txt:
                    body.append(txt)
    return " ".join(body)


class document(office_wvware.document):

    def text(self):
        htmlfile = open(os.path.join(self.tmpdir, self.__name__+'.html'))
        text = getBodyTextFromHTML(htmlfile, ENCODING)
        return text


class word_to_text:
    __implements__ = itransform

    __name__ = 'word_to_text'
    inputs   = ('application/msword',)
    output  = 'text/plain'

    def name(self):
        return self.__name__

    def convert(self, data, cache, **kwargs):
        orig_file = os.path.basename((kwargs.get('filename') or 'unknown.doc'))

        doc = document(orig_file, data)
        doc.convert()
        text = doc.text()

        doc.cleanDir(doc.tmpdir)

        cache.setData(text)
        return cache

def register():
    return word_to_text()
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.