| | 124 | class 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 | |
|---|
| | 146 | class 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 | |
|---|
| 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 | |
|---|
| 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) |
|---|