Modify ↓
Opened 19 years ago
Closed 19 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
7 7 from trac.util import escape, shorten_line 8 8 from trac.wiki.api import IWikiSyntaxProvider, IWikiMacroProvider 9 9 from trac.Search import ISearchSource 10 import inspect, os 11 from pydoc import ispackage 10 12 11 13 try: 12 14 from trac.util import Markup … … 45 47 def __init__(self, env): 46 48 self.env = env 47 49 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 48 87 def modulelink(self, obj): 49 88 return '<a href="%s">%s</a>' % \ 50 89 (self.env.href.pydoc(obj.__name__), obj.__name__) … … 104 143 syspath.split(os.pathsep)] 105 144 else: 106 145 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 107 150 show_private = self.config.get('pydoc', 'show_private', '') 108 151 self.show_private = [p.rstrip('.*') for p in show_private.split()] 109 152 self.makedoc_lock = threading.Lock() … … 161 204 doc = '<h1>Python: Index of Modules</h1>' 162 205 for dir in self.syspath: 163 206 if os.path.isdir(dir): 164 doc += self.doc.index(dir )207 doc += self.doc.index(dir, show=self.show) 165 208 return doc 166 209 else: 167 210 if inline:
Attachments (0)
Note: See
TracTickets for help on using
tickets.
(In [372]) * Added filtering of what gets displayed, thanks to coderanger. Closes #141.