Changeset 871

Show
Ignore:
Timestamp:
06/15/06 10:45:10 (2 years ago)
Author:
Blackhex
Message:

DoxygenPlugin:

  • Configurable file extention handling.
  • DOXYGEN_VIEW permission checking.
  • Configurable Mainnav button text.
  • Doxygen search redirection.
  • Hope functional putting under /doxygen/ prefix.
Files:

Legend:

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

    r361 r871  
    1010import posixpath 
    1111import re 
     12import mimetypes 
    1213 
    1314from trac.core import * 
    1415from trac.web import IRequestHandler 
    15 from trac.web.chrome import INavigationContributor, ITemplateProvider 
     16from trac.perm import IPermissionRequestor 
     17from trac.web.chrome import INavigationContributor, ITemplateProvider, add_stylesheet 
    1618from trac.Search import ISearchSource 
    1719from trac.util import Markup 
     
    2224    elif x['rank'] > y['rank']: 
    2325        return -1 
    24      
    2526    return 1 
    2627 
    2728class DoxygenPlugin(Component): 
    28     implements(INavigationContributor, IRequestHandler, ITemplateProvider, ISearchSource) 
     29    implements(IPermissionRequestor, INavigationContributor, IRequestHandler, 
     30      ITemplateProvider, ISearchSource) 
     31 
     32    # IPermissionRequestor methods 
     33 
     34    def get_permission_actions(self): 
     35        return ['DOXYGEN_VIEW'] 
    2936 
    3037    # INavigationContributor methods 
     
    3340        return 'doxygen' 
    3441    def get_navigation_items(self, req): 
    35         yield ('mainnav', 'doxygen', Markup('<a href="%s">Doxygen</a>', self.env.href.doxygen())) 
     42        if req.perm.has_permission('DOXYGEN_VIEW'): 
     43            # Get config variables 
     44            title = self.env.config.get('doxygen', 'title', 'Doxygen') 
     45            index = self.env.config.get('doxygen', 'index', 'main.html') 
     46 
     47            # Return mainnav buttons 
     48            yield 'mainnav', 'doxygen', Markup('<a href="%s">%s</a>' % \ 
     49              (self.env.href.doxygen(index), title)) 
    3650 
    3751    # IRequestHandler methods 
    3852 
    3953    def match_request(self, req): 
    40         if req.path_info == '/doxygen': 
    41             req.args['path'] = ''.join([self.config.get('doxygen', 'path'), '/main.html']) 
     54        # Get config variables 
     55        base_path = self.config.get('doxygen', 'path', '/var/lib/trac/doxygen') 
     56        ext = self.config.get('doxygen', 'ext', 'htm html png') 
     57        ext = '|'.join(ext.split(' ')) 
     58 
     59        # Match searching request 
     60        if re.match('^/doxygen/search.php$', req.path_info): 
    4261            return True 
    43         elif re.match(r'''^/.*[.]html$''', req.path_info): 
    44             self.log.debug("path = %s" % (req.path_info)) 
    45             path = ''.join([self.config.get('doxygen', 'path'), req.path_info]) 
     62 
     63        # Match request if requested file exists 
     64        elif re.match(r'''^/doxygen/.*[.](%s)$''' % (ext), req.path_info): 
     65            file = re.sub('^/doxygen', '', req.path_info) 
     66            path = base_path + file 
    4667            req.args['path'] = path 
     68            req.args['type'] = mimetypes.guess_type(path)[0] 
    4769            return os.path.exists(path) 
    48          
    49         return False 
     70        else: 
     71            return False 
    5072 
    5173    def process_request(self, req): 
    52         req.hdf['doxygen.path'] = req.args['path'] 
    53         return 'doxygen.cs', 'text/html' 
     74        # Get request arguments 
     75        path = req.args.get('path') 
     76        type = req.args.get('type') 
     77 
     78        # Retrun apropriate content to type or search request 
     79        if req.args.has_key('query'): 
     80            req.redirect('%s?q=%s&doxygen=on' % (self.env.href.search(), 
     81              req.args.get('query'))) 
     82            return None, None 
     83        elif type == 'text/html': 
     84            #add_stylesheet(req, 'doxygen/css/doxygen.css') 
     85            req.hdf['doxygen.path'] = path 
     86            return 'doxygen.cs', type 
     87        else: 
     88            req.send_file(path, type) 
     89            return None, None 
    5490 
    5591    # ITemplateProvider methods 
     92 
     93    def get_htdocs_dirs(self): 
     94        from pkg_resources import resource_filename 
     95        return [('doxygen', resource_filename(__name__, 'htdocs'))] 
    5696 
    5797    def get_templates_dirs(self): 
     
    60100 
    61101    # ISearchProvider methods 
    62      
     102 
    63103    def get_search_filters(self, req): 
    64         yield('doxygen', 'Doxygen') 
     104        if req.perm.has_permission('DOXYGEN_VIEW'): 
     105            # Get config variables 
     106            title = self.env.config.get('doxygen', 'title', 'Doxygen') 
     107 
     108            yield('doxygen', title) 
    65109 
    66110    def get_search_results(self, req, query, filters): 
     
    71115        else: 
    72116            keywords = query.split(' ') 
    73    
     117 
    74118        path = self.config.get('doxygen', 'path') 
    75         path = ''.join([path, '/search.idx']
    76  
    77         if os.path.exists(path):  
     119        path = os.path.join(path, 'search.idx'
     120 
     121        if os.path.exists(path): 
    78122            fd = open(path) 
    79              
     123 
    80124            results = [] 
    81125            for keyword in keywords: 
    82126                results += self._search(fd, keyword) 
    83              
    84             results.sort(compare_rank)             
    85              
    86             # use the creation time for the search.idx file for all results       
     127 
     128            results.sort(compare_rank) 
     129 
     130            # use the creation time for the search.idx file for all results 
    87131            creation = os.path.getctime(path) 
    88132 
    89133            for result in results: 
    90                 yield result['url'], result['name'], creation, 'doxygen', None 
    91      
     134                yield 'doxygen/' + result['url'], result['name'], creation, 'doxygen', None 
     135 
    92136    # internal methods 
    93          
     137 
    94138    def _search(self, fd, word): 
    95139        results = [] 
     
    98142            fd.seek(index * 4 + 4, 0) 
    99143            index = self._readInt(fd) 
    100              
     144 
    101145            if index: 
    102146                fd.seek(index) 
     
    109153                        matches.append({'word' : word, 'match' : w, 'index' : statIdx, 'full' : len(low) == len(w)}) 
    110154                    w = self._readString(fd) 
    111                  
     155 
    112156                count = 0 
    113157                totalHi = 0 
     
    122166                    fd.seek(match['index']) 
    123167                    numDocs = self._readInt(fd) 
    124                     
     168 
    125169                    for i in range(numDocs): 
    126170                        idx = self._readInt(fd) 
     
    132176                        else: 
    133177                            totalFreqLo += freq * multiplier 
    134                      
     178 
    135179                    for i in range(numDocs): 
    136180                        fd.seek(results[count]['idx']) 
     
    140184                        results[count]['url'] = url 
    141185                        count += 1 
    142                  
     186 
    143187                totalFreq = (totalHi + 1) * totalFreqLo + totalFreqHi 
    144188                for i in range(count): 
     
    149193                    else: 
    150194                        results[i]['rank'] = float((freq * multi)) / float(totalFreq) 
    151                          
     195 
    152196        return results 
    153197 
     
    155199        if len(word) < 2: 
    156200            return -1 
    157          
     201 
    158202        hi = ord(word[0].lower()) 
    159203        if hi == 0: 
    160204            return -1 
    161              
     205 
    162206        lo = ord(word[1].lower()) 
    163207        if lo == 0: 
    164208            return -1 
    165         
     209 
    166210        return hi * 256 + lo 
    167          
     211 
    168212    def _readInt(self, fd): 
    169213        b1 = fd.read(1) 
     
    171215        b3 = fd.read(1) 
    172216        b4 = fd.read(1) 
    173          
     217 
    174218        return (ord(b1) << 24) | (ord(b2) << 16) | (ord(b3) << 8) | ord(b4) 
    175      
    176      
     219 
    177220    def _readString(self, fd): 
    178221        byte = fd.read(1) 
    179222        if byte == '\0': 
    180             return "" 
     223            return '' 
    181224        result = byte 
    182225        while byte != '\0': 
    183226            byte = fd.read(1) 
    184227            result = ''.join([result, byte]) 
    185      
     228 
    186229        return result 
    187  
  • doxygenplugin/0.9/setup.py

    r231 r871  
    77    description='Doxygen plugin for Trac', 
    88    keywords='trac doxygen', 
    9     version='0.1', 
     9    version='0.2', 
    1010    url='http://trac-hacks.swapoff.org/wiki/DoxygenPlugin', 
    1111    license = """Copyright (C) 2005 Jason Parks <jparks@jparks.net> 
     
    3737OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 
    3838IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.""", 
    39     author='Jason Parks', 
     39    author='Jason Parks, Radek Bartoň', 
    4040    author_email='jparks@jparks.net', 
    4141    long_description=""" 
     
    4343    zip_safe=True, 
    4444    packages=['doxygentrac'], 
    45     package_data={'doxygentrac': ['templates/*.cs']}, 
     45    package_data={'doxygentrac': ['templates/*.cs', 'htdocs/css/*.css']}, 
    4646    entry_points={'trac.plugins': 'doxygentrac = doxygentrac.doxygentrac'})