~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Aaron Bentley
  • Date: 2006-10-15 16:22:42 UTC
  • mfrom: (2077 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2078.
  • Revision ID: aaron.bentley@utoronto.ca-20061015162242-2de5677dd0495500
Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
262
262
            raise errors.ParseConfigError(e.errors, e.config.filename)
263
263
        return self._parser
264
264
 
 
265
    def _get_matching_sections(self):
 
266
        """Return an ordered list of (section_name, extra_path) pairs.
 
267
 
 
268
        If the section contains inherited configuration, extra_path is
 
269
        a string containing the additional path components.
 
270
        """
 
271
        section = self._get_section()
 
272
        if section is not None:
 
273
            return [(section, '')]
 
274
        else:
 
275
            return []
 
276
 
265
277
    def _get_section(self):
266
278
        """Override this to define the section used by the config."""
267
279
        return "DEFAULT"
284
296
 
285
297
    def _get_user_option(self, option_name):
286
298
        """See Config._get_user_option."""
287
 
        try:
288
 
            return self._get_parser().get_value(self._get_section(),
289
 
                                                option_name)
290
 
        except KeyError:
291
 
            pass
 
299
        for (section, extra_path) in self._get_matching_sections():
 
300
            try:
 
301
                return self._get_parser().get_value(section, option_name)
 
302
            except KeyError:
 
303
                pass
 
304
        else:
 
305
            return None
292
306
 
293
307
    def _gpg_signing_command(self):
294
308
        """See Config.gpg_signing_command."""
386
400
            location = urlutils.local_path_from_url(location)
387
401
        self.location = location
388
402
 
389
 
    def _get_section(self):
390
 
        """Get the section we should look in for config items.
391
 
 
392
 
        Returns None if none exists. 
393
 
        TODO: perhaps return a NullSection that thunks through to the 
394
 
              global config.
395
 
        """
 
403
    def _get_matching_sections(self):
 
404
        """Return an ordered list of section names matching this location."""
396
405
        sections = self._get_parser()
397
406
        location_names = self.location.split('/')
398
407
        if self.location.endswith('/'):
429
438
                        continue
430
439
                except KeyError:
431
440
                    pass
432
 
            matches.append((len(section_names), section))
433
 
        if not len(matches):
434
 
            return None
 
441
            matches.append((len(section_names), section,
 
442
                            '/'.join(location_names[len(section_names):])))
435
443
        matches.sort(reverse=True)
436
 
        return matches[0][1]
 
444
        sections = []
 
445
        for (length, section, extra_path) in matches:
 
446
            sections.append((section, extra_path))
 
447
            # should we stop looking for parent configs here?
 
448
            try:
 
449
                if self._get_parser()[section].as_bool('ignore_parents'):
 
450
                    break
 
451
            except KeyError:
 
452
                pass
 
453
        return sections
437
454
 
438
455
    def set_user_option(self, option, value):
439
456
        """Save option and its value in the configuration."""