97
STORE_LOCATION_NORECURSE = 1
98
STORE_LOCATION_APPENDPATH = 2
104
97
POLICY_NORECURSE = 1
105
98
POLICY_APPENDPATH = 2
100
_policy_key_names = [
101
('policy_norecurse', POLICY_NORECURSE),
102
('policy_appendpath', POLICY_APPENDPATH)]
105
STORE_LOCATION = POLICY_NONE
106
STORE_LOCATION_NORECURSE = POLICY_NORECURSE
107
STORE_LOCATION_APPENDPATH = POLICY_APPENDPATH
108
112
class ConfigObj(configobj.ConfigObj):
492
496
return POLICY_NORECURSE
494
for (name, policy) in [('norecurse', POLICY_NORECURSE),
495
('appendpath', POLICY_APPENDPATH)]:
498
for (name, policy) in _policy_key_names:
497
value = self._get_parser().get_value(section,
500
value = self._get_parser().get_value(section, name)
501
if not isinstance(value, list):
499
503
if option_name in value:
504
508
# fall back to no special policy
505
509
return POLICY_NONE
507
def set_user_option(self, option, value):
511
def _set_option_policy(self, section, option_name, option_policy):
512
"""Set the policy for the given option name in the given section."""
513
# The old recurse=False option affects all options in the
514
# section. To handle multiple policies in the section, we
515
# need to convert it to a policy_norecurse key.
517
recurse = self._get_parser()[section].as_bool('recurse')
521
warning('The recurse option in section %s of %s '
522
'has been converted to a policy_norecurse option'
523
% (section, self._get_filename()))
524
del self._get_parser()[section]['recurse']
526
key for key in self._get_parser()[section].keys()
527
if not key.startswith('policy_'))
529
self._get_parser()[section]['policy_norecurse'] = all_keys
531
for (name, policy) in _policy_key_names:
533
value = self._get_parser().get_value(section, name)
534
if not isinstance(value, list):
538
if policy == option_policy:
539
if option_name not in value:
540
value = sorted(value + [option_name])
541
self._get_parser()[section][name] = value
543
if option_name in value:
544
value.remove(option_name)
545
self._get_parser()[section][name] = value
547
def set_user_option(self, option, value, store=STORE_LOCATION):
508
548
"""Save option and its value in the configuration."""
549
assert store in [STORE_LOCATION,
550
STORE_LOCATION_NORECURSE,
551
STORE_LOCATION_APPENDPATH], 'bad storage policy'
509
552
# FIXME: RBC 20051029 This should refresh the parser and also take a
510
553
# file lock on locations.conf.
511
554
conf_dir = os.path.dirname(self._get_filename())
519
562
elif location + '/' in self._get_parser():
520
563
location = location + '/'
521
564
self._get_parser()[location][option]=value
565
# the allowed values of store match the config policies
566
self._set_option_policy(location, option, store)
522
567
self._get_parser().write(file(self._get_filename(), 'wb'))
602
def set_user_option(self, name, value, local=False):
604
self._get_location_config().set_user_option(name, value)
647
def set_user_option(self, name, value, store=STORE_BRANCH):
648
if store == STORE_BRANCH:
606
649
self._get_branch_data_config().set_option(value, name)
650
elif store == STORE_GLOBAL:
651
self._get_global_config().set_option(name, value)
653
self._get_location_config().set_user_option(name, value, store)
609
655
def _gpg_signing_command(self):
610
656
"""See Config.gpg_signing_command."""