[Happydoc-checkins] CVS: HappyDoc3/happydoclib packagetree.py,1.1,1.2
Brought to you by:
doughellmann,
krlosaqp
|
From: Doug H. <dou...@us...> - 2003-01-01 13:47:27
|
Update of /cvsroot/happydoc/HappyDoc3/happydoclib
In directory sc8-pr-cvs1:/tmp/cvs-serv26212/happydoclib
Modified Files:
packagetree.py
Log Message:
Add node types for code (classes, functions and methods).
Modify the algorithm for getPathToNode() so that it returns something
which can more directly be used to build a relative URL. This
includes going one level higher than needed when accessing a directory
and treating some nodes as special cases.
Make the module name '*.py' lookup optional in the dotted name lookup.
Index: packagetree.py
===================================================================
RCS file: /cvsroot/happydoc/HappyDoc3/happydoclib/packagetree.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** packagetree.py 29 Dec 2002 18:35:14 -0000 1.1
--- packagetree.py 1 Jan 2003 13:47:22 -0000 1.2
***************
*** 57,60 ****
--- 57,61 ----
import mimetypes
import os
+ import pprint
import re
import UserDict
***************
*** 149,152 ****
--- 150,170 ----
self.module_info = docs
+ #
+ # Add classes to the tree
+ #
+ for class_name in self.module_info.getClassNames():
+ class_tree = self.addSubNode(class_name,
+ nodeClass=ClassTree,
+ )
+
+ #
+ # Add functions to the tree
+ #
+ for function_name in self.module_info.getFunctionNames():
+ function_tree = self.addSubNode(function_name,
+ nodeClass=FunctionTree,
+ )
+
+
trace.outof(outputLevel=TRACE_LEVEL)
return
***************
*** 397,403 ****
--- 415,427 ----
A '..' indicates moving up to the parent one level.
"""
+ trace.into('PackageTree', 'getPathToNode',
+ otherNode=otherNode.getName(),
+ outputLevel=TRACE_LEVEL,
+ )
+
my_path = self.getPath()
other_path = otherNode.getPath()
if my_path == other_path:
+ trace.outof((), outputLevel=TRACE_LEVEL)
return ()
***************
*** 406,424 ****
#
while my_path and other_path and my_path[0] == other_path[0]:
my_path = my_path[1:]
other_path = other_path[1:]
! if self.items():
! is_file = 0
! else:
! is_file = 1
! going_up = ('..',) * (len(my_path) - is_file)
relative_path = going_up + other_path
!
return relative_path
! def findNodeFromDottedName(self, dottedNodeName, tryParent=1):
"""Find the node referenced by the dotted name given.
--- 430,484 ----
#
while my_path and other_path and my_path[0] == other_path[0]:
+ trace.write('Removing %s from both paths' % my_path[0],
+ outputLevel=TRACE_LEVEL)
my_path = my_path[1:]
other_path = other_path[1:]
+
+ trace.writeVar(my_path=my_path,
+ other_path=other_path,
+ outputLevel=TRACE_LEVEL,
+ )
! if not other_path:
! #
! # Special Case: I am a child of the other node.
! #
! trace.write('source is child of dest',
! outputLevel=TRACE_LEVEL)
! if self.getMimeType()[0] == 'application/x-directory':
! is_dir = 1
! else:
! is_dir = 0
! trace.writeVar(is_dir=is_dir,
! outputLevel=TRACE_LEVEL)
! going_up = ('..',) * (len(my_path) + is_dir)
! other_path = (otherNode.getName(),)
!
! else:
! #
! # Either a parent or off in another branch of the
! # tree.
! #
! if self.getMimeType()[0] == 'application/x-directory':
! is_file = 0
! else:
! is_file = 1
!
! going_up = ('..',) * (len(my_path) - is_file)
+ #
+ # Go up to a common point in the tree,
+ # and then back down to the other node.
+ #
relative_path = going_up + other_path
!
! trace.outof(relative_path, outputLevel=TRACE_LEVEL)
return relative_path
! def findNodeFromDottedName(self, dottedNodeName,
! tryParent=1,
! tryModuleExtensions=1,
! ):
"""Find the node referenced by the dotted name given.
***************
*** 431,434 ****
--- 491,495 ----
dottedNodeName=dottedNodeName,
outputLevel=trace_level,
+ start=self.getName(),
)
***************
*** 461,465 ****
named_node = self.get(name)
! if (named_node is None):
trace.write('Checking %s.py as child' % name,
outputLevel=trace_level,
--- 522,526 ----
named_node = self.get(name)
! if (named_node is None) and tryModuleExtensions:
trace.write('Checking %s.py as child' % name,
outputLevel=trace_level,
***************
*** 497,501 ****
return named_node
! def addSubNode(self, name):
"""Insert a child node under this node.
--- 558,562 ----
return named_node
! def addSubNode(self, name, nodeClass=None):
"""Insert a child node under this node.
***************
*** 505,509 ****
trace.into('PackageTree', 'addSubNode', name=name,
outputLevel=TRACE_LEVEL)
! new_node = PackageTree(self, name)
self[name] = new_node
trace.outof(outputLevel=TRACE_LEVEL)
--- 566,575 ----
trace.into('PackageTree', 'addSubNode', name=name,
outputLevel=TRACE_LEVEL)
!
! if nodeClass:
! new_node = nodeClass(self, name)
! else:
! new_node = PackageTree(self, name)
!
self[name] = new_node
trace.outof(outputLevel=TRACE_LEVEL)
***************
*** 522,527 ****
self.grouped_children = {}
for node in self.values():
! mimetype, encoding = node.getMimeType()
! group = self.grouped_children.setdefault(mimetype, [])
group.append(node)
return self.grouped_children.get(mimetype, [])
--- 588,593 ----
self.grouped_children = {}
for node in self.values():
! node_mimetype, node_encoding = node.getMimeType()
! group = self.grouped_children.setdefault(node_mimetype, [])
group.append(node)
return self.grouped_children.get(mimetype, [])
***************
*** 534,535 ****
--- 600,699 ----
child.walk(callback)
return
+
+
+
+ class CodeObjectTree(PackageTree):
+ """Represents a code object to be documented.
+ """
+
+ MIMETYPE = 'application/x-code'
+
+ def __init__(self, parent, name):
+ """Construct a CodeObjectTree.
+ """
+ trace.into('CodeObjectTree', '__init__',
+ name=name,
+ outputLevel=TRACE_LEVEL,
+ )
+ PackageTree.__init__(self, parent, name)
+ self.code_info = self._getCodeInfo()
+ trace.write(self.getMimeType()[0], outputLevel=TRACE_LEVEL)
+ trace.outof(outputLevel=TRACE_LEVEL)
+ return
+
+ def getMimeType(self):
+ return (self.MIMETYPE, None)
+
+ def getInputFilename(self):
+ """Returns the input filename of the parent node.
+ """
+ return self.getParent().getInputFilename()
+
+ def getRelativeFilename(self):
+ """Returns the filename of the parent node.
+ """
+ return self.getParent().getRelativeFilename()
+
+ def getDocStringAndFormat(self):
+ """Returns the docstring of the code object, and the format of that data.
+ """
+ return self.code_info.getDocStringAndFormat()
+
+ def parseInput(self):
+ "Does nothing."
+ return
+
+
+ class FunctionTree(CodeObjectTree):
+ """Represents a function in the package tree.
+ """
+ MIMETYPE = 'application/x-function'
+
+ def _getCodeInfo(self):
+ return self.getParent().module_info.getFunctionInfo(self.name)
+
+ class MethodTree(FunctionTree):
+ """Represents a method in the package tree.
+ """
+
+ def _getCodeInfo(self):
+ return self.getParent().code_info.getMethodInfo(self.name)
+
+ class ClassTree(CodeObjectTree):
+ """Represent a class in the package tree.
+ """
+
+ MIMETYPE = 'application/x-class'
+
+ def __init__(self, parent, name):
+ trace.into('ClassTree', '__init__',
+ name=name,
+ outputLevel=TRACE_LEVEL,
+ )
+ CodeObjectTree.__init__(self, parent, name)
+
+ for method_name in self.code_info.getMethodNames():
+ method_node = self.addSubNode(method_name,
+ nodeClass=MethodTree,
+ )
+ trace.outof(outputLevel=TRACE_LEVEL)
+ return
+
+ def _getCodeInfo(self):
+ return self.getParent().module_info.getClassInfo(self.name)
+
+ def parseInput(self):
+ """Add methods as sub-nodes.
+ """
+ return
+
+ def getRelativeFilename(self):
+ return PackageTree.getRelativeFilename(self)
+
+ # def getRelativeFilename(self):
+ # """Returns the filename of this node.
+ # """
+ # parent_filename = self.getParent().getRelativeFilename()
+ # parent_filename, ext = os.path.splitext(parent_filename)
+ # my_filename = os.path.join(parent_filename, self.getName())
+ # return my_filename
|