444
444
def set_user_option(self, option, value):
445
445
"""Save option and its value in the configuration."""
446
self._set_option(option, value, 'DEFAULT')
448
def get_aliases(self):
449
"""Return the aliases section."""
450
if 'ALIASES' in self._get_parser():
451
return self._get_parser()['ALIASES']
455
def set_alias(self, alias_name, alias_command):
456
"""Save the alias in the configuration."""
457
self._set_option(alias_name, alias_command, 'ALIASES')
459
def unset_alias(self, alias_name):
460
"""Unset an existing alias."""
461
aliases = self._get_parser().get('ALIASES')
462
assert aliases and alias_name in aliases, (
463
"The alias should exist before this is called")
464
del aliases[alias_name]
465
self._writeConfigFile()
467
def _set_option(self, option, value, section):
446
468
# FIXME: RBC 20051029 This should refresh the parser and also take a
447
469
# file lock on bazaar.conf.
448
470
conf_dir = os.path.dirname(self._get_filename())
449
471
ensure_config_dir_exists(conf_dir)
450
if 'DEFAULT' not in self._get_parser():
451
self._get_parser()['DEFAULT'] = {}
452
self._get_parser()['DEFAULT'][option] = value
472
if section not in self._get_parser():
473
self._get_parser()[section] = {}
474
self._get_parser()[section][option] = value
475
self._writeConfigFile()
477
def _writeConfigFile(self):
453
478
f = open(self._get_filename(), 'wb')
454
479
self._get_parser().write(f)