Hi all,
Jochen Knuth <jok-zope@ipro.de> wrote:
Hi,
i have a ZClass with a property which is renderd as structured text. Because i designed this ZClass before there was a standard for including images, i made my own extension of structured text formating. Short: I used __imageobject__ as markup for the image.
Now i want to update all my zclass instances to the new syntax (while upgrading to Zope 2.5.1).
I have a Python Script listKBE, which call an External Method updateKBE. If i use it with a path with only a few ZClass instances (about 10) it works (slowly). If i use it with a path with about 550 instances it crashes or is extreme slow. Anyone to suggest a faster method?
Thank you, Jochen
again replying to myself:
i now do a ZopeFind (or correct: two nested ZopeFinds) in the External Method (attached) and give the result to the converter function. It works now reasonably fast, even with all my ZClass instances (about 600).
no, it doesn't work :-(
------------------------------------------------------------------------
#!/usr/local/bin/python import string import re
def punc_func(exclude): punc = r'' for char in string.punctuation: if char not in exclude: punc = punc + r'\%s' % char return punc
digits = string.digits letters = string.letters literal_punc = punc_func("'") dbl_quoted_punc = punc_func("\"") strongem_punc = punc_func('*') under_punc = punc_func('_<>') phrase_delimiters = r'\s\.\,\?\/\!\&\(\)'
def kbeimage_search_replace(text):
expr = re.compile(r'__([%s%s%s\s]+?)__' % (letters, digits, strongem_punc)).search r=expr(text) if r: start, end = r.span(1) newtext='"bild":img:' newtext=text[:start-2]+newtext+text[start:end]+' '+text[end+2:] return kbeimage_search_replace(newtext) else: return text
def updateKBE(self,path): pathobj=self.restrictedTraverse(path) resultbases=self.ZopeFind(pathobj, obj_metatypes=['IPRO Knowledge Base'],search_sub=1) resultlist=[] for fid,fobj in resultbases: results=self.ZopeFind(pathobj, obj_metatypes=['IPRO Knowledge Base Entry'])
this should be results=self.ZopeFind(fobj, obj_metatypes=['IPRO Knowledge Base Entry']) not searching recursively else.
for id,obj in results: resultlist.append(id) issue = obj.Issue newissue = kbeimage_search_replace(issue)
and here the Zope process dies on signal 11, if i only print e.g. id, obj.Issue it works, but when i call the kbeimage_search_replace()-function ->kaboom.
obj.propertysheets.properties.manage_changeProperties({'Issue':newissue}) return resultlist
if i test the kbeimage_search_replace()-function manually, i can replace the __image.gif__ several times, but i think that the recursive call is causing the error. Any re expert here, who can change the recursive function into an one pass function (there might be several image refs per issue)? Thank you, Jochen -- -------------------------------------------------- Jochen Knuth WebMaster http://www.ipro.de IPRO GmbH Phone ++49-7152-93330 Steinbeisstr. 6 Fax ++49-7152-933340 71229 Leonberg EMail: J.Knuth@ipro.de