~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Aaron Bentley
  • Date: 2008-06-06 16:40:46 UTC
  • mfrom: (3482 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3483.
  • Revision ID: aaron@aaronbentley.com-20080606164046-ghbxplxuhtpcb9iz
Merge with bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
440
440
 
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')
 
444
 
 
445
    def get_aliases(self):
 
446
        """Return the aliases section."""
 
447
        if 'ALIASES' in self._get_parser():
 
448
            return self._get_parser()['ALIASES']
 
449
        else:
 
450
            return {}
 
451
 
 
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')
 
455
 
 
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()
 
463
 
 
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()
 
471
 
 
472
    def _write_config_file(self):
450
473
        f = open(self._get_filename(), 'wb')
451
474
        self._get_parser().write(f)
452
475
        f.close()