On Fri, Sep 5, 2014 at 6:58 AM, Edward K. Ream <[email protected]> wrote:
> Here is a script to replace body.x with body.wrapper.x for all x in the
> WrapperAPI except __init__.
Here is an improved script that stresses the gc less and produces
clearer messages:
'''
A script to replace body.x with body.wrapper.x for all x in the WrapperAPI.
It is *not undoable* to save massive amounts of memory.
Please run on an already-saved .leo file, and take all other
reasonable precautions.
If replace is False, it will just report the changes to be made.
'''
import leo.core.leoFrame as leoFrame
replace = False
aList = sorted([z for z in dir(leoFrame.WrapperAPI) if not z.startswith('__')])
nodes = 0
for p in c.all_unique_positions():
s = p.b
nodes += 1
found = False
for target in aList:
i = 0
pattern = 'body.' + target
while True:
i = s.find(pattern,i)
if i == -1:
break
if g.match_word(s,i,pattern):
if not found:
print('In node: %s' % p.h)
found = True
i1,i2 = g.getLine(s,i)
if replace:
j = i + len('body.')
s = s[:j] + 'wrapper.' + s[j:]
print(s[i1:i2+len('wrapper.')].rstrip())
i += len('wrapper.') + len(pattern)
else:
print(s[i1:i2].rstrip())
i += len(pattern)
else:
i += len(pattern)
if found and replace:
p.b = s
print('searched %s nodes' % nodes)
Edward
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.