Rev 5802: Merge config-hooks into selftest-config-stats in file:///home/vila/src/bzr/experimental/config/

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Jun 14 10:07:34 UTC 2011


At file:///home/vila/src/bzr/experimental/config/

------------------------------------------------------------
revno: 5802 [merge]
revision-id: v.ladeuil+lp at free.fr-20110614100733-0h2likecd203aqdv
parent: v.ladeuil+lp at free.fr-20110614091014-dnogx7ukn00j3lcl
parent: v.ladeuil+lp at free.fr-20110614100716-3g1r718dzbedopkr
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: selftest-config-stats
timestamp: Tue 2011-06-14 12:07:33 +0200
message:
  Merge config-hooks into selftest-config-stats
modified:
  bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
  bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
  doc/en/release-notes/bzr-2.4.txt bzr2.4.txt-20110114053217-k7ym9jfz243fddjm-1
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-06-13 15:38:54 +0000
+++ b/bzrlib/config.py	2011-06-14 10:07:16 +0000
@@ -371,7 +371,7 @@
                               % (option_name,))
             else:
                 value = self._expand_options_in_string(value)
-        for hook in ConfigHooks['old_get']:
+        for hook in OldConfigHooks['get']:
             hook(self, option_name, value)        
         return value
 
@@ -589,29 +589,42 @@
                       'Invoked when a config option is removed.'
                       ' The signature is (stack, name).',
                       (2, 4))
