/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/config.py

add support for norecurse and appendpath policies when reading configuration files

Show diffs side-by-side

added added

removed removed

Lines of Context:
93
93
SIGN_NEVER=2
94
94
 
95
95
 
 
96
STORE_LOCATION = 0
 
97
STORE_LOCATION_NORECURSE = 1
 
98
STORE_LOCATION_APPENDPATH = 2
 
99
STORE_BRANCH = 3
 
100
STORE_GLOBAL = 4
 
101
 
 
102
 
 
103
POLICY_NONE = 0
 
104
POLICY_NORECURSE = 1
 
105
POLICY_APPENDPATH = 2
 
106
 
 
107
 
96
108
class ConfigObj(configobj.ConfigObj):
97
109
 
98
110
    def get_bool(self, section, key):
278
290
        """Override this to define the section used by the config."""
279
291
        return "DEFAULT"
280
292
 
 
293
    def _get_option_policy(self, section, option_name):
 
294
        """Return the policy for the given (section, option_name) pair."""
 
295
        return POLICY_NONE
 
296
 
281
297
    def _get_signature_checking(self):
282
298
        """See Config._get_signature_checking."""
283
299
        policy = self._get_user_option('check_signatures')
298
314
        """See Config._get_user_option."""
299
315
        for (section, extra_path) in self._get_matching_sections():
300
316
            try:
301
 
                return self._get_parser().get_value(section, option_name)
 
317
                value = self._get_parser().get_value(section, option_name)
302
318
            except KeyError:
303
 
                pass
 
319
                continue
 
320
            policy = self._get_option_policy(section, option_name)
 
321
            if policy == POLICY_NONE:
 
322
                return value
 
323
            elif policy == POLICY_NORECURSE:
 
324
                # norecurse items only apply to the exact path
 
325
                if extra_path:
 
326
                    continue
 
327
                else:
 
328
                    return value
 
329
            elif policy == POLICY_APPENDPATH:
 
330
                return urlutils.join(value, extra_path)
304
331
        else:
305
332
            return None
306
333
 
431
458
            # if section is longer, no match.
432
459
            if len(section_names) > len(location_names):
433
460
                continue
434
 
            # if path is longer, and recurse is not true, no match
435
 
            if len(section_names) < len(location_names):
436
 
                try:
437
 
                    if not self._get_parser()[section].as_bool('recurse'):
438
 
                        continue
439
 
                except KeyError:
440
 
                    pass
 
461
##             # if path is longer, and recurse is not true, no match
 
462
##             if len(section_names) < len(location_names):
 
463
##                 try:
 
464
##                     if not self._get_parser()[section].as_bool('recurse'):
 
465
##                         continue
 
466
##                 except KeyError:
 
467
##                     pass
441
468
            matches.append((len(section_names), section,
442
469
                            '/'.join(location_names[len(section_names):])))
443
470
        matches.sort(reverse=True)
452
479
                pass
453
480
        return sections
454
481
 
 
482
    def _get_option_policy(self, section, option_name):
 
483
        """Return the policy for the given (section, option_name) pair."""
 
484
        # check for the old 'recurse=False' flag
 
485
        try:
 
486
            recurse = self._get_parser()[section].as_bool('recurse')
 
487
        except KeyError:
 
488
            recurse = True
 
489
        if not recurse:
 
490
            return POLICY_NORECURSE
 
491
 
 
492
        for (name, policy) in [('norecurse', POLICY_NORECURSE),
 
493
                               ('appendpath', POLICY_APPENDPATH)]:
 
494
            try:
 
495
                value = self._get_parser().get_value(section,
 
496
                                                     'policy_%s' % name)
 
497
                if option_name in value:
 
498
                    return policy
 
499
            except KeyError:
 
500
                pass
 
501
 
 
502
        # fall back to no special policy
 
503
        return POLICY_NONE
 
504
 
455
505
    def set_user_option(self, option, value):
456
506
        """Save option and its value in the configuration."""
457
507
        # FIXME: RBC 20051029 This should refresh the parser and also take a