~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-05-26 11:24:26 UTC
  • mfrom: (4708.2.3 filelifetimes)
  • Revision ID: pqm@pqm.ubuntu.com-20100526112426-r041wtw03oqi4hj1
(lifeless) Explicitly close various file objects used in bzrlib (Martin [gz])

Show diffs side-by-side

added added

removed removed

Lines of Context:
477
477
    def _get_nickname(self):
478
478
        return self.get_user_option('nickname')
479
479
 
 
480
    def _write_config_file(self):
 
481
        f = file(self._get_filename(), "wb")
 
482
        try:
 
483
            osutils.copy_ownership_from_path(f.name)
 
484
            self._get_parser().write(f)
 
485
        finally:
 
486
            f.close()
 
487
 
480
488
 
481
489
class GlobalConfig(IniBasedConfig):
482
490
    """The configuration that should be used for a specific location."""
518
526
        self._get_parser().setdefault(section, {})[option] = value
519
527
        self._write_config_file()
520
528
 
521
 
    def _write_config_file(self):
522
 
        path = self._get_filename()
523
 
        f = open(path, 'wb')
524
 
        osutils.copy_ownership_from_path(path)
525
 
        self._get_parser().write(f)
526
 
        f.close()
527
 
 
528
529
 
529
530
class LocationConfig(IniBasedConfig):
530
531
    """A configuration object that gives the policy for a location."""
664
665
        self._get_parser()[location][option]=value
665
666
        # the allowed values of store match the config policies
666
667
        self._set_option_policy(location, option, store)
667
 
        self._get_parser().write(file(self._get_filename(), 'wb'))
 
668
        self._write_config_file()
668
669
 
669
670
 
670
671
class BranchConfig(Config):
991
992
        """Save the config file, only tests should use it for now."""
992
993
        conf_dir = os.path.dirname(self._filename)
993
994
        ensure_config_dir_exists(conf_dir)
994
 
        self._get_config().write(file(self._filename, 'wb'))
 
995
        f = file(self._filename, 'wb')
 
996
        try:
 
997
            self._get_config().write(f)
 
998
        finally:
 
999
            f.close()
995
1000
 
996
1001
    def _set_option(self, section_name, option_name, value):
997
1002
        """Set an authentication configuration option"""
1445
1450
            return StringIO()
1446
1451
 
1447
1452
    def _get_configobj(self):
1448
 
        return ConfigObj(self._get_config_file(), encoding='utf-8')
 
1453
        f = self._get_config_file()
 
1454
        try:
 
1455
            return ConfigObj(f, encoding='utf-8')
 
1456
        finally:
 
1457
            f.close()
1449
1458
 
1450
1459
    def _set_configobj(self, configobj):
1451
1460
        out_file = StringIO()