From: Doug H. <dou...@pr...> - 2002-11-18 13:46:01
|
Update of /cvsroot/happydoc/HappyDoc3/happydoclib/docset In directory sc8-pr-cvs1:/tmp/cvs-serv9383 Added Files: docset_MultiHTMLFile.py test_docset_MultiHTMLFile.py tests.py Log Message: Initial checkin --- NEW FILE: docset_MultiHTMLFile.py --- #!/usr/bin/env python # # $Id: docset_MultiHTMLFile.py,v 1.1 2002/11/18 13:45:58 doughellmann Exp $ # # Copyright 2002 Doug Hellmann. # # # All Rights Reserved # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose and without fee is hereby # granted, provided that the above copyright notice appear in all # copies and that both that copyright notice and this permission # notice appear in supporting documentation, and that the name of Doug # Hellmann not be used in advertising or publicity pertaining to # distribution of the software without specific, written prior # permission. # # DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, # INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN # NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS # OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # """Documentation set which writes output to multiple files. """ __rcs_info__ = { # # Creation Information # 'module_name' : '$RCSfile: docset_MultiHTMLFile.py,v $', 'rcs_id' : '$Id: docset_MultiHTMLFile.py,v 1.1 2002/11/18 13:45:58 doughellmann Exp $', 'creator' : 'Doug Hellmann <do...@he...>', 'project' : 'HappyDoc', 'created' : 'Sun, 17-Nov-2002 13:32:00 EST', # # Current Information # 'author' : '$Author: doughellmann $', 'version' : '$Revision: 1.1 $', 'date' : '$Date: 2002/11/18 13:45:58 $', } try: __version__ = __rcs_info__['version'].split(' ')[1] except: __version__ = '0.0' # # Import system modules # import os # # Import Local modules # from happydoclib.docset import base from happydoclib.trace import trace # # Module # def entryPoint(): "Return info about this module to the dynamic loader." return { 'name':'MultiHTMLFile', 'factory':MultiHTMLFileDocSet, } class MultiHTMLFileDocSet(base.MultiFileDocSet): """Documentation set written to multiple HTML files. """ def getOutputFilenameForPackageTreeNode(self, packageTreeNode): filename = base.MultiFileDocSet.getOutputFilenameForPackageTreeNode(self, packageTreeNode) if packageTreeNode.values(): # # This is a directory. # filename_with_extension = os.path.join(filename, 'index.html') else: # # This is a file. # filename_with_extension = '%s.html' % filename return filename_with_extension def writeDirectory(self, packageTreeNode): trace.into('MultiHTMLFileDocSet', 'writeDirectory', packageTreeNode=packageTreeNode, ) canonical_path = packageTreeNode.getPath(1) canonical_filename = apply(os.path.join, canonical_path) output_filename = self.getOutputFilenameForPackageTreeNode(packageTreeNode) self.statusMessage('Directory : "%s"\n to: "%s"' % ( canonical_filename, output_filename, )) trace.outof() return def writePythonFile(self, packageTreeNode): trace.into('MultiHTMLFileDocSet', 'writePythonFile', packageTreeNode=packageTreeNode, ) canonical_path = packageTreeNode.getPath(1) canonical_filename = apply(os.path.join, canonical_path) output_filename = self.getOutputFilenameForPackageTreeNode(packageTreeNode) self.statusMessage('Documenting: "%s"\n to: "%s"' % ( canonical_filename, output_filename, )) trace.outof() return def writePlainTextFile(self, packageTreeNode): trace.into('MultiHTMLFileDocSet', 'writePlainTextFile', packageTreeNode=packageTreeNode, ) canonical_path = packageTreeNode.getPath(1) canonical_filename = apply(os.path.join, canonical_path) output_filename = self.getOutputFilenameForPackageTreeNode(packageTreeNode) self.statusMessage('Translating: "%s"\n to: "%s"' % ( canonical_filename, output_filename, )) trace.outof() return def writeCB(self, packageTreeNode): trace.into('MultiHTMLFileDocSet', 'writeCB', packageTreeNode=packageTreeNode, ) node_name = packageTreeNode.getName() extension = os.path.splitext(node_name)[1] if packageTreeNode.values(): # # Directory node # self.writeDirectory(packageTreeNode) elif node_name == '__init__.py': # # Skip the __init__.py file, since it will # be handled as part of the package. # trace.write('skipping __init__.py') pass else: # # Anything past here looks like a file. # if extension == '.py': # # Filename ends in .py, so it is a Python file. # self.writePythonFile(packageTreeNode) elif extension in ('.txt', '.stx'): # # Filename ends in .txt or .stx so it is # a text file. # self.writePlainTextFile(packageTreeNode) else: # # Unrecognized file, skipped. # node_path = packageTreeNode.getPath() filename = apply(os.path.join, node_path) self.statusMessage('Skiping unrecognized file %s' % filename, 2) trace.outof() return --- NEW FILE: test_docset_MultiHTMLFile.py --- #!/usr/bin/env python # # $Id: test_docset_MultiHTMLFile.py,v 1.1 2002/11/18 13:45:58 doughellmann Exp $ # # Copyright 2002 Doug Hellmann. # # # All Rights Reserved # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose and without fee is hereby # granted, provided that the above copyright notice appear in all # copies and that both that copyright notice and this permission # notice appear in supporting documentation, and that the name of Doug # Hellmann not be used in advertising or publicity pertaining to # distribution of the software without specific, written prior # permission. # # DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, # INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN # NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS # OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # """Tests for the MultiHTMLFile docset. """ __rcs_info__ = { # # Creation Information # 'module_name' : '$RCSfile: test_docset_MultiHTMLFile.py,v $', 'rcs_id' : '$Id: test_docset_MultiHTMLFile.py,v 1.1 2002/11/18 13:45:58 doughellmann Exp $', 'creator' : 'Doug Hellmann <do...@he...>', 'project' : 'HappyDoc', 'created' : 'Sun, 17-Nov-2002 17:31:33 EST', # # Current Information # 'author' : '$Author: doughellmann $', 'version' : '$Revision: 1.1 $', 'date' : '$Date: 2002/11/18 13:45:58 $', } try: __version__ = __rcs_info__['version'].split(' ')[1] except: __version__ = '0.0' # # Import system modules # import os import unittest # # Import Local modules # from happydoclib.scanner import Scanner from docset_MultiHTMLFile import MultiHTMLFileDocSet # # Module # class MultiHTMLFileDocSetTestCase(unittest.TestCase): def _test(self, inputDir, outputDir, expected): scanner = Scanner([inputDir]) trees = scanner.getPackageTrees() expected_tree = trees[0] module_two = expected_tree['levelOne']['levelTwo']['two.py'] docset = MultiHTMLFileDocSet(scanner, 'Testing', outputDir, ) actual = docset.getOutputFilenameForPackageTreeNode(module_two) self.failUnlessEqual(actual, expected) return def testScanningFromCurrentDirectory(self): output_directory = '/foo/bar' expected = os.path.join( output_directory, 'testScanner', 'levelOne', 'levelTwo', 'two.py.html', ) self._test(inputDir='TestCases/testScanner', outputDir=output_directory, expected=expected, ) return def testScanningFromRoot(self): output_directory = '/foo/bar' expected = os.path.join( output_directory, 'testScanner', 'levelOne', 'levelTwo', 'two.py.html', ) self._test(inputDir=os.path.join( os.getcwd(), 'TestCases/testScanner'), outputDir=output_directory, expected=expected, ) return def testScanningRelativePath(self): output_directory = '/foo/bar' expected = os.path.join( output_directory, 'testScanner', 'levelOne', 'levelTwo', 'two.py.html', ) self._test(inputDir='../HappyDoc3/TestCases/testScanner', outputDir=output_directory, expected=expected, ) return --- NEW FILE: tests.py --- #!/usr/bin/env python # # $Id: tests.py,v 1.1 2002/11/18 13:45:58 doughellmann Exp $ # # Copyright 2002 Doug Hellmann. # # # All Rights Reserved # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose and without fee is hereby # granted, provided that the above copyright notice appear in all # copies and that both that copyright notice and this permission # notice appear in supporting documentation, and that the name of Doug # Hellmann not be used in advertising or publicity pertaining to # distribution of the software without specific, written prior # permission. # # DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, # INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN # NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS # OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # """Tests for docsets. """ __rcs_info__ = { # # Creation Information # 'module_name' : '$RCSfile: tests.py,v $', 'rcs_id' : '$Id: tests.py,v 1.1 2002/11/18 13:45:58 doughellmann Exp $', 'creator' : 'Doug Hellmann <do...@he...>', 'project' : 'HappyDoc', 'created' : 'Sun, 17-Nov-2002 14:09:33 EST', # # Current Information # 'author' : '$Author: doughellmann $', 'version' : '$Revision: 1.1 $', 'date' : '$Date: 2002/11/18 13:45:58 $', } try: __version__ = __rcs_info__['version'].split(' ')[1] except: __version__ = '0.0' # # Import system modules # # # Import Local modules # # # Module # |