[Zope] FIND AND REPLACE

Carlos de la Guardia cguardia@aldeasystems.com
Mon, 1 Apr 2002 13:26:30 -0600 (CST)


If you need simple string substitution, you could use the following Python script:

## Script (Python) "searchAndReplace"
## parameters=search_string,replace_string
##
folder=context.folder_to_change
for pt in folder.objectValues('Page Template'):
  body=pt.read()
  body=body.replace(search_string,replace_string)
  pt.write(body)
  print "Changed "+pt.id+" ("+pt.title+")"
for dtml in folder.objectValues(['DTML Document','DTML Method']):
  body=dtml.document_src()
  body=body.replace(search_string,replace_string)
  dtml.manage_edit(body,dtml.title)
  print "Changed "+dtml.id()+" ("+dtml.title+")"
return printed

Place it anywhere where you can acquire the folder where the documents you
want to change are located. It searches for all page templates, dtml
documents and dtml methods in that folder and substitutes all ocurrences of
the search_string with the replace_string.

Carlos de la Guardia
Aldea Systems

On Mon, 1 Apr 2002 12:10:13 -0300 "Alejandro T. Singer" <alejandro.singer@systeam.com.ar> wrote:

> I have to change on more than 700 dtml pages the syntax of a link.
> 
> There's any automatic way on ZOPE to find and replace those parts of
> code ?
> 
> 
> Thanks
> 
> Alejandro
> 
>