Changeset 4012

Show
Ignore:
Timestamp:
07/14/08 08:14:56 (3 months ago)
Author:
eblot
Message:

Closes #2674.

  • Fix up the invalid syntax in url_parts
  • Use the new Trac API for options (so that TracIni now shows up the proper option)

Thanks to anonymous for the original patch.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • revtreeplugin/0.11/revtree/web_ui.py

    r3491 r4012  
    2121from revtree.api import EmptyRangeError, RevtreeSystem 
    2222from revtree.model import Repository 
     23from trac.config import Option, IntOption, BoolOption, ListOption, \ 
     24                        Section, ConfigurationError 
    2325from trac.core import * 
    2426from trac.perm import IPermissionRequestor 
     
    120122 
    121123 
     124class FloatOption(Option): 
     125    """Descriptor for float configuration options. 
     126       Option for real number is missing in Trac 
     127    """ 
     128     
     129    def accessor(self, section, name, default=''): 
     130        """Return the value of the specified option as float. 
     131         
     132        If the specified option can not be converted to a float, a 
     133        `ConfigurationError` exception is raised. 
     134         
     135        Valid default input is a string or a float. Returns an float. 
     136        """ 
     137        value = section.get(name, default) 
     138        if not value: 
     139            return 0.0 
     140        try: 
     141            return float(value) 
     142        except ValueError: 
     143            raise ConfigurationError('expected real number, got %s' % \ 
     144                                     repr(value)) 
     145 
     146class ChoiceOption(Option): 
     147    """Descriptor for choice configuration options.""" 
     148 
     149    def __init__(self, section, name, default=None, choices='', doc=''): 
     150        Option.__init__(self, section, name, default, doc) 
     151        self.choices = filter(None, [c.strip() for c in choices.split(',')]) 
     152 
     153    def accessor(self, section, name, default): 
     154        value = section.get(name, default) 
     155        if value not in self.choices: 
     156            raise ConfigurationError('expected a choice among "%s", got %s' % \ 
     157                                     (', '.join(self.choices), repr(value))) 
     158        return value 
     159 
     160     
    122161class RevtreeModule(Component): 
    123162    """Implements the revision tree feature""" 
     
    125164    implements(IPermissionRequestor, INavigationContributor, \ 
    126165               IRequestFilter, IRequestHandler, ITemplateProvider) 
    127                     
     166              
     167    # Timeline ranges 
    128168    PERIODS = { 1: 'day', 2: '2 days', 3: '3 days', 5: '5 days', 7:'week', 
    129169                14: 'fortnight', 31: 'month', 61: '2 months',  
    130170                91: 'quarter', 183: 'semester', 366: 'year', 0: 'all' } 
    131      
     171   
     172    # Configuration Options 
     173    branchre = Option('revtree', 'branch_re', 
     174        r'^(?P<branch>trunk|(?:branches|tags)/[^/]+)(?:/(?P<path>.*))?$', 
     175        doc = """Regular expression to extract branches from paths""") 
     176     
     177    abstime = BoolOption('revtree', 'abstime', 'true', 
     178        doc = """Timeline filters start on absolute time or on the youngest 
     179                 revision.""") 
     180 
     181    contexts = ListOption('revtree', 'contexts', 
     182        doc = """Navigation contexts where the Revtree item appears. 
     183                 If empty, the Revtree item appears in the main navigation 
     184                 bar.""") 
     185                  
     186    trunks = ListOption('revtree', 'trunks', 
     187        doc = """Branches that are considered as trunks""") 
     188     
     189    oldest = IntOption('revtree', 'revbase', '1', 
     190        doc = """Oldest revision to consider (older revisions are ignored)""") 
     191     
     192    style = ChoiceOption('revtree', 'style', 'compact', 'compact,timeline', 
     193        doc = """Revtree style, 'compact' or 'timeline'""") 
     194         
     195    scale = FloatOption('revtree', 'scale', '1', 
     196        doc = """Default rendering scale for the SVG graph""") 
     197         
    132198    # IPermissionRequestor methods 
    133199 
     
    155221    def post_process_request(self, req, template, data, content_type): 
    156222        if req.perm.has_permission('REVTREE_VIEW'): 
    157             url_parts = req.path_info.split(u'/') 
    158             if (url_parts > 1) and (url_parts[1] in self.contexts): 
    159                 add_ctxtnav(req, 'Revtree', href=req.href.revtree()) 
     223            url_parts = filter(None, req.path_info.split(u'/')) 
     224            if url_parts and (url_parts[0] in self.contexts): 
     225                add_ctxtnav(req, 'Revtree' % self.contexts,  
     226                            href=req.href.revtree()) 
    160227        return (template, data, content_type) 
    161228 
     
    188255    def get_templates_dirs(self): 
    189256        """Return the absolute path of the directory containing the provided 
    190         ClearSilver templates. 
     257        Genshi templates. 
    191258        """ 
    192259        from pkg_resources import resource_filename 
     
    197264    def __init__(self): 
    198265        """Reads the configuration and run sanity checks""" 
    199         bre = self.config.get('revtree', 'branch_re', 
    200                   r'^(?P<branch>trunk|(?:branches|tags)/[^/]+)' 
    201                   r'(?:/(?P<path>.*))?$') 
    202         self.bcre = re.compile(bre) 
    203         self.trunks = self.env.config.get('revtree', 'trunks',  
    204                                           'trunk').split(' ') 
    205         self.scale = float(self.env.config.get('revtree', 'scale', '1')) 
    206         self.oldest = int(self.env.config.get('revtree', 'revbase', '1')) 
    207         self.abstime = self.config.getbool('revtree', 'abstime', True) 
    208         self.style = self.config.get('revtree', 'style', 'compact') 
    209         if self.style not in [ 'compact', 'timeline']: 
    210             self.env.log.warning("Unsupported style: %s" % self.style) 
    211             self.style = 'compact' 
    212         contexts = self.config.get('revtree', 'contexts', None) 
    213         self.contexts = contexts and [c.strip() for c in contexts.split(u',')] 
     266        self.bcre = re.compile(self.branchre) 
    214267        self.rt = RevtreeSystem(self.env) 
    215268 
  • revtreeplugin/0.11/setup.py

    r3491 r4012  
    1616 
    1717PACKAGE = 'TracRevtreePlugin' 
    18 VERSION = '0.5.15
     18VERSION = '0.5.16
    1919 
    2020setup (