[svn r41080] Added support for filtering listdir() calls in the SourcePageBuilder, using it

to filter out hidden files and the 'build' subdir of greenlet.

--HG--
branch : trunk
This commit is contained in:
guido 2007-03-22 16:06:41 +01:00
parent e3715545fb
commit 417d97c850
3 changed files with 25 additions and 17 deletions

View File

@ -31,6 +31,11 @@ def get_documentable_items(pkgdir):
Channel.__apigen_hide_from_nav__ = True Channel.__apigen_hide_from_nav__ = True
return pkgname, pkgdict return pkgname, pkgdict
def sourcedirfilter(p):
return ('.svn' not in str(p).split(p.sep) and
not p.basename.startswith('.') and
str(p).find('c-extension%sgreenlet%sbuild' % (p.sep, p.sep)) == -1)
def build(pkgdir, dsa, capture): def build(pkgdir, dsa, capture):
# create a linker (link database) for cross-linking # create a linker (link database) for cross-linking
l = linker.TempLinker() l = linker.TempLinker()
@ -51,7 +56,7 @@ def build(pkgdir, dsa, capture):
apb = htmlgen.ApiPageBuilder(targetdir, l, dsa, pkgdir, namespace_tree, apb = htmlgen.ApiPageBuilder(targetdir, l, dsa, pkgdir, namespace_tree,
proj, capture, LayoutPage) proj, capture, LayoutPage)
spb = htmlgen.SourcePageBuilder(targetdir, l, pkgdir, proj, capture, spb = htmlgen.SourcePageBuilder(targetdir, l, pkgdir, proj, capture,
LayoutPage) LayoutPage, dirfilter=sourcedirfilter)
apb.build_namespace_pages() apb.build_namespace_pages()
class_names = dsa.get_class_names() class_names = dsa.get_class_names()

View File

@ -81,7 +81,7 @@ def get_param_htmldesc(linker, func):
return inspect.formatargspec(*inspect.getargspec(func)) return inspect.formatargspec(*inspect.getargspec(func))
# some helper functionality # some helper functionality
def source_dirs_files(fspath): def source_dirs_files(fspath, fil=None):
""" returns a tuple (dirs, files) for fspath """ returns a tuple (dirs, files) for fspath
dirs are all the subdirs, files are the files which are interesting dirs are all the subdirs, files are the files which are interesting
@ -93,7 +93,7 @@ def source_dirs_files(fspath):
""" """
dirs = [] dirs = []
files = [] files = []
for child in fspath.listdir(): for child in fspath.listdir(fil=fil):
if child.basename.startswith('.'): if child.basename.startswith('.'):
continue continue
if child.check(dir=True): if child.check(dir=True):
@ -203,13 +203,14 @@ class AbstractPageBuilder(object):
class SourcePageBuilder(AbstractPageBuilder): class SourcePageBuilder(AbstractPageBuilder):
""" builds the html for a source docs page """ """ builds the html for a source docs page """
def __init__(self, base, linker, projroot, project, capture=None, def __init__(self, base, linker, projroot, project, capture=None,
pageclass=LayoutPage): pageclass=LayoutPage, dirfilter=None):
self.base = base self.base = base
self.linker = linker self.linker = linker
self.projroot = projroot self.projroot = projroot
self.project = project self.project = project
self.capture = capture self.capture = capture
self.pageclass = pageclass self.pageclass = pageclass
self.dirfilter = dirfilter
def build_navigation(self, fspath): def build_navigation(self, fspath):
nav = H.Navigation(class_='sidebar') nav = H.Navigation(class_='sidebar')
@ -240,7 +241,7 @@ class SourcePageBuilder(AbstractPageBuilder):
else: else:
# we're a file, build our parent's children only # we're a file, build our parent's children only
dirpath = fspath.dirpath() dirpath = fspath.dirpath()
diritems, fileitems = source_dirs_files(dirpath) diritems, fileitems = source_dirs_files(dirpath, self.dirfilter)
for dir in diritems: for dir in diritems:
nav.append(H.NavigationItem(self.linker, dir.strpath, dir.basename, nav.append(H.NavigationItem(self.linker, dir.strpath, dir.basename,
indent, False)) indent, False))
@ -265,7 +266,7 @@ class SourcePageBuilder(AbstractPageBuilder):
return tag, nav return tag, nav
def build_dir_page(self, fspath): def build_dir_page(self, fspath):
dirs, files = source_dirs_files(fspath) dirs, files = source_dirs_files(fspath, self.dirfilter)
dirs = [(p.basename, self.linker.get_lazyhref(str(p))) for p in dirs] dirs = [(p.basename, self.linker.get_lazyhref(str(p))) for p in dirs]
files = [(p.basename, self.linker.get_lazyhref(str(p))) for p in files] files = [(p.basename, self.linker.get_lazyhref(str(p))) for p in files]
tag = H.DirList(dirs, files) tag = H.DirList(dirs, files)
@ -281,7 +282,15 @@ class SourcePageBuilder(AbstractPageBuilder):
return tag, nav return tag, nav
def build_pages(self, base): def build_pages(self, base):
for fspath in [base] + list(base.visit()): def visit(p):
dirs, files = source_dirs_files(p, self.dirfilter)
for d in dirs:
yield d
for sp in visit(d):
yield sp
for f in files:
yield f
for fspath in [base] + list(visit(base)):
if fspath.ext in ['.pyc', '.pyo']: if fspath.ext in ['.pyc', '.pyo']:
continue continue
if self.capture: if self.capture:

View File

@ -62,10 +62,6 @@
border: 0px; border: 0px;
} }
#hosts {
width: 100%;
}
</style> </style>
</head> </head>
<body onload="main()"> <body onload="main()">
@ -114,12 +110,10 @@
</table> </table>
<fieldset id="messagebox_fieldset"> <fieldset id="messagebox_fieldset">
<legend><b>Data [<a href="javascript:hide_messagebox()">hide</a>]:</b></legend> <legend><b>Data [<a href="javascript:hide_messagebox()">hide</a>]:</b></legend>
<a name="message"> <a name="message"> </a>
<div id="messagebox"></div> <div id="messagebox"></div>
</a>
</fieldset> </fieldset>
<a name="aftermessage"> <a name="aftermessage"> </a>
<div id="testmain"></div> <div id="testmain"></div>
</a>
</body> </body>
</html> </html>