Changeset 1129

Show
Ignore:
Timestamp:
08/17/06 08:49:20 (2 years ago)
Author:
Blackhex
Message:

DoxygenPlugin:

  • Support for exended documentation referencing.
  • Bug with searching in multiple documentations fix.
  • Minor bug in reading searching index fix.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • doxygenplugin/0.9/doxygentrac/doxygentrac.py

    r1010 r1129  
    4343    def get_navigation_items(self, req): 
    4444        if req.perm.has_permission('DOXYGEN_VIEW'): 
    45             # Get config variables 
     45            # Get config variables. 
    4646            title = self.env.config.get('doxygen', 'title', 'Doxygen') 
    4747 
    48             # Return mainnav buttons 
     48            # Return mainnav buttons. 
    4949            yield 'mainnav', 'doxygen', Markup('<a href="%s">%s</a>' % \ 
    5050              (self.env.href.doxygen() + '/', title)) 
     
    5353 
    5454    def match_request(self, req): 
    55         # Get config variables 
     55        # Get config variables. 
    5656        base_path = self.config.get('doxygen', 'path', '/var/lib/trac/doxygen') 
     57        default_project = self.config.get('doxygen', 'default_project', '') 
    5758        ext = self.config.get('doxygen', 'ext', 'htm html png') 
    5859        ext = '|'.join(ext.split(' ')) 
    59  
    60         # Match index 
    61         if re.match('^/doxygen/$', req.path_info): 
    62             req.args['path'] = base_path 
    63             req.args['type'] = 'index' 
     60        source_ext = self.config.get('doxygen', 'source_ext', 'idl odl java' \ 
     61          ' cs py php php4 inc phtml m cpp cxx c hpp hxx h') 
     62        source_ext = '|'.join(source_ext.split(' ')) 
     63 
     64        # Match documentation request. 
     65        self.log.debug(req.path_info) 
     66        match = re.match('^/doxygen(?:/?$|/([^/]*)(?:/?$|/(.*)$))', 
     67          req.path_info) 
     68        if match: 
     69            self.log.debug('matched group 1: %s' % (match.group(1),)) 
     70            self.log.debug('matched group 2: %s' % (match.group(2),)) 
     71 
     72            if not match.group(1) and not match.group(2): 
     73                # Request for documentation index. 
     74                req.args['path'] = os.path.join(base_path, default_project) 
     75                req.args['action'] = 'index' 
     76            else: 
     77                # Get project and file from request. 
     78                if not match.group(2): 
     79                    project = default_project 
     80                    file = match.group(1) 
     81                else: 
     82                    project = match.group(1) 
     83                    file = match.group(2) 
     84 
     85                self.log.debug('project: %s' % (project,)) 
     86                self.log.debug('file: %s' % (file,)) 
     87 
     88                if re.match(r'''^search.php$''', file): 
     89                    # Request for searching. 
     90                    req.args['action'] = 'search' 
     91 
     92                elif re.match(r'''^(.*)[.](%s)''' % (ext,), file): 
     93                    # Request for documentation file. 
     94                    path = os.path.join(base_path, project, file) 
     95                    self.log.debug('path: %s' % (path,)) 
     96                    if os.path.exists(path): 
     97                        req.args['path'] = path 
     98                        req.args['action'] = 'file' 
     99                    else: 
     100                        req.args['action'] = 'search' 
     101                        req.args['query'] = file 
     102 
     103                else: 
     104                    match = re.match(r'''^(.*)[.](%s)''' % (source_ext,), file) 
     105                    if match: 
     106                        # Request for source file documentation. 
     107                        path = os.path.join(base_path, project, '%s_8%s.html' 
     108                          % (match.group(1), match.group(2))) 
     109                        self.log.debug('path: %s' % (path,)) 
     110                        if os.path.exists(path): 
     111                            req.args['path'] = path 
     112                            req.args['action'] = 'file' 
     113                        else: 
     114                            req.args['action'] = 'search' 
     115                            req.args['query'] = file 
     116 
     117                    else: 
     118                        path = os.path.join(base_path, project, 'class%s.html' 
     119                          % (file,)) 
     120                        if os.path.exists(path): 
     121                            req.args['path'] = path 
     122                            req.args['action'] = 'file' 
     123                        else: 
     124                            path = os.path.join(base_path, project, 
     125                              'struct%s.html' % (file,)) 
     126                            if os.path.exists(path): 
     127                                req.args['path'] = path 
     128                                req.args['action'] = 'file' 
     129                            else: 
     130                                results = self._search_in_project(project, 
     131                                  [file]) 
     132                                for result in results: 
     133                                    self.log.debug(result) 
     134                                    if result['name'] == file: 
     135                                        req.redirect(self.env.href.doxygen( 
     136                                          project) + '/' + result['url']) 
     137                                req.args['action'] = 'search' 
     138                                req.args['query'] = file 
     139 
     140            # Request matched. 
    64141            return True 
    65142 
    66         # Match searching request 
    67         if re.match('^/doxygen/search.php$', req.path_info): 
    68             return True 
    69  
    70         # Match request if requested file exists 
    71         elif re.match(r'''^/doxygen/.*[.](%s)$''' % (ext), req.path_info): 
    72             file = re.sub('^/doxygen', '', req.path_info) 
    73             path = base_path + file 
    74             req.args['path'] = path 
    75             req.args['type'] = mimetypes.guess_type(path)[0] 
    76             return os.path.exists(path) 
    77143        else: 
     144            # Request not matched. 
    78145            return False 
    79146 
    80147    def process_request(self, req): 
     148        req.perm.assert_permission('DOXYGEN_VIEW') 
     149 
    81150        # Get request arguments 
    82151        path = req.args.get('path') 
    83         type = req.args.get('type') 
     152        action = req.args.get('action') 
    84153 
    85154        # Get config variables 
     
    87156        wiki_index = self.config.get('doxygen', 'wiki_index', None) 
    88157 
    89         # Retrun apropriate content to type or search request 
    90         if req.args.has_key('query')
     158        # Redirect search requests. 
     159        if action == 'search'
    91160            req.redirect('%s?q=%s&doxygen=on' % (self.env.href.search(), 
    92161              req.args.get('query'))) 
    93             return None, None 
    94         elif type == 'index': 
     162 
     163        # Retrun apropriate content to type or search request 
     164        elif action == 'index': 
    95165            if wiki_index: 
    96166                # Get access to database 
     
    101171                sql = "SELECT text FROM wiki WHERE name = %s" 
    102172                cursor.execute(sql, (wiki_index,)) 
    103                 text = Markup(system_message('Error', 'Wiki page %s does not exists' % (wiki_index))) 
     173                text = Markup(system_message('Error', 'Wiki page %s does not' \ 
     174                  ' exists' % (wiki_index))) 
    104175                for row in cursor: 
    105176                    text = wiki_to_html(row[0], self.env, req) 
     
    112183                req.hdf['doxygen.path'] = path + '/' + index 
    113184                return 'doxygen.cs', 'text/html' 
    114         elif type == 'text/html': 
    115             add_stylesheet(req, 'doxygen/css/doxygen.css') 
    116             req.hdf['doxygen.path'] = path 
    117             return 'doxygen.cs', type 
    118         else: 
    119             req.send_file(path, type) 
    120             return None, None 
     185 
     186        elif action == 'file': 
     187            type = mimetypes.guess_type(path)[0] 
     188 
     189            if type == 'text/html': 
     190                add_stylesheet(req, 'doxygen/css/doxygen.css') 
     191                req.hdf['doxygen.path'] = path 
     192                return 'doxygen.cs', 'text/html' 
     193            else: 
     194                req.send_file(path, type) 
    121195 
    122196    # ITemplateProvider methods 
     
    147221            keywords = query.split(' ') 
    148222 
    149         path = self.config.get('doxygen', 'path') 
    150         path = os.path.join(path, 'search.idx') 
    151  
    152         if os.path.exists(path): 
    153             fd = open(path) 
    154  
     223        base_path = self.config.get('doxygen', 'path') 
     224 
     225        for project in os.listdir(base_path): 
     226            # Search in project documentation directories 
     227            path = os.path.join(base_path, project) 
     228            if os.path.isdir(path): 
     229                index = os.path.join(path, 'search.idx') 
     230                if os.path.exists(index): 
     231                    creation = os.path.getctime(index) 
     232                    for result in  self._search_in_project(project, keywords): 
     233                        result['url'] =  self.env.href.doxygen(project) + '/' \ 
     234                          + result['url'] 
     235                        yield result['url'], result['name'], creation, \ 
     236                          'doxygen', None 
     237 
     238            # Search in common documentation directory 
     239            index = os.path.join(base_path, 'search.idx') 
     240            if os.path.exists(index): 
     241                creation = os.path.getctime(index) 
     242                for result in self._search_in_project('', keywords): 
     243                    result['url'] =  self.env.href.doxygen() + '/' + \ 
     244                      result['url'] 
     245                    yield result['url'], result['name'], creation, 'doxygen', \ 
     246                      None 
     247 
     248    # IWikiSyntaxProvider 
     249    def get_link_resolvers(self): 
     250        yield ('doxygen', self._doxygen_link) 
     251 
     252    def get_wiki_syntax(self): 
     253        return [] 
     254 
     255    # internal methods 
     256    def _search_in_project(self, project, keywords): 
     257        # Open index file for project documentation 
     258        base_path = self.config.get('doxygen', 'path') 
     259        index = os.path.join(base_path, project, 'search.idx') 
     260        if os.path.exists(index): 
     261            fd = open(index) 
     262 
     263            # Search for keywords in index 
    155264            results = [] 
    156265            for keyword in keywords: 
    157266                results += self._search(fd, keyword) 
    158  
    159             results.sort(compare_rank) 
    160  
    161             # use the creation time for the search.idx file for all results 
    162             creation = os.path.getctime(path) 
    163  
    164             for result in results: 
    165                 yield 'doxygen/' + result['url'], result['name'], creation, 'doxygen', None 
    166  
    167     # IWikiSyntaxProvider 
    168     def get_link_resolvers(self): 
    169         yield ('doxygen', self._doxygen_link) 
    170  
    171     def get_wiki_syntax(self): 
    172         return [] 
    173  
    174  
    175     # internal methods 
     267                results.sort(compare_rank) 
     268                for result in results: 
     269                    yield result 
    176270 
    177271    def _search(self, fd, word): 
     
    258352 
    259353    def _readString(self, fd): 
     354        result = '' 
    260355        byte = fd.read(1) 
    261         if byte == '\0': 
    262             return '' 
    263         result = byte 
    264356        while byte != '\0': 
     357            result = ''.join([result, byte]) 
    265358            byte = fd.read(1) 
    266             result = ''.join([result, byte]) 
    267  
    268359        return result 
    269360 
  • doxygenplugin/0.9/setup.py

    r1010 r1129  
    77    description='Doxygen plugin for Trac', 
    88    keywords='trac doxygen', 
    9     version='0.3', 
    10     url='http://trac-hacks.swapoff.org/wiki/DoxygenPlugin', 
     9    version='0.4', 
     10    url='http://trac-hacks.org/wiki/DoxygenPlugin', 
    1111    license = """Copyright (C) 2005 Jason Parks <jparks@jparks.net> 
    1212All rights reserved. 
     
    3838IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.""", 
    3939    author='Jason Parks, Radek Bartoň', 
    40     author_email='jparks@jparks.net', 
     40    author_email='blackhex@post.cz', 
    4141    long_description=""" 
    4242    """,