~abentley/bzr/appenddir

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Aaron Bentley
  • Date: 2011-02-16 22:02:38 UTC
  • Revision ID: aaron@aaronbentley.com-20110216220238-ptrm40clbin86v0c
Support appenddir configuration policy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
109
109
POLICY_NONE = 0
110
110
POLICY_NORECURSE = 1
111
111
POLICY_APPENDPATH = 2
 
112
POLICY_APPENDDIR = 5
112
113
 
113
114
_policy_name = {
114
115
    POLICY_NONE: None,
115
116
    POLICY_NORECURSE: 'norecurse',
116
117
    POLICY_APPENDPATH: 'appendpath',
117
 
    }
118
 
_policy_value = {
119
 
    None: POLICY_NONE,
120
 
    'none': POLICY_NONE,
121
 
    'norecurse': POLICY_NORECURSE,
122
 
    'appendpath': POLICY_APPENDPATH,
123
 
    }
124
 
 
 
118
    POLICY_APPENDDIR: 'appenddir',
 
119
    }
 
120
_policy_value = dict((v, k) for k, v in _policy_name.iteritems())
 
121
_policy_value['none'] = POLICY_NONE
125
122
 
126
123
STORE_LOCATION = POLICY_NONE
127
124
STORE_LOCATION_NORECURSE = POLICY_NORECURSE
128
125
STORE_LOCATION_APPENDPATH = POLICY_APPENDPATH
129
126
STORE_BRANCH = 3
130
127
STORE_GLOBAL = 4
 
128
STORE_LOCATION_APPENDDIR = POLICY_APPENDDIR
131
129
 
132
130
_ConfigObj = None
133
131
def ConfigObj(*args, **kwargs):
561
559
                if extra_path:
562
560
                    value = urlutils.join(value, extra_path)
563
561
                return value
 
562
            elif policy == POLICY_APPENDDIR:
 
563
                if extra_path:
 
564
                    value = urlutils.join(value, urlutils.basename(extra_path))
 
565
                return value
564
566
            else:
565
567
                raise AssertionError('Unexpected config policy %r' % policy)
566
568
        else:
929
931
    @needs_write_lock
930
932
    def set_user_option(self, option, value, store=STORE_LOCATION):
931
933
        """Save option and its value in the configuration."""
932
 
        if store not in [STORE_LOCATION,
933
 
                         STORE_LOCATION_NORECURSE,
934
 
                         STORE_LOCATION_APPENDPATH]:
 
934
        if store not in _policy_name:
935
935
            raise ValueError('bad storage policy %r for %r' %
936
936
                (store, option))
937
937
        self.reload()