Changeset 377

Show
Ignore:
Timestamp:
01/19/06 23:49:38 (3 years ago)
Author:
athomas
Message:

PyDocPlugin:

  • Updated search to respect include/exclude filters.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pydocplugin/0.9/tracpydoc/tracpydoc.py

    r373 r377  
    6363                shadowed[name] = 1 
    6464 
    65         def matched(file): 
    66             for match in excludes: 
    67                 if fnmatch(file, match): 
    68                     return 0 
    69             for match in includes: 
    70                 if fnmatch(file, match): 
    71                     self.env.log.debug(file + ',' + match) 
    72                     return 1 
    73             return not includes and not excludes 
     65        matched = PyDoc(self.env).filter_match 
    7466 
    7567        # Package spam/__init__.py takes precedence over module spam.py. 
    76  
    77         # Do matching against include/exclude list 
    7868        for file in files: 
    7969            path = os.path.join(dir, file) 
     
    155145            self.syspath = sys.path 
    156146 
    157         self.includes = [p for p in self.config.get('pydoc', 
    158                          'include', '').split() if p] 
    159         self.excludes = [p for p in self.config.get('pydoc', 
    160                          'exclude', '').split() if p] 
     147        self.includes, self.excludes = self.get_filters() 
    161148 
    162149        show_private = self.config.get('pydoc', 'show_private', '') 
    163150        self.show_private = [p.rstrip('.*') for p in show_private.split()] 
    164151        self.makedoc_lock = threading.Lock() 
     152 
     153    def filter_match(self, file): 
     154        includes, excludes = self.get_filters() 
     155        for match in excludes: 
     156            if fnmatch(file, match): 
     157                return 0 
     158        for match in includes: 
     159            if fnmatch(file, match): 
     160                return 1 
     161        return not includes 
     162 
     163 
     164    def get_filters(self): 
     165        return ([p for p in self.config.get('pydoc', 
     166                         'include', '').split() if p], 
     167                [p for p in self.config.get('pydoc', 
     168                         'exclude', '').split() if p]) 
    165169 
    166170    def load_object(self, fullobject): 
     
    366370 
    367371    def get_search_filters(self, req): 
    368         yield ('pydoc', 'Python Documentation'
     372        yield ('pydoc', 'Python Documentation', 0
    369373 
    370374    def get_search_results(self, req, query, filters): 
    371375        query = query.split() 
    372376        results = [] 
     377        matched = PyDoc(self.env).filter_match 
    373378        if 'pydoc' in filters: 
    374379            def callback(path, modname, desc): 
    375380                for q in query: 
     381                    if (path and not matched(path)) and (modname and not matched(modname)): 
     382                        return 
    376383                    if q in modname or q.lower() in desc.lower(): 
    377384                        results.append((self.env.href.pydoc(modname), modname,