Modify

Opened 12 years ago

Closed 12 years ago

#141 closed enhancement (fixed)

Show only specific modules

Reported by: Noah Kantrowitz Owned by: Alec Thomas
Priority: normal Component: PyDocPlugin
Severity: normal Keywords:
Cc: Noah Kantrowitz Trac Release:

Description

Here is the diff for this. Its a very ugly hack, but it does work. Configuration is via the show parameter in trac.ini.

  • tracpydoc/tracpydoc.py

     
    77from trac.util import escape, shorten_line
    88from trac.wiki.api import IWikiSyntaxProvider, IWikiMacroProvider
    99from trac.Search import ISearchSource
     10import inspect, os
     11from pydoc import ispackage
    1012
    1113try:
    1214    from trac.util import Markup
     
    4547    def __init__(self, env):
    4648        self.env = env
    4749
     50    def index(self, dir, shadowed=None, show=None):
     51        """Generate an HTML index for a directory of modules."""
     52        modpkgs = []
     53        if shadowed is None: shadowed = {}
     54        seen = {}
     55        files = os.listdir(dir)
     56
     57        def found(name, ispackage,
     58                  modpkgs=modpkgs, shadowed=shadowed, seen=seen):
     59            if name not in seen:
     60                modpkgs.append((name, '', ispackage, name in shadowed))
     61                seen[name] = 1
     62                shadowed[name] = 1
     63
     64        # Package spam/__init__.py takes precedence over module spam.py.
     65        for file in files:
     66            path = os.path.join(dir, file)
     67            if show:
     68                if ispackage(path) and file in show: found(file, 1)
     69            else:
     70                if ispackage(path): found(file, 1)
     71        for file in files:
     72            path = os.path.join(dir, file)
     73            if os.path.isfile(path):
     74                modname = inspect.getmodulename(file)
     75                if show:
     76                    if modname and modname in show: found(modname, 0)
     77                else:
     78                    if modname: found(modname, 0)
     79
     80        modpkgs.sort()
     81        contents = self.multicolumn(modpkgs, self.modpkglink)
     82        if modpkgs:
     83            return self.bigsection(dir, '#ffffff', '#ee77aa', contents)
     84        else:
     85            return ''
     86
    4887    def modulelink(self, obj):
    4988        return '<a href="%s">%s</a>' % \
    5089               (self.env.href.pydoc(obj.__name__), obj.__name__)
     
    104143                            syspath.split(os.pathsep)]
    105144        else:
    106145            self.syspath = sys.path
     146
     147       self.show = self.config.get('pydoc', 'show', None)
     148       if self.show: self.show = [p.rstrip('.*') for p in self.show.split()]
     149
    107150        show_private = self.config.get('pydoc', 'show_private', '')
    108151        self.show_private = [p.rstrip('.*') for p in show_private.split()]
    109152        self.makedoc_lock = threading.Lock()
     
    161204                    doc = '<h1>Python: Index of Modules</h1>'
    162205                for dir in self.syspath:
    163206                    if os.path.isdir(dir):
    164                         doc += self.doc.index(dir)
     207                        doc += self.doc.index(dir, show=self.show)
    165208                return doc
    166209            else:
    167210                if inline:

Attachments (0)

Change History (1)

comment:1 Changed 12 years ago by Alec Thomas

Resolution: fixed
Status: newclosed

(In [372]) * Added filtering of what gets displayed, thanks to coderanger. Closes #141.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Alec Thomas.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.