From: Doug H. <dou...@us...> - 2002-05-13 01:14:47
|
Update of /cvsroot/happydoc/HappyDoc/happydoclib/formatter In directory usw-pr-cvs1:/tmp/cvs-serv10733/happydoclib/formatter Modified Files: Tag: dos_path_bug fileformatterbase.py formatter_HTMLFile.py Log Message: Initial pass at a fix for the Win32 path problems, including simplifying the definition of the path to the output file for an objects documentation. Index: fileformatterbase.py =================================================================== RCS file: /cvsroot/happydoc/HappyDoc/happydoclib/formatter/fileformatterbase.py,v retrieving revision 1.8 retrieving revision 1.8.2.1 diff -C2 -d -r1.8 -r1.8.2.1 *** fileformatterbase.py 10 Feb 2002 13:07:00 -0000 1.8 --- fileformatterbase.py 13 May 2002 01:14:44 -0000 1.8.2.1 *************** *** 119,126 **** --- 119,129 ---- the output path to create a full path. """ + happydoclib.TRACE.into('FileBasedFormatter', 'fixUpOutputFilename', + filename=filename) # # Remove preceding slashes to make name relative # filename = happydoclib.path.removeRelativePrefix(filename) + happydoclib.TRACE.writeVar(filename_after_remove_relative_prefix=filename) # # Apply the path prefix, if required *************** *** 129,132 **** --- 132,137 ---- filename = happydoclib.path.applyPrefixToPath( filename, self.getFilenamePrefix()) + happydoclib.TRACE.writeVar(filename_after_apply_prefix=filename) + happydoclib.TRACE.outof(filename) return filename *************** *** 142,149 **** --- 147,156 ---- filename=filename) filename = self.fixUpOutputFilename(filename) + happydoclib.TRACE.writeVar(filename=filename) # # Set the correct extension for the output file # extension = self.getFilenameExtension() + happydoclib.TRACE.writeVar(extension=extension) # # Build the name *************** *** 163,179 **** happydoclib.TRACE.into('FileBasedFormatter', 'getOutputNameForObject', infoObject=infoObject) if type(infoObject) == types.StringType: ! happydoclib.TRACE.write('string') name = infoObject elif type(infoObject) == types.FileType: ! happydoclib.TRACE.write('file') name = infoObject.name elif infoObject is not None: ! happydoclib.TRACE.write('infoObject') ! name = self.getOutputNameForFile(infoObject.getFullyQualifiedName()) happydoclib.TRACE.write('file for %s' % infoObject.getName()) happydoclib.TRACE.write('is %s' % name) else: ! name = self.getRootNodeName() happydoclib.TRACE.outof(name) return name --- 170,199 ---- happydoclib.TRACE.into('FileBasedFormatter', 'getOutputNameForObject', infoObject=infoObject) + if type(infoObject) == types.StringType: ! happydoclib.TRACE.write('object is a string') name = infoObject + elif type(infoObject) == types.FileType: ! happydoclib.TRACE.write('object is a file') name = infoObject.name + elif infoObject is not None: ! happydoclib.TRACE.write('object is an infoObject') ! #name = self.getOutputNameForFile(infoObject.getFullyQualifiedName()) ! name = apply(happydoclib.path.join, infoObject.getPath() ) ! name = '%s.%s' % (name, self.getFilenameExtension()) happydoclib.TRACE.write('file for %s' % infoObject.getName()) happydoclib.TRACE.write('is %s' % name) + else: ! happydoclib.TRACE.write('object is a root node') ! docset_path = self._docset.getPath() ! if docset_path: ! name = apply(happydoclib.path.join, docset_path ) ! name = happydoclib.path.join(name, self.getRootNodeName()) ! else: ! name = self.getRootNodeName() ! happydoclib.TRACE.outof(name) return name *************** *** 196,200 **** return name - def getFullOutputNameForObject(self, infoObject): """Get the full name, including path, to the object being output. --- 216,219 ---- *************** *** 206,209 **** --- 225,285 ---- happydoclib.TRACE.into('FileBasedFormatter', 'getFullOutputNameForObject', infoObject=infoObject) + + # + # Get the basic output name for the object + # + obj_output_name = self.getOutputNameForObject(infoObject) + # + # Get the root output directory + # + output_base = self._docset.getOutputBaseDirectory() + # + # Get the base input directory for the docset + # + docset_base_directory = self._docset.getDocsetBaseDirectory() + + happydoclib.TRACE.writeVar(obj_output_name=obj_output_name) + happydoclib.TRACE.writeVar(docset_base_directory=docset_base_directory) + happydoclib.TRACE.writeVar(output_base=output_base) + + if (not infoObject) and docset_base_directory: + # + # For a docset root node, just tack the object + # output name onto the output base directory. + # + happydoclib.TRACE.write('ROOT NODE FOR CURRENT DOCSET') + name = happydoclib.path.join(output_base, obj_output_name) + + elif docset_base_directory: + # + # Here we have a real HappyDOM based object. + # + happydoclib.TRACE.write('SUBNODE OF DOCSET') + #obj_parent_path = infoObject.getParent().getPath() + #obj_parent_path = infoObject.getPath() + #obj_parent_file_path = apply(os.path.join, obj_parent_path) + #output_dir = happydoclib.path.join(output_base, obj_parent_file_path) + name = happydoclib.path.join(output_base, obj_output_name) + + else: + happydoclib.TRACE.write('OTHER') + # + # How can we get here? + # + name = self.getOutputNameForObject(infoObject) + + happydoclib.TRACE.outof(name) + return name + + + def old_getFullOutputNameForObject(self, infoObject): + """Get the full name, including path, to the object being output. + + The prefix of the return value should be the output path for + all documentation. The rest of the return value will be based + on the path to the source for the object. + """ + happydoclib.TRACE.into('FileBasedFormatter', 'getFullOutputNameForObject', + infoObject=infoObject) obj_output_name = self.getOutputNameForObject(infoObject) *************** *** 216,246 **** if (not infoObject) and docset_base_directory: ! happydoclib.TRACE.write('root node for docset') # # Root node for docset # ! output_subdir = happydoclib.path.removePrefix(docset_base_directory, output_base) happydoclib.TRACE.writeVar(output_subdir=output_subdir) ! if os.name != 'nt': ! happydoclib.TRACE.write('adding prefix for os %s' % os.name) ! output_subdir = '%s%s' % (os.sep, output_subdir) happydoclib.TRACE.writeVar(output_subdir=output_subdir) ! if output_subdir != output_base: ! happydoclib.TRACE.write('output_subdir and output_base do not match') ! if output_subdir[0] == os.sep: ! output_subdir=output_subdir[1:] ! happydoclib.TRACE.writeVar(output_subdir=output_subdir) ! obj_output_sub_path = happydoclib.path.join(output_subdir, obj_output_name) ! happydoclib.TRACE.writeVar(obj_output_sub_path=obj_output_sub_path) ! obj_output_sub_path = self.fixUpOutputFilename(obj_output_sub_path) ! happydoclib.TRACE.writeVar(obj_output_sub_path=obj_output_sub_path) ! name = happydoclib.path.join(output_base, obj_output_sub_path) ! else: ! happydoclib.TRACE.write('output_subdir and output_base do match') ! name = happydoclib.path.join(output_base, obj_output_name) elif docset_base_directory: ! happydoclib.TRACE.write('subnode of docset') # # Subnode of docset --- 292,338 ---- if (not infoObject) and docset_base_directory: ! happydoclib.TRACE.write('ROOT NODE FOR CURRENT DOCSET') # # Root node for docset # ! happydoclib.TRACE.writeVar(docset_base_directory=docset_base_directory) ! happydoclib.TRACE.writeVar(output_base=output_base) ! ! common_prefix = happydoclib.path.commonPrefix(docset_base_directory, output_base) ! happydoclib.TRACE.writeVar(common_prefix=common_prefix) ! ! #output_subdir = happydoclib.path.removePrefix(docset_base_directory, output_base) ! output_subdir = happydoclib.path.removePrefix(docset_base_directory, common_prefix) happydoclib.TRACE.writeVar(output_subdir=output_subdir) ! output_subdir = happydoclib.path.join(output_base, output_subdir) happydoclib.TRACE.writeVar(output_subdir=output_subdir) ! name = happydoclib.path.join(output_subdir, obj_output_name) ! # if os.name != 'nt': ! # happydoclib.TRACE.write('adding prefix for os %s' % os.name) ! # output_subdir = '%s%s' % (os.sep, output_subdir) ! # happydoclib.TRACE.writeVar(output_subdir=output_subdir) ! # if output_subdir != output_base: ! # happydoclib.TRACE.write('output_subdir (%s) and' % output_subdir) ! # happydoclib.TRACE.write('and output_base (%s) do not match' % output_base) ! # if output_subdir[0] == os.sep: ! # output_subdir=output_subdir[1:] ! # elif os.name == 'nt': ! # drive, output_subdir = os.path.splitdrive(output_subdir) ! # happydoclib.TRACE.writeVar(output_subdir=output_subdir) ! # obj_output_sub_path = happydoclib.path.join(output_subdir, obj_output_name) ! # happydoclib.TRACE.writeVar(obj_output_sub_path=obj_output_sub_path) ! # obj_output_sub_path = self.fixUpOutputFilename(obj_output_sub_path) ! # if obj_output_sub_path[0] == os.sep: ! # obj_output_sub_path = obj_output_sub_path[1:] ! # happydoclib.TRACE.writeVar(obj_output_sub_path=obj_output_sub_path) ! ! # name = happydoclib.path.join(output_base, obj_output_sub_path) ! # else: ! # happydoclib.TRACE.write('output_subdir and output_base do match') ! # name = happydoclib.path.join(output_base, obj_output_name) elif docset_base_directory: ! happydoclib.TRACE.write('SUBNODE OF DOCSET') # # Subnode of docset *************** *** 248,252 **** file_name = self.getOutputNameForObject(infoObject) happydoclib.TRACE.writeVar(file_name=file_name) ! name = happydoclib.path.join(output_base, file_name) #name = happydoclib.path.joinWithCommonMiddle( # output_base, --- 340,354 ---- file_name = self.getOutputNameForObject(infoObject) happydoclib.TRACE.writeVar(file_name=file_name) ! ! common_prefix = happydoclib.path.commonPrefix(output_base, file_name) ! #common_prefix = happydoclib.path.commonPrefix(docset_base_directory, file_name) ! ! happydoclib.TRACE.writeVar(common_prefix=common_prefix) ! ! sub_file_name = happydoclib.path.removePrefix(file_name, common_prefix) ! happydoclib.TRACE.writeVar(sub_file_name=sub_file_name) ! ! name = happydoclib.path.join(output_base, sub_file_name) ! #name = happydoclib.path.join(output_base, file_name) #name = happydoclib.path.joinWithCommonMiddle( # output_base, *************** *** 256,260 **** else: ! happydoclib.TRACE.write('other') # # How can we get here? --- 358,362 ---- else: ! happydoclib.TRACE.write('OTHER') # # How can we get here? *************** *** 289,296 **** --- 391,404 ---- output_base_dir = os.sep + os.path.join('tmp', 'fakedocset', 'output') + if os.name == 'nt': + output_base_dir_win32 = 'c:\\%s' % output_base_dir[1:] def setUp(self): class FakeDocset: + + def getPath(self): + return [ ] + def getOutputBaseDirectory(self): return FileFormatterBaseTest.output_base_dir *************** *** 298,301 **** --- 406,416 ---- def getDocsetBaseDirectory(self): return os.sep + os.path.join('docset', 'base', 'directory') + + class FakeDocsetWin32: + def getOutputBaseDirectory(self): + return FileFormatterBaseTest.output_base_dir_win32 + + def getDocsetBaseDirectory(self): + return 'c:\\' + os.path.join('docset', 'base', 'directory') class TestFormatter(FileBasedFormatter): *************** *** 306,309 **** --- 421,425 ---- self.formatter = TestFormatter(FakeDocset()) + self.formatter_win32 = TestFormatter(FakeDocsetWin32()) return *************** *** 317,320 **** --- 433,446 ---- return + if os.name == 'nt': + def testFixUpOutputFilenameFromRootWin32(self): + expected = 'c:\\' + os.path.join('fix', 'up', 'filename') + actual = self.formatter.fixUpOutputFilename( + 'c:\\' + os.path.join('fix', 'up', 'filename') + ) + assert expected == actual, \ + 'Fixed filenames do not match ("%s" vs. "%s").' % (expected, actual) + return + def testFixUpOutputFilenameParentDir(self): expected = os.path.join('fix', 'up', 'filename') *************** *** 375,382 **** pass info_obj = FakeInfoObj('myfake', None, 'filename.py', []) ! expected = 'filename.py.test' actual = self.formatter.getOutputNameForObject(info_obj) assert expected == actual, \ ! 'Output name for object does not match ("%s" vs "%s")' % \ (expected, actual) return --- 501,508 ---- pass info_obj = FakeInfoObj('myfake', None, 'filename.py', []) ! expected = 'myfake.test' actual = self.formatter.getOutputNameForObject(info_obj) assert expected == actual, \ ! 'Output name for object does not match (\n"%s"\nvs\n"%s")' % \ (expected, actual) return *************** *** 388,395 **** parent_obj = FakeInfoObj('myfakeparent', None, 'parent', []) info_obj = FakeInfoObj('myfake', parent_obj, 'filename.py', []) ! expected = 'parent_myfake.test' actual = self.formatter.getOutputNameForObject(info_obj) assert expected == actual, \ ! 'Output name for object does not match ("%s" vs "%s")' % \ (expected, actual) return --- 514,521 ---- parent_obj = FakeInfoObj('myfakeparent', None, 'parent', []) info_obj = FakeInfoObj('myfake', parent_obj, 'filename.py', []) ! expected = 'myfakeparent/myfake.test' actual = self.formatter.getOutputNameForObject(info_obj) assert expected == actual, \ ! 'Output name for object does not match (\n"%s"\nvs\n"%s")' % \ (expected, actual) return *************** *** 424,452 **** class FakeInfoObj(happydoclib.happydom.HappyDOM): pass ! info_obj = FakeInfoObj('myfake', None, 'filename.py', []) expected = os.sep + os.path.join('tmp', 'fakedocset', 'output', ! 'filename.py.test' ) actual = self.formatter.getFullOutputNameForObject(info_obj) assert expected == actual, \ ! 'Output name for object does not match ("%s" vs "%s")' % \ (expected, actual) return def testGetFullOutputNameForObjectNone(self): info_obj = None ! expected = os.sep + os.path.join('tmp', ! 'fakedocset', ! 'output', ! 'docset', ! 'base', ! 'directory', ! 'index.test' ! ) actual = self.formatter.getFullOutputNameForObject(info_obj) assert expected == actual, \ ! 'Output name for object does not match ("%s" vs "%s")' % \ (expected, actual) return def testGetFullOutputNameForObjectFullyQualifiedNameOneParent(self): --- 550,612 ---- class FakeInfoObj(happydoclib.happydom.HappyDOM): pass ! info_obj = FakeInfoObj('filename', None, 'filename.py', []) expected = os.sep + os.path.join('tmp', 'fakedocset', 'output', ! 'filename.test' ) actual = self.formatter.getFullOutputNameForObject(info_obj) assert expected == actual, \ ! 'Output name for object does not match\n(\n"%s"\nvs\n"%s")' % \ (expected, actual) return + if os.name == 'nt': + def testGetFullOutputNameForObjectFullyQualifiedNameRootWin32(self): + import happydoclib + import happydoclib.happydom + happydoclib.TRACE.verboseLevel = 1 + class FakeInfoObj(happydoclib.happydom.HappyDOM): + pass + info_obj = FakeInfoObj('myfake', None, 'filename.py', []) + expected = happydoclib.path.join( + 'c:\\', + os.path.join('tmp', 'fakedocset', 'output', 'filename.py.test') + ) + actual = self.formatter_win32.getFullOutputNameForObject(info_obj) + assert expected == actual, \ + 'Output name for object does not match (expect "%s", got "%s")' % \ + (expected, actual) + return + def testGetFullOutputNameForObjectNone(self): info_obj = None ! expected = os.sep + os.path.join( ! 'tmp', ! 'fakedocset', ! 'output', ! 'index.test' ! ) actual = self.formatter.getFullOutputNameForObject(info_obj) assert expected == actual, \ ! 'Output name for object does not match (\n"%s"\nvs\n"%s")' % \ (expected, actual) return + + if os.name == 'nt': + def testGetFullOutputNameForObjectNoneWin32(self): + info_obj = None + expected = os.path.join('c:\\', + 'tmp', + 'fakedocset', + 'output', + 'docset', + 'base', + 'directory', + 'index.test' + ) + actual = self.formatter_win32.getFullOutputNameForObject(info_obj) + assert expected == actual, \ + 'Output name for object does not match (expected "%s", got "%s")' % \ + (expected, actual) + return def testGetFullOutputNameForObjectFullyQualifiedNameOneParent(self): *************** *** 454,465 **** class FakeInfoObj(happydoclib.happydom.HappyDOM): pass ! parent_obj = FakeInfoObj('myfakeparent', None, 'parent', []) info_obj = FakeInfoObj('myfake', parent_obj, 'filename.py', []) expected = os.sep + os.path.join('tmp', 'fakedocset', 'output', ! 'parent_myfake.test' ) actual = self.formatter.getFullOutputNameForObject(info_obj) assert expected == actual, \ ! 'Output name for object does not match ("%s" vs "%s")' % \ (expected, actual) return --- 614,625 ---- class FakeInfoObj(happydoclib.happydom.HappyDOM): pass ! parent_obj = FakeInfoObj('myfakeparentname', None, 'myfakeparentfilename', []) info_obj = FakeInfoObj('myfake', parent_obj, 'filename.py', []) expected = os.sep + os.path.join('tmp', 'fakedocset', 'output', ! 'myfakeparentname', 'myfake.test' ) actual = self.formatter.getFullOutputNameForObject(info_obj) assert expected == actual, \ ! 'Output name for object does not match\n(\n"%s"\nvs\n"%s")' % \ (expected, actual) return *************** *** 472,476 **** actual = self.formatter.getFullOutputNameForFile(filename) assert expected == actual, \ ! 'Output name for file does not match ("%s" vs "%s")' % \ (expected, actual) return --- 632,636 ---- actual = self.formatter.getFullOutputNameForFile(filename) assert expected == actual, \ ! 'Output name for file does not match\n(\n"%s"\nvs\n"%s")' % \ (expected, actual) return *************** *** 484,488 **** actual = self.formatter.getFullOutputNameForFile(filename) assert expected == actual, \ ! 'Output name for file does not match ("%s" vs "%s")' % \ (expected, actual) return --- 644,648 ---- actual = self.formatter.getFullOutputNameForFile(filename) assert expected == actual, \ ! 'Output name for file does not match\n(\n"%s"\nvs\n"%s")' % \ (expected, actual) return Index: formatter_HTMLFile.py =================================================================== RCS file: /cvsroot/happydoc/HappyDoc/happydoclib/formatter/formatter_HTMLFile.py,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -C2 -d -r1.5 -r1.5.2.1 *** formatter_HTMLFile.py 10 Feb 2002 13:37:12 -0000 1.5 --- formatter_HTMLFile.py 13 May 2002 01:14:44 -0000 1.5.2.1 *************** *** 211,222 **** # Figure out the name of the infoSource # - - if not name: - name = self.getNameForInfoSource( infoSource ) happydoclib.TRACE.into('HTMLTableFormatter', 'getReference', name=name, relativeSource=relativeSource, ) ! info_source_path = self.getOutputNameForObject( infoSource ) link = happydoclib.path.computeRelativeHTMLLink( relativeSource, --- 211,230 ---- # Figure out the name of the infoSource # happydoclib.TRACE.into('HTMLTableFormatter', 'getReference', + infoSource=infoSource, name=name, relativeSource=relativeSource, ) ! ! if hasattr(infoSource, 'getPath'): ! path = infoSource.getPath() ! happydoclib.TRACE.writeVar(path=path) ! if not name: ! name = self.getNameForInfoSource( infoSource ) ! happydoclib.TRACE.writeVar(name=name) ! ! info_source_path = self.getFullOutputNameForObject( infoSource ) ! happydoclib.TRACE.writeVar(info_source_path=info_source_path) ! link = happydoclib.path.computeRelativeHTMLLink( relativeSource, *************** *** 224,228 **** self._docset.getOutputBaseDirectory() ) ! happydoclib.TRACE.write('link to %s: %s' % (name, link)) if link[0] == '/': happydoclib.TRACE.write('starts at root') --- 232,237 ---- self._docset.getOutputBaseDirectory() ) ! happydoclib.TRACE.write('Name is "%s"' % name) ! happydoclib.TRACE.writeVar(link=link) if link[0] == '/': happydoclib.TRACE.write('starts at root') *************** *** 235,239 **** --- 244,253 ---- } ref = '<a href="%(link)s">%(name)s</a>' % info + #if link=='formatterloader.html': + # raise 'DEBUG HERE' + #print 'REFERENCE:', ref + return happydoclib.TRACE.outof(ref) + *************** *** 431,441 **** <table border="0" cellpadding="5" cellspacing="0" width="100%%"> ! <tr bgcolor="%(title_bg)s"> <th rowspan="2" valign="top" align="left" ! width="10%%"><font color="%(title_fg)s">%(title)s</font> </th> - <th width="90%%" align="right"><font color="%(title_fg)s">%(subtitle)s</font></th> </tr> <tr> --- 445,459 ---- <table border="0" cellpadding="5" cellspacing="0" width="100%%"> ! <tr> <th rowspan="2" valign="top" align="left" ! width="10%%" ! bgcolor="%(title_bg)s"><font color="%(title_fg)s">%(title)s</font> ! </th> ! <th bgcolor="%(title_bg)s" ! width="90%%" ! align="right"><font color="%(title_fg)s">%(subtitle)s</font> </th> </tr> <tr> *************** *** 664,668 **** def descriptiveListItem(self, output, item, description, descriptionFormat): "Format and write the 'item' and 'description' for a descriptive list to the 'output'." ! self.writeHTML('<tr><td valign="top" align="left">%s</td>' % item, output) self.writeHTML('<td valign="top" align="left">', output) --- 682,686 ---- def descriptiveListItem(self, output, item, description, descriptionFormat): "Format and write the 'item' and 'description' for a descriptive list to the 'output'." ! self.writeHTML('<tr><td valign="top" align="left"><p>%s</p></td>' % item, output) self.writeHTML('<td valign="top" align="left">', output) *************** *** 804,808 **** formatter = docset._formatter reference = formatter.getNamedReference( cla, 'CommandLineApp', 'index.html' ) ! expected_reference = '<a href="happydoclib%sCommandLineApp.py.html#CommandLineApp">CommandLineApp</a>' % os.sep assert reference == expected_reference, 'Got reference "%s" instead of "%s"' % \ (reference, expected_reference) --- 822,826 ---- formatter = docset._formatter reference = formatter.getNamedReference( cla, 'CommandLineApp', 'index.html' ) ! expected_reference = '<a href="CommandLineApp.html#CommandLineApp">CommandLineApp</a>' assert reference == expected_reference, 'Got reference "%s" instead of "%s"' % \ (reference, expected_reference) |