441
441
def set_user_option(self, option, value):
442
442
"""Save option and its value in the configuration."""
443
self._set_option(option, value, 'DEFAULT')
445
def get_aliases(self):
446
"""Return the aliases section."""
447
if 'ALIASES' in self._get_parser():
448
return self._get_parser()['ALIASES']
452
def set_alias(self, alias_name, alias_command):
453
"""Save the alias in the configuration."""
454
self._set_option(alias_name, alias_command, 'ALIASES')
456
def unset_alias(self, alias_name):
457
"""Unset an existing alias."""
458
aliases = self._get_parser().get('ALIASES')
459
if not aliases or alias_name not in aliases:
460
raise errors.NoSuchAlias(alias_name)
461
del aliases[alias_name]
462
self._write_config_file()
464
def _set_option(self, option, value, section):
443
465
# FIXME: RBC 20051029 This should refresh the parser and also take a
444
466
# file lock on bazaar.conf.
445
467
conf_dir = os.path.dirname(self._get_filename())
446
468
ensure_config_dir_exists(conf_dir)
447
if 'DEFAULT' not in self._get_parser():
448
self._get_parser()['DEFAULT'] = {}
449
self._get_parser()['DEFAULT'][option] = value
469
self._get_parser().setdefault(section, {})[option] = value
470
self._write_config_file()
472
def _write_config_file(self):
450
473
f = open(self._get_filename(), 'wb')
451
474
self._get_parser().write(f)