[Happydoc-checkins] CVS: HappyDoc3/happydoclib packagetree.py,1.5,1.6
Brought to you by:
doughellmann,
krlosaqp
|
From: Doug H. <dou...@us...> - 2003-01-18 20:00:18
|
Update of /cvsroot/happydoc/HappyDoc3/happydoclib
In directory sc8-pr-cvs1:/tmp/cvs-serv13437/happydoclib
Modified Files:
packagetree.py
Log Message:
Move logic dealing with different mimetypes in special ways into
subclasses in the parsers package.
Index: packagetree.py
===================================================================
RCS file: /cvsroot/happydoc/HappyDoc3/happydoclib/packagetree.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** packagetree.py 18 Jan 2003 16:52:04 -0000 1.5
--- packagetree.py 18 Jan 2003 20:00:12 -0000 1.6
***************
*** 55,59 ****
# Import system modules
#
- import mimetypes
import os
import pprint
--- 55,58 ----
***************
*** 68,72 ****
from happydoclib.status import statusMessage
from happydoclib.trace import trace
! from happydoclib.utils import *
--- 67,71 ----
from happydoclib.status import statusMessage
from happydoclib.trace import trace
! from happydoclib.utils import getMimeType
***************
*** 77,81 ****
TRACE_LEVEL=2
- mimetypes.types_map['.stx'] = 'text/x-structured'
class PackageTree(UserDict.UserDict):
--- 76,79 ----
***************
*** 86,95 ****
"""
- parser_mapping = {
- 'text/x-python' : 'parsePythonInput',
- 'text/plain' : 'parsePlainTextInput',
- 'text/x-structured' : 'parseStructuredTextInput',
- }
-
def __init__(self, parent, name):
trace.into('PackageTree', '__init__',
--- 84,87 ----
***************
*** 118,122 ****
trace.write('self.name=%s' % self.name, outputLevel=TRACE_LEVEL)
!
trace.outof(outputLevel=TRACE_LEVEL)
return
--- 110,114 ----
trace.write('self.name=%s' % self.name, outputLevel=TRACE_LEVEL)
!
trace.outof(outputLevel=TRACE_LEVEL)
return
***************
*** 127,239 ****
#
- # Parsing methods
- #
-
- def parsePythonInput(self):
- trace.into('PackageTree', 'parsePythonInput',
- outputLevel=TRACE_LEVEL)
- #
- # Derive the filename for this module.
- #
- filename = self.getInputFilename()
- statusMessage('Parsing: %s' % filename)
-
- #
- # Figure out if there is a parent node for the
- # documentation suite.
- #
- package_parent = self.getParent()
- if package_parent and hasattr(package_parent, 'module_info'):
- docs_parent = package_parent.module_info
- else:
- docs_parent = None
-
- trace.writeVar(docs_parent=docs_parent,
- outputLevel=TRACE_LEVEL)
-
- docs = happydoclib.parseinfo.getDocs(
- parent=docs_parent,
- fileName=filename,
- )
-
- self.module_info = docs
-
- #
- # Add classes to the tree
- #
- for class_name in self.module_info.getClassNames():
- class_tree = ClassTree(self, class_name)
-
- #
- # Add functions to the tree
- #
- for function_name in self.module_info.getFunctionNames():
- function_tree = FunctionTree(self, function_name)
-
-
- trace.outof(outputLevel=TRACE_LEVEL)
- return
-
- def parsePlainTextInput(self):
- trace.into('PackageTree', 'parsePlainTextInput',
- outputLevel=TRACE_LEVEL,
- )
- #
- # Derive the filename for this module.
- #
- filename = self.getInputFilename()
- trace.writeVar(filename=filename, outputLevel=TRACE_LEVEL)
-
- statusMessage('Importing preformatted file: %s' % filename)
-
- #f = open(filename, 'rt')
- #body = f.read()
- #f.close()
-
- #packageTreeNode.preformatted_text = body
-
- trace.outof(outputLevel=TRACE_LEVEL)
- return
-
- def parseStructuredTextInput(self):
- trace.into('PackageTree', 'parseStructuredTextInput',
- outputLevel=TRACE_LEVEL)
- self.parsePlainTextInput()
- trace.outof(outputLevel=TRACE_LEVEL)
- return
-
- def parseInput(self):
- """Get whatever information is appropriate from the input file.
- """
- trace.into('PackageTree', 'parseInput',
- outputLevel=TRACE_LEVEL)
-
- if os.path.isdir(self.getInputFilename()):
- trace.write('directory', outputLevel=TRACE_LEVEL)
- trace.outof(outputLevel=TRACE_LEVEL)
- return
-
- mimetype, encoding = self.getMimeType()
- try:
- parse_method_name = self.parser_mapping[mimetype]
- except KeyError:
- #
- # Don't know what to do with this file.
- #
- statusMessage('Not parsing input %s with mimetype %s' % (
- self.getInputFilename(),
- mimetype,
- ), 2)
- else:
- #
- # Call the parse method
- #
- parse_method = getattr(self, parse_method_name)
- parse_method()
-
- trace.outof(outputLevel=TRACE_LEVEL)
- return
-
- #
# Data retrieval methods
#
--- 119,122 ----
***************
*** 248,259 ****
input_filename = self.getInputFilename()
! mimetype = mimetypes.guess_type(input_filename)
!
! if mimetype == (None, None):
! if isSomethingThatLooksLikeDirectory(input_filename):
! mimetype = ('application/x-directory', None)
trace.outof(mimetype, outputLevel=TRACE_LEVEL)
! return mimetype
def getName(self):
--- 131,138 ----
input_filename = self.getInputFilename()
! mimetype, encoding = getMimeType(input_filename)
trace.outof(mimetype, outputLevel=TRACE_LEVEL)
! return (mimetype, encoding)
def getName(self):
***************
*** 296,368 ****
trace.outof(filename, outputLevel=TRACE_LEVEL)
return filename
-
- def _unquoteString(self, str):
- "Remove surrounding quotes from a string."
- str = str.strip()
- while ( str
- and
- (str[0] == str[-1])
- and
- str[0] in ('"', "'")
- ):
- str = str[1:-1]
- return str
def getDocStringAndFormat(self):
! #
! # Are we a python module?
! #
! if hasattr(self, 'module_info'):
! docstring = self.module_info.getDocString()
! docstring = self._unquoteString(docstring)
! format = self.module_info.getDocStringFormat()
! return (docstring, format)
!
! #
! # Are we a text file?
! #
! mimetype, encoding = self.getMimeType()
! if mimetype in ('text/plain', 'text/x-structured'):
! input_filename = self.getInputFilename()
! readme_text = open(input_filename, 'rt').read()
! format = 'StructuredText'
! return (readme_text, format)
!
! #
! # Look inside sub-nodes
! #
! for name in ('__init__.py', 'README.txt', 'README.stx'):
! trace.write('looking for %s' % name, outputLevel=TRACE_LEVEL)
! node = self.get(name)
! if node is not None:
! return node.getDocStringAndFormat()
!
! return ('', 'StructuredText')
- _summary_pattern = re.compile(r'^\s*([^\n]+)\n')
def getSummaryAndFormat(self):
! if hasattr(self, 'module_info'):
! return self.module_info.getSummaryAndFormat()
! else:
! text, format = self.getDocStringAndFormat()
! text = text.strip()
! #
! # Remove surrounding quotes, if present.
! #
! while text and (text[0] in ('"', "'")):
! text = text[1:]
! while text and (text[-1] in ('"', "'")):
! text = text[:-1]
! #
! # Pull out the first line, and return it if
! # we can find it. Otherwise, return the whole
! # string since that means that the whole thing
! # is just one line.
! #
! matchObj = self._summary_pattern.search(text)
! if matchObj:
! return (matchObj.group(0).strip(), format)
! else:
! return (text, format)
--- 175,192 ----
trace.outof(filename, outputLevel=TRACE_LEVEL)
return filename
def getDocStringAndFormat(self):
! """Returns a tuple containing the actual documentation string
! and the format of that docstring as understood by the
! docstring converters plugins.
! """
! raise NotImplementedError('getDocStringAndFormat')
def getSummaryAndFormat(self):
! """Returns a tuple containing a one line summary of the
! documentation for the node and the format of that
! string as understood by the docstring converter plugins.
! """
! raise NotImplementedError('getSummaryAndFormat')
***************
*** 636,643 ****
return self.code_info.getDocStringAndFormat()
- def parseInput(self):
- "Does nothing."
- return
-
class FunctionTree(CodeObjectTree):
--- 460,463 ----
***************
*** 678,687 ****
return self.getParent().module_info.getClassInfo(self.name)
- def parseInput(self):
- """Add methods as sub-nodes.
- """
- return
-
def getRelativeFilename(self):
return PackageTree.getRelativeFilename(self)
--- 498,504 ----
return self.getParent().module_info.getClassInfo(self.name)
def getRelativeFilename(self):
+ """Classes are written to their own file.
+ """
return PackageTree.getRelativeFilename(self)
|