[Happydoc-checkins] CVS: HappyDoc3/happydoclib/docset base.py,1.1,1.2
Brought to you by:
doughellmann,
krlosaqp
|
From: Doug H. <dou...@us...> - 2002-12-01 22:36:56
|
Update of /cvsroot/happydoc/HappyDoc3/happydoclib/docset
In directory sc8-pr-cvs1:/tmp/cvs-serv27748/happydoclib/docset
Modified Files:
base.py
Log Message:
Start working on mimetype-driven output code. This version creates
output directories and empty index.html files.
Index: base.py
===================================================================
RCS file: /cvsroot/happydoc/HappyDoc3/happydoclib/docset/base.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** base.py 18 Nov 2002 13:43:37 -0000 1.1
--- base.py 1 Dec 2002 22:36:53 -0000 1.2
***************
*** 67,70 ****
--- 67,78 ----
#
+ def isSomethingThatLooksLikeDirectory(path):
+ return (os.path.isdir(path)
+ or
+ os.path.islink(path)
+ or
+ os.path.ismount(path)
+ )
+
class DocSet:
"""Basic Documentation Set.
***************
*** 155,163 ****
def write(self):
! package_trees = self.scanner.getPackageTrees()
!
! for package_tree in package_trees:
! package_tree.walk(self.writeCB)
!
return
--- 163,167 ----
def write(self):
! self.scanner.walk(self.writeCB)
return
***************
*** 168,171 ****
--- 172,188 ----
"""
+ mimetype_writer_mapping = {
+ 'text/x-python': 'writePythonFile',
+ 'text/x-text': 'writePlainTextFile',
+ 'text/x-structured': 'writePlainTextFile',
+ 'text/html': 'copyInputFileToOutput',
+ }
+
+ mimetype_extension_mapping = {
+ 'text/x-python': { 'remove_existing':1,},
+ 'text/plain': { 'remove_existing':1,},
+ 'text/x-structured': { 'remove_existing':1,},
+ 'text/html': { 'remove_existing':1,},
+ }
def getOutputFilenameForPackageTreeNode(self, packageTreeNode):
***************
*** 184,205 ****
results in : /foo/output/input/bar.py
"""
! #
! # Get the path to the node from the root of the scanned
! # tree.
! #
! node_path = packageTreeNode.getPath()
#
# Get the input filename, relative to the root of the input.
#
! filename = apply(os.path.join, node_path)
#
# Add the output directory to the front of the input
# filename.
#
! output_filename = os.path.join(self.output_directory, filename)
#
# Normalize the path, in case it includes /./ and the like.
#
normalized_output_filename = os.path.normpath(output_filename)
return normalized_output_filename
--- 201,335 ----
results in : /foo/output/input/bar.py
"""
! trace.into('MultiFileDocSet', 'getOutputFilenameForPackageTreeNode',
! packageTreeNode=packageTreeNode,
! )
!
! mimetype, encoding = packageTreeNode.getMimeType()
! trace.writeVar(mimetype=mimetype)
! settings = self.mimetype_extension_mapping.get(mimetype, {})
! trace.writeVar(settings=settings)
!
#
# Get the input filename, relative to the root of the input.
#
! #input_filename = packageTreeNode.getInputFilename()
! input_filename = packageTreeNode.getRelativeFilename()
!
#
# Add the output directory to the front of the input
# filename.
#
! output_filename = os.path.join(self.output_directory, input_filename)
!
! if settings.get('remove_existing'):
! output_filename, ignore = os.path.splitext(output_filename)
!
#
# Normalize the path, in case it includes /./ and the like.
#
normalized_output_filename = os.path.normpath(output_filename)
+ trace.outof(normalized_output_filename)
return normalized_output_filename
+
+ def copyInputFileToOutput(self, packageTreeNode):
+ input_filename = packageTreeNode.getInputFilename()
+ output_filename = self.getOutputFilenameForPackageTreeNode(packageTreeNode)
+ self.statusMessage('Copying: %s\n To: %s' % (
+ input_filename,
+ output_filename,
+ ))
+ input_file = open(input_filename, 'rb')
+ output_file = open(output_filename, 'wb')
+ output_file.write(input_file.read())
+ input_file.close()
+ output_file.close()
+ return
+
+ def writeCB(self, packageTreeNode):
+ trace.into('MultiHTMLFileDocSet', 'writeCB',
+ packageTreeNode=packageTreeNode,
+ )
+
+ if packageTreeNode.values():
+ #
+ # Directory node
+ #
+ self.writeDirectory(packageTreeNode)
+
+ else:
+ #
+ # Anything past here looks like a file.
+ #
+ mimetype, encoding = packageTreeNode.getMimeType()
+
+ writer_name = self.mimetype_writer_mapping.get(mimetype)
+ if writer_name:
+ writer = getattr(self, writer_name)
+ writer(packageTreeNode)
+
+ else:
+ #
+ # Unrecognized file, skipped.
+ #
+ node_path = packageTreeNode.getPath()
+ filename = apply(os.path.join, node_path)
+ self.statusMessage('Skiping unrecognized file %s with mimetype %s' % (
+ filename,
+ mimetype,
+ ))
+
+ trace.outof()
+ return
+ def rmkdir(self, path):
+ "Create a directory and all of its children."
+ if not path:
+ return
+ parts = os.path.split(path)
+ if len(parts) > 1:
+ parent, child = parts
+ if not isSomethingThatLooksLikeDirectory(parent):
+ self.rmkdir(parent)
+ if not isSomethingThatLooksLikeDirectory(path):
+ os.mkdir(path)
+ return
+
+ def writeDirectory(self, packageTreeNode):
+ trace.into('MultiFileDocSet', 'writeDirectory',
+ packageTreeNode=packageTreeNode,
+ )
+
+ canonical_path = packageTreeNode.getPath(1)
+ canonical_filename = apply(os.path.join, canonical_path)
+ output_filename = self.getOutputFilenameForPackageTreeNode(packageTreeNode)
+ output_dirname = os.path.dirname(output_filename)
+
+ self.statusMessage('Directory : "%s"\n to: "%s"' % (
+ canonical_filename,
+ output_filename,
+ ))
+
+ if os.path.isdir(output_dirname):
+ self.statusMessage('\tExists')
+ else:
+ self.rmkdir(output_dirname)
+ self.statusMessage('\tCreated')
+
+ self.writeTOCFile(packageTreeNode)
+
+ trace.outof()
+ return
+
+ def writeTOCFile(self, packageTreeNode):
+ trace.into('MultiFileDocSet', 'writeDirectory',
+ packageTreeNode=packageTreeNode,
+ )
+
+ output_filename = self.getOutputFilenameForPackageTreeNode(packageTreeNode)
+
+ file = open(output_filename, 'wt')
+ file.write('\n')
+ file.close()
+
+ trace.outof()
+ return
|