-        # Hooks for the actual implementation
-        self.add_hook('old_load',
+ConfigHooks = _ConfigHooks()
+
+
+class _OldConfigHooks(hooks.Hooks):
+    """A dict mapping hook names and a list of callables for configs.
+    """
+
+    def __init__(self):
+        """Create the default hooks.
+
+        These are all empty initially, because by default nothing should get
+        notified.
+        """
+        super(_OldConfigHooks, self).__init__('bzrlib.config', 'OldConfigHooks')
+        self.add_hook('load',
                       'Invoked when a config store is loaded.'
                       ' The signature is (config).',
                       (2, 4))
-        self.add_hook('old_save',
+        self.add_hook('save',
                       'Invoked when a config store is saved.'
                       ' The signature is (config).',
                       (2, 4))
         # The hooks for config options
-        self.add_hook('old_get',
+        self.add_hook('get',
                       'Invoked when a config option is read.'
                       ' The signature is (config, name, value).',
                       (2, 4))
-        self.add_hook('old_set',
+        self.add_hook('set',
                       'Invoked when a config option is set.'
                       ' The signature is (config, name, value).',
                       (2, 4))
-        self.add_hook('old_remove',
+        self.add_hook('remove',
                       'Invoked when a config option is removed.'
                       ' The signature is (config, name).',
                       (2, 4))
-ConfigHooks = _ConfigHooks()
+OldConfigHooks = _OldConfigHooks()
 
 
 class IniBasedConfig(Config):
@@ -681,7 +694,7 @@
             raise errors.ParseConfigError(e.errors, e.config.filename)
         # Make sure self.reload() will use the right file name
         self._parser.filename = self.file_name
-        for hook in ConfigHooks['old_load']:
+        for hook in OldConfigHooks['load']:
             hook(self)
         return self._parser
 
@@ -691,7 +704,7 @@
             raise AssertionError('We need a file name to reload the config')
         if self._parser is not None:
             self._parser.reload()
-        for hook in ConfigHooks['old_load']:
+        for hook in ConfigHooks['load']:
             hook(self)
 
     def _get_matching_sections(self):
@@ -870,7 +883,7 @@
         except KeyError:
             raise errors.NoSuchConfigOption(option_name)
         self._write_config_file()
-        for hook in ConfigHooks['old_remove']:
+        for hook in OldConfigHooks['remove']:
             hook(self, option_name)
 
     def _write_config_file(self):
@@ -883,7 +896,7 @@
         atomic_file.commit()
         atomic_file.close()
         osutils.copy_ownership_from_path(self.file_name)
-        for hook in ConfigHooks['old_save']:
+        for hook in OldConfigHooks['save']:
             hook(self)
 
 
@@ -1018,7 +1031,7 @@
         self.reload()
         self._get_parser().setdefault(section, {})[option] = value
         self._write_config_file()
-        for hook in ConfigHooks['old_set']:
+        for hook in OldConfigHooks['set']:
             hook(self, option, value)
 
     def _get_sections(self, name=None):
@@ -1221,7 +1234,7 @@
         # the allowed values of store match the config policies
         self._set_option_policy(location, option, store)
         self._write_config_file()
-        for hook in ConfigHooks['old_set']:
+        for hook in OldConfigHooks['set']:
             hook(self, option, value)
 
 
@@ -2126,7 +2139,7 @@
             except KeyError:
                 return default
         value = section_obj.get(name, default)
-        for hook in ConfigHooks['old_get']:
+        for hook in OldConfigHooks['get']:
             hook(self, name, value)        
         return value
 
@@ -2142,7 +2155,7 @@
             configobj[name] = value
         else:
             configobj.setdefault(section, {})[name] = value
-        for hook in ConfigHooks['old_set']:
+        for hook in OldConfigHooks['set']:
             hook(self, name, value)
         self._set_configobj(configobj)
 
@@ -2152,14 +2165,14 @@
             del configobj[option_name]
         else:
             del configobj[section_name][option_name]
-        for hook in ConfigHooks['old_remove']:
+        for hook in OldConfigHooks['remove']:
             hook(self, option_name)
         self._set_configobj(configobj)
 
     def _get_config_file(self):
         try:
             f = StringIO(self._transport.get_bytes(self._filename))
-            for hook in ConfigHooks['old_load']:
+            for hook in OldConfigHooks['load']:
                 hook(self)
             return f
         except errors.NoSuchFile:
@@ -2177,7 +2190,7 @@
         configobj.write(out_file)
         out_file.seek(0)
         self._transport.put_file(self._filename, out_file)
-        for hook in ConfigHooks['old_save']:
+        for hook in OldConfigHooks['save']:
             hook(self)
 
 

=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2011-06-14 08:59:12 +0000
+++ b/bzrlib/remote.py	2011-06-14 10:07:16 +0000
@@ -3115,7 +3115,7 @@
                 value = section_obj.get(name, default)
         except errors.UnknownSmartMethod:
             value = self._vfs_get_option(name, section, default)
-        for hook in config.ConfigHooks['old_get']:
+        for hook in config.OldConfigHooks['get']:
             hook(self, name, value)
         return value
 
@@ -3124,7 +3124,7 @@
             raise errors.UnexpectedSmartServerResponse(response)
         lines = response[1].read_body_bytes().splitlines()
         conf = config.ConfigObj(lines, encoding='utf-8')
-        for hook in config.ConfigHooks['old_load']:
+        for hook in config.OldConfigHooks['load']:
             hook(self)
         return conf
 

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-06-14 09:03:36 +0000
+++ b/bzrlib/tests/test_config.py	2011-06-14 10:07:16 +0000
@@ -1919,7 +1919,9 @@
         calls = []
         def hook(*args):
             calls.append(args)
-        config.ConfigHooks.install_named_hook('old_get', hook, None)
+        config.OldConfigHooks.install_named_hook('get', hook, None)
+        self.addCleanup(
+            config.OldConfigHooks.uninstall_named_hook, 'get', None)
         self.assertLength(0, calls)
         actual_value = conf.get_user_option(name)
         self.assertEquals(value, actual_value)
@@ -1941,7 +1943,9 @@
         calls = []
         def hook(*args):
             calls.append(args)
-        config.ConfigHooks.install_named_hook('old_set', hook, None)
+        config.OldConfigHooks.install_named_hook('set', hook, None)
+        self.addCleanup(
+            config.OldConfigHooks.uninstall_named_hook, 'set', None)
         self.assertLength(0, calls)
         conf.set_user_option(name, value)
         self.assertLength(1, calls)
@@ -1963,7 +1967,9 @@
         calls = []
         def hook(*args):
             calls.append(args)
-        config.ConfigHooks.install_named_hook('old_remove', hook, None)
+        config.OldConfigHooks.install_named_hook('remove', hook, None)
+        self.addCleanup(
+            config.OldConfigHooks.uninstall_named_hook, 'remove', None)
         self.assertLength(0, calls)
         conf.remove_user_option(name, section_name)
         self.assertLength(1, calls)
@@ -1986,7 +1992,9 @@
         calls = []
         def hook(*args):
             calls.append(args)
-        config.ConfigHooks.install_named_hook('old_load', hook, None)
+        config.OldConfigHooks.install_named_hook('load', hook, None)
+        self.addCleanup(
+            config.OldConfigHooks.uninstall_named_hook, 'load', None)
         self.assertLength(0, calls)
         # Build a config
         conf = conf_class(*conf_args)
@@ -2008,7 +2016,9 @@
         calls = []
         def hook(*args):
             calls.append(args)
-        config.ConfigHooks.install_named_hook('old_save', hook, None)
+        config.OldConfigHooks.install_named_hook('save', hook, None)
+        self.addCleanup(
+            config.OldConfigHooks.uninstall_named_hook, 'save', None)
         self.assertLength(0, calls)
         # Setting an option triggers a save
         conf.set_user_option('foo', 'bar')
@@ -2040,9 +2050,9 @@
         calls = []
         def hook(*args):
             calls.append(args)
-        config.ConfigHooks.install_named_hook('old_get', hook, None)
+        config.OldConfigHooks.install_named_hook('get', hook, None)
         self.addCleanup(
-            config.ConfigHooks.uninstall_named_hook, 'old_get', None)
+            config.OldConfigHooks.uninstall_named_hook, 'get', None)
         self.assertLength(0, calls)
         actual_value = conf.get_option(name)
         self.assertEquals(value, actual_value)
@@ -2063,9 +2073,9 @@
         calls = []
         def hook(*args):
             calls.append(args)
-        config.ConfigHooks.install_named_hook('old_set', hook, None)
+        config.OldConfigHooks.install_named_hook('set', hook, None)
         self.addCleanup(
-            config.ConfigHooks.uninstall_named_hook, 'old_set', None)
+            config.OldConfigHooks.uninstall_named_hook, 'set', None)
         self.assertLength(0, calls)
         conf.set_option(value, name)
         self.assertLength(1, calls)
@@ -2089,9 +2099,9 @@
         calls = []
         def hook(*args):
             calls.append(args)
-        config.ConfigHooks.install_named_hook('old_load', hook, None)
+        config.OldConfigHooks.install_named_hook('load', hook, None)
         self.addCleanup(
-            config.ConfigHooks.uninstall_named_hook, 'old_load', None)
+            config.OldConfigHooks.uninstall_named_hook, 'load', None)
         self.assertLength(0, calls)
         # Build a config
         conf = conf_class(*conf_args)
@@ -2119,9 +2129,9 @@
         calls = []
         def hook(*args):
             calls.append(args)
-        config.ConfigHooks.install_named_hook('old_save', hook, None)
+        config.OldConfigHooks.install_named_hook('save', hook, None)
         self.addCleanup(
-            config.ConfigHooks.uninstall_named_hook, 'old_save', None)
+            config.OldConfigHooks.uninstall_named_hook, 'save', None)
         self.assertLength(0, calls)
         # Setting an option triggers a save
         conf.set_option('foo', 'bar')

=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- a/doc/en/release-notes/bzr-2.4.txt	2011-06-08 19:49:23 +0000
+++ b/doc/en/release-notes/bzr-2.4.txt	2011-06-14 09:58:01 +0000
@@ -20,10 +20,10 @@
 
 .. New commands, options, etc that users may wish to try out.
 
-* Hooks added for config stacks: ``get``, ``set`` and ``remove`` are called
-  when an option is repsectively read, modified or deleted. Also added
-  ``load`` and ``save`` hooks for config stores, called when the stores are
-  loaded or saved.  (Vincent Ladeuil)
+* Hooks have been added for config stacks: ``get``, ``set`` and ``remove``
+  are called when an option is repsectively read, modified or deleted. Also
+  added ``load`` and ``save`` hooks for config stores, called when the
+  stores are loaded or saved.  (Vincent Ladeuil)
 
 * New hook server_exception in bzrlib.smart.server to catch any
   exception caused while running bzr serve.



More information about the bazaar-commits mailing list