Here is the code:
#@+leo-ver=4-thin
#@+node:pap.20060415232117:@thin trees\ml.py
#@<< docstring >>
#@+node:pap.20060415232117.1:<< docstring >>
"""A Test handler.
This defines
@auto-test = adds some nodes
@auto-test2 = doesn't do anything
@auto-test3 = adds nodes but doesn't delete the old ones
"""
#@-node:pap.20060415232117.1:<< docstring >>
#@nl
from autotrees import BaseTreeHandler, TreeNode
from glob import glob
import os
__version__ = "0.1"
__plugin_requires__ = ["autotrees"]
__plugin_group__ = "ML"
#@<< version history >>
#@+node:pap.20060415232117.2:<< version history >>
#@+at
#
# Version history
#
# 0.1 Paul Paterson:
# - Initial version
#@-at
#@nonl
#@-node:pap.20060415232117.2:<< version history >>
#@nl
#@+others
#@+node:pap.20060415232117.3:class MLTree
class MLTree(BaseTreeHandler):
"""A tree for showing documentation files"""
#@ @+others
#@+node:pap.20060415232117.4:initFrom
def initFrom(self, parameter):
"""Initialize the tree"""
self.children = []
self.children.extend(self.getDocsFor(parameter))
#@nonl
#@-node:pap.20060415232117.4:initFrom
#@+node:pap.20060415232117.5:getDocsFor
def getDocsFor(self, path):
"""Return the child nodes for the given path"""
files = glob(os.path.join(path, "*.mo"))
children = []
# Get all doc nodes
for f in files:
name = "Doc: %s" % os.path.split(f)[1]
body = file(f, "r").read()
children.append(TreeNode(name, body))
# Get the sub directories
for f in os.listdir(path):
fullname = os.path.join(path, f)
if os.path.isdir(fullname):
children.append(TreeNode("Dir: %s" % f, "", self.getDocsFor(fullname)))
#
return children
#@-node:pap.20060415232117.5:getDocsFor
#@-others
#@nonl
#@-node:pap.20060415232117.3:class MLTree
#@-others
#@nonl
#@-node:pap.20060415232117:@thin trees\ml.py
#@-leo