~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Tim Penhey
  • Date: 2008-01-20 05:06:12 UTC
  • mto: (3473.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3474.
  • Revision ID: tim@penhey.net-20080120050612-vl9z8pmpo79xydht
A working alias command.

Show diffs side-by-side

added added

removed removed

Lines of Context:
443
443
 
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')
 
447
 
 
448
    def get_aliases(self):
 
449
        """Return the aliases section."""
 
450
        if 'ALIASES' in self._get_parser():
 
451
            return self._get_parser()['ALIASES']
 
452
        else:
 
453
            return {}
 
454
 
 
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')
 
458
 
 
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()
 
466
 
 
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()
 
476
 
 
477
    def _writeConfigFile(self):
453
478
        f = open(self._get_filename(), 'wb')
454
479
        self._get_parser().write(f)
455
480
        f.close()