[Happydoc-checkins] CVS: HappyDoc3/happydoclib scanner.py,1.5,1.6
Brought to you by:
doughellmann,
krlosaqp
|
From: Doug H. <dou...@us...> - 2002-12-08 16:23:27
|
Update of /cvsroot/happydoc/HappyDoc3/happydoclib
In directory sc8-pr-cvs1:/tmp/cvs-serv32693/happydoclib
Modified Files:
scanner.py
Log Message:
Reorganize PackageTreeNode methods.
Add getDocStringAndFormat(), getSummaryAndFormat() methods.
Index: scanner.py
===================================================================
RCS file: /cvsroot/happydoc/HappyDoc3/happydoclib/scanner.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** scanner.py 1 Dec 2002 22:35:19 -0000 1.5
--- scanner.py 8 Dec 2002 16:23:24 -0000 1.6
***************
*** 116,119 ****
--- 116,123 ----
return '<%s %s: %s>' % (self.__class__.__name__, self.getName(), base_str)
+ #
+ # Parsing methods
+ #
+
def parsePythonInput(self):
trace.into('PackageTree', 'parsePythonInput')
***************
*** 172,180 ****
return
- def getMimeType(self):
- """Returns the mimetype setting for this node.
- """
- return self.mimetype
-
def parseInput(self):
"""Get whatever information is appropriate from the input file.
--- 176,179 ----
***************
*** 208,217 ****
return
! def getParent(self):
! """Returns the parent node for this tree.
!
! If there is no parent (root of the tree), returns None.
"""
! return self.parent
def getName(self):
--- 207,218 ----
return
! #
! # Data retrieval methods
! #
!
! def getMimeType(self):
! """Returns the mimetype setting for this node.
"""
! return self.mimetype
def getName(self):
***************
*** 224,227 ****
--- 225,325 ----
"""
return self.canonical_name
+
+ def getInputFilename(self):
+ """Returns the original input filename that created the node.
+ """
+ trace.into('PackageTree', 'getInputFilename')
+
+ node_path = self.getPath(1)
+ trace.writeVar(node_path=node_path)
+ filename = apply(os.path.join, node_path)
+ trace.writeVar(filename=filename)
+
+ trace.outof(filename)
+ return filename
+
+ def getRelativeFilename(self):
+ """Returns the filename relative to the root of the input area.
+ """
+ trace.into('PackageTree', 'getRelativeFilename')
+
+ node_path = self.getPath()
+ trace.writeVar(node_path=node_path)
+ filename = apply(os.path.join, node_path)
+ trace.writeVar(filename=filename)
+
+ trace.outof(filename)
+ return filename
+
+ def getDocStringAndFormat(self):
+ #
+ # Are we a python module?
+ #
+ if hasattr(self, 'module_info'):
+ docstring = self.module_info.getDocString()
+ format = self.module_info.getDocStringFormat()
+ return (docstring, format)
+
+ #
+ # Are we a text file?
+ #
+ if self.getName() in ('README.txt', 'README.stx'):
+ input_filename = self.getInputFilename()
+ readme_text = open(input_filename, 'rt').read()
+ format = 'StructuredText'
+ return (readme_text, format)
+
+ #
+ # Look inside sub-nodes
+ #
+ node = self.get('__init__.py')
+ if node is not None:
+ return node.getDocStringAndFormat()
+
+ for name in ('README.txt', 'README.stx'):
+ trace.write('looking for %s' % name)
+ 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)
+
+
+ #
+ # Tree methods
+ #
+
+ def getParent(self):
+ """Returns the parent node for this tree.
+
+ If there is no parent (root of the tree), returns None.
+ """
+ return self.parent
def getPath(self, useCanonicalName=0):
***************
*** 252,282 ****
return path
- def getInputFilename(self):
- """Returns the original input filename that created the node.
- """
- trace.into('PackageTree', 'getInputFilename')
-
- node_path = self.getPath(1)
- trace.writeVar(node_path=node_path)
- filename = apply(os.path.join, node_path)
- trace.writeVar(filename=filename)
-
- trace.outof(filename)
- return filename
-
- def getRelativeFilename(self):
- """Returns the filename relative to the root of the input area.
- """
- trace.into('PackageTree', 'getRelativeFilename')
-
- node_path = self.getPath()
- trace.writeVar(node_path=node_path)
- filename = apply(os.path.join, node_path)
- trace.writeVar(filename=filename)
-
- trace.outof(filename)
- return filename
-
-
def addSubNode(self, name):
"""Insert a child node under this node.
--- 350,353 ----
***************
*** 298,301 ****
--- 369,373 ----
child.walk(callback)
return
+
|