Changeset 1209

Show
Ignore:
Timestamp:
08/30/06 17:29:22 (2 years ago)
Author:
Blackhex
Message:

DoxygenPlugin:

Initial commit of 0.10 branch.

Files:

Legend:

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

    r1130 r1209  
    1212import mimetypes 
    1313 
     14from trac.config import Option 
    1415from trac.core import * 
    1516from trac.web import IRequestHandler 
    1617from trac.perm import IPermissionRequestor 
    17 from trac.web.chrome import INavigationContributor, ITemplateProvider, add_stylesheet 
     18from trac.web.chrome import INavigationContributor, ITemplateProvider, \ 
     19  add_stylesheet 
    1820from trac.Search import ISearchSource 
    1921from trac.wiki import IWikiSyntaxProvider, wiki_to_html 
    2022from trac.wiki.formatter import system_message 
    21 from trac.util import Markup 
     23from trac.util.html import html 
    2224 
    2325def compare_rank(x, y): 
     
    3234      ITemplateProvider, ISearchSource, IWikiSyntaxProvider) 
    3335 
     36    base_path = Option('doxygen', 'path', '/var/lib/trac/doxygen', 
     37      """Directory containing doxygen generated files.""") 
     38 
     39    default_doc = Option('doxygen', 'default_documentation', '', 
     40      """Default path relative to `base_path` in which to look for 
     41      documentation files.""") 
     42 
     43    title = Option('doxygen', 'title', 'Doxygen', 
     44      """Title to use for the main navigation tab.""") 
     45 
     46    ext = Option('doxygen', 'ext', 'htm html png', 
     47      """Space separated list of extensions for doxygen managed files.""") 
     48 
     49    source_ext = Option('doxygen', 'source_ext', 
     50      'idl odl java cs py php php4 inc phtml m ' 
     51      'cpp cxx c hpp hxx h', 
     52      """Space separated list of source files extensions""") 
     53 
     54    index = Option('doxygen', 'index', 'main.html', 
     55      """Default index page to pick in the generated documentation.""") 
     56 
     57    wiki_index = Option('doxygen', 'wiki_index', None, 
     58      """Wiki page to use as the default page for the Doxygen main page.""") 
     59 
     60    encoding = Option('doxygen', 'encoding', 'iso-8859-1', 
     61      """Default encoding used by the generated documentation files.""") 
     62 
    3463    # IPermissionRequestor methods 
    3564 
     
    4170    def get_active_navigation_item(self, req): 
    4271        return 'doxygen' 
     72 
    4373    def get_navigation_items(self, req): 
    4474        if req.perm.has_permission('DOXYGEN_VIEW'): 
    45             # Get config variables. 
    46             title = self.env.config.get('doxygen', 'title', 'Doxygen') 
    47  
    4875            # Return mainnav buttons. 
    49             yield 'mainnav', 'doxygen', Markup('<a href="%s">%s</a>' % \ 
    50               (self.env.href.doxygen() + '/', title)) 
     76            yield 'mainnav', 'doxygen', html.a(self.title, 
     77              href = req.href.doxygen()) 
    5178 
    5279    # IRequestHandler methods 
    5380 
    5481    def match_request(self, req): 
    55         # Get config variables. 
    56         base_path = self.config.get('doxygen', 'path', '/var/lib/trac/doxygen') 
    57         default_doc = self.config.get('doxygen', 'default_documentation', '') 
    58         ext = self.config.get('doxygen', 'ext', 'htm html png') 
    59         ext = '|'.join(ext.split(' ')) 
    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(' ')) 
     82        ext = '|'.join(self.ext.split(' ')) 
     83        source_ext = '|'.join(self.source_ext.split(' ')) 
    6384 
    6485        # Match documentation request. 
     
    7293            if not match.group(1) and not match.group(2): 
    7394                # Request for documentation index. 
    74                 req.args['path'] = os.path.join(base_path, default_doc) 
     95                req.args['path'] = os.path.join(self.base_path, 
     96                  self.default_doc) 
    7597                req.args['action'] = 'index' 
    7698            else: 
    7799                # Get doc and file from request. 
    78100                if not match.group(2): 
    79                     doc = default_doc 
     101                    doc = self.default_doc 
    80102                    file = match.group(1) 
    81103                else: 
     
    92114                elif re.match(r'''^(.*)[.](%s)''' % (ext,), file): 
    93115                    # Request for documentation file. 
    94                     path = os.path.join(base_path, doc, file) 
     116                    path = os.path.join(self.base_path, doc, file) 
    95117                    self.log.debug('path: %s' % (path,)) 
    96118                    if os.path.exists(path): 
     
    105127                    if match: 
    106128                        # Request for source file documentation. 
    107                         path = os.path.join(base_path, doc, '%s_8%s.html' 
     129                        path = os.path.join(self.base_path, doc, '%s_8%s.html' 
    108130                          % (match.group(1), match.group(2))) 
    109131                        self.log.debug('path: %s' % (path,)) 
     
    116138 
    117139                    else: 
    118                         path = os.path.join(base_path, doc, 'class%s.html' 
     140                        path = os.path.join(self.base_path, doc, 'class%s.html' 
    119141                          % (file,)) 
    120142                        if os.path.exists(path): 
     
    122144                            req.args['action'] = 'file' 
    123145                        else: 
    124                             path = os.path.join(base_path, doc, 
     146                            path = os.path.join(self.base_path, doc, 
    125147                              'struct%s.html' % (file,)) 
    126148                            if os.path.exists(path): 
     
    133155                                    self.log.debug(result) 
    134156                                    if result['name'] == file: 
    135                                         req.redirect(self.env.href.doxygen(doc) 
     157                                        req.redirect(req.href.doxygen(doc) 
    136158                                          + '/' + result['url']) 
    137159                                req.args['action'] = 'search' 
    138160                                req.args['query'] = file 
    139  
    140161            # Request matched. 
    141162            return True 
     
    152173        action = req.args.get('action') 
    153174 
    154         # Get config variables 
    155         index =  self.config.get('doxygen', 'index', 'main.html') 
    156         wiki_index = self.config.get('doxygen', 'wiki_index', None) 
     175        self.log.debug('path: %s' % (path,)) 
     176        self.log.debug('action: %s' % (action,)) 
    157177 
    158178        # Redirect search requests. 
    159179        if action == 'search': 
    160             req.redirect('%s?q=%s&doxygen=on' % (self.env.href.search(), 
    161               req.args.get('query'))) 
     180            req.redirect(req.href.search(q = req.args.get('query'), 
     181              doxygen = 'on')) 
    162182 
    163183        # Retrun apropriate content to type or search request 
    164184        elif action == 'index': 
    165             if wiki_index: 
     185            if self.wiki_index: 
    166186                # Get access to database 
    167187                db = self.env.get_db_cnx() 
    168188                cursor = db.cursor() 
    169189 
    170                 # Get wiki index 
     190                # Get wiki index  # FIXME: use WikiPage() instead 
    171191                sql = "SELECT text FROM wiki WHERE name = %s" 
    172                 cursor.execute(sql, (wiki_index,)) 
    173                 text = Markup(system_message('Error', 'Wiki page %s does not' \ 
    174                   ' exists' % (wiki_index))
     192                cursor.execute(sql, (self.wiki_index,)) 
     193                text = system_message('Error', 'Wiki page %s does not exists' % 
     194                  self.wiki_index
    175195                for row in cursor: 
    176196                    text = wiki_to_html(row[0], self.env, req) 
     
    181201            else: 
    182202                add_stylesheet(req, 'doxygen/css/doxygen.css') 
    183                 req.hdf['doxygen.path'] = path + '/' + index 
     203                req.hdf['doxygen.path'] = path + '/' + self.index 
    184204                return 'doxygen.cs', 'text/html' 
    185205 
     
    208228    def get_search_filters(self, req): 
    209229        if req.perm.has_permission('DOXYGEN_VIEW'): 
    210             # Get config variables 
    211             title = self.env.config.get('doxygen', 'title', 'Doxygen') 
    212  
    213             yield('doxygen', title) 
    214  
    215     def get_search_results(self, req, query, filters): 
     230            yield('doxygen', self.title) 
     231 
     232    def get_search_results(self, req, keywords, filters): 
    216233        if not 'doxygen' in filters: 
    217234            return 
    218         if query[0] == query[-1] == "'" or query[0] == query[-1] == '"': 
    219             keywords = [query[1:-1]] 
    220         else: 
    221             keywords = query.split(' ') 
    222  
    223         base_path = self.config.get('doxygen', 'path') 
    224  
    225         for doc in os.listdir(base_path): 
     235 
     236        # We have to search for the raw bytes... 
     237        keywords = [k.encode(self.encoding) for k in keywords] 
     238 
     239        for doc in os.listdir(self.base_path): 
    226240            # Search in documentation directories 
    227             path = os.path.join(base_path, doc) 
     241            path = os.path.join(self.base_path, doc) 
    228242            if os.path.isdir(path): 
    229243                index = os.path.join(path, 'search.idx') 
     
    231245                    creation = os.path.getctime(index) 
    232246                    for result in  self._search_in_documentation(doc, keywords): 
    233                         result['url'] =  self.env.href.doxygen(doc) + '/' \ 
     247                        result['url'] =  req.href.doxygen(doc) + '/' \ 
    234248                          + result['url'] 
    235249                        yield result['url'], result['name'], creation, \ 
     
    237251 
    238252            # Search in common documentation directory 
    239             index = os.path.join(base_path, 'search.idx') 
     253            index = os.path.join(self.base_path, 'search.idx') 
    240254            if os.path.exists(index): 
    241255                creation = os.path.getctime(index) 
    242256                for result in self._search_in_documentation('', keywords): 
    243                     result['url'] =  self.env.href.doxygen() + '/' + \ 
     257                    result['url'] =  req.href.doxygen() + '/' + \ 
    244258                      result['url'] 
    245259                    yield result['url'], result['name'], creation, 'doxygen', \ 
     
    256270    def _search_in_documentation(self, doc, keywords): 
    257271        # Open index file for documentation 
    258         base_path = self.config.get('doxygen', 'path') 
    259         index = os.path.join(base_path, doc, 'search.idx') 
     272        index = os.path.join(self.base_path, doc, 'search.idx') 
    260273        if os.path.exists(index): 
    261274            fd = open(index) 
     
    284297                    low = word.lower() 
    285298                    if w.find(low) != -1: 
    286                         matches.append({'word' : word, 'match' : w, 'index' : statIdx, 'full' : len(low) == len(w)}) 
     299                        matches.append({'word': word, 'match': w, 
     300                         'index': statIdx, 'full': len(low) == len(w)}) 
    287301                    w = self._readString(fd) 
    288302 
     
    303317                        idx = self._readInt(fd) 
    304318                        freq = self._readInt(fd) 
    305                         results.append({'idx' : idx, 'freq' : freq >> 1, 'hi' : freq & 1, 'multi' : multiplier}) 
     319                        results.append({'idx': idx, 'freq': freq >> 1, 
     320                          'hi': freq & 1, 'multi': multiplier}) 
    306321                        if freq & 1: 
    307322                            totalHi += 1 
     
    323338                    multi = results[i]['multi'] 
    324339                    if results[i]['hi']: 
    325                         results[i]['rank'] = float((freq * multi + totalFreqLo)) / float(totalFreq) 
     340                        results[i]['rank'] = float(freq*multi + totalFreqLo) \ 
     341                          / float(totalFreq) 
    326342                    else: 
    327                         results[i]['rank'] = float((freq * multi)) / float(totalFreq) 
     343                        results[i]['rank'] = float(freq*multi) \ 
     344                          / float(totalFreq) 
    328345 
    329346        return results 
     
    361378    def _doxygen_link(self, formatter, ns, params, label): 
    362379        if ns == 'doxygen': 
    363             return '<a href="%s" title="%s">%s</a>' % \ 
    364               (self.env.href.doxygen(params), params, label
     380            return html.a(label, href = formatter.href.doxygen(params), 
     381              title = params
    365382        else: 
    366             return '<a href="%s" class="missing">%s?</a>' % \ 
    367               (self.env.href.doxygen(), label
     383            return html.a(label, href = formatter.href.doxygen(), 
     384              title = params, class_ = 'missing'
  • doxygenplugin/0.10/setup.py

    r1129 r1209  
    11#!/usr/bin/env python 
     2# -*- coding: utf-8 -*- 
    23 
    34from setuptools import setup, find_packages 
  • doxygenplugin/0.9/setup.py

    r1129 r1209  
    11#!/usr/bin/env python 
     2# -*- coding: utf-8 -*- 
    23 
    34from setuptools import setup, find_packages