Posted By

laurenceosx on 07/29/09


Tagged

python leo


Versions (?)

Python Leo - Fix Path Nodes Top Down


 / Published in: Python
 

  1. def GetPath(p):
  2. def GetHs(itr): return itr.headString().strip().split('\n')[0].strip()
  3. def GetBs(itr): return itr.bodyString().strip().split('\n')[0].strip()
  4.  
  5. lst = []
  6. itr = p.copy()
  7. level = p.copy().level()
  8. while level >= 0:
  9.  
  10. hs = GetHs(itr)
  11. bs = GetBs(itr)
  12. if hs.startswith('@path'):
  13. ThePath = bs
  14. lst.append( ThePath )
  15. else:
  16. if level > 0:
  17. for p in itr.siblings_iter():
  18. hs = GetHs(p)
  19. bs = GetBs(p)
  20. if hs.startswith('@path'):
  21. ThePath = bs
  22. lst.append( ThePath )
  23.  
  24. itr = itr.parent()
  25. level = level -1
  26.  
  27. lst.reverse()
  28. s = '\\'.join( lst )
  29. return s
  30.  
  31.  
  32. # Iterate and fix
  33.  
  34. start = p.copy()
  35. current = p.copy()
  36.  
  37. for p in current.self_and_subtree_iter():
  38. hs = p.headString().strip()
  39. if hs.startswith('@path'):
  40. sPath = GetPath(p)
  41. NewHeadString = '@path ' + sPath
  42. if hs <> NewHeadString:
  43. print 'NewPath->', NewHeadString
  44. c.setHeadString(p, NewHeadString)
  45. else:
  46. print 'PathCheck', hs

Report this snippet  

You need to login to post a comment.