Rev 5797: Separate the hooks for old and new config implementations instead of cheating like crazy. in file:///home/vila/src/bzr/experimental/config/

Vincent Ladeuil v.ladeuil+lp at free.fr
Mon Jun 13 10:57:46 UTC 2011


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

------------------------------------------------------------
revno: 5797
revision-id: v.ladeuil+lp at free.fr-20110613105746-zlggzfmc0spxzfsg
parent: v.ladeuil+lp at free.fr-20110613102346-25hem1cl1q05kd1q
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-hooks
timestamp: Mon 2011-06-13 12:57:46 +0200
message:
  Separate the hooks for old and new config implementations instead of cheating like crazy.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-06-13 10:23:46 +0000
+++ b/bzrlib/config.py	2011-06-13 10:57:46 +0000
@@ -371,9 +371,7 @@
                               % (option_name,))
             else:
                 value = self._expand_options_in_string(value)
-        for hook in ConfigHooks['get']:
-            # We're lying here pretending to be a Stack until we get deprecated
-            # -- vila 20110610
+        for hook in ConfigHooks['old_get']:
             hook(self, option_name, value)        
         return value
 
@@ -591,6 +589,28 @@
                       'Invoked when a config option is removed.'
                       ' The signature is (stack, name).',
                       (2, 4))
+        # Hooks for the actual implementation
+        self.add_hook('old_load',
+                      'Invoked when a config store is loaded.'
+                      ' The signature is (config).',
+                      (2, 4))
+        self.add_hook('old_save',
+                      'Invoked when a config store is saved.'
+                      ' The signature is (config).',
+                      (2, 4))
+        # The hooks for config options
+        self.add_hook('old_get',
+                      'Invoked when a config option is read.'
+                      ' The signature is (config, name, value).',
+                      (2, 4))
+        self.add_hook('old_set',
+                      'Invoked when a config option is set.'
+                      ' The signature is (config, name, value).',
+                      (2, 4))
+        self.add_hook('old_remove',
+                      'Invoked when a config option is removed.'
+                      ' The signature is (config, name).',
+                      (2, 4))
 ConfigHooks = _ConfigHooks()
 
 
@@ -661,9 +681,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['load']:
-            # We're lying here pretending to be a Store until we get deprecated
-            # -- vila 20110610
+        for hook in ConfigHooks['old_load']:
             hook(self)
         return self._parser
 
@@ -673,9 +691,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['load']:
-            # We're lying here pretending to be a Store until we get deprecated
-            # -- vila 20110610
+        for hook in ConfigHooks['old_load']:
             hook(self)
 
     def _get_matching_sections(self):
@@ -854,9 +870,7 @@
         except KeyError:
             raise errors.NoSuchConfigOption(option_name)
         self._write_config_file()
-        for hook in ConfigHooks['remove']:
-            # We're lying here pretending to be a Stack until we get deprecated
-            # -- vila 20110610
+        for hook in ConfigHooks['old_remove']:
             hook(self, option_name)
 
     def _write_config_file(self):
@@ -869,9 +883,7 @@
         atomic_file.commit()
         atomic_file.close()
         osutils.copy_ownership_from_path(self.file_name)
-        for hook in ConfigHooks['save']:
-            # We're lying here pretending to be a Store until we get deprecated
-            # -- vila 20110610
+        for hook in ConfigHooks['old_save']:
             hook(self)
 
 
@@ -1006,9 +1018,7 @@
         self.reload()
         self._get_parser().setdefault(section, {})[option] = value
         self._write_config_file()
-        for hook in ConfigHooks['set']:
-            # We're lying here pretending to be a Store until we get deprecated
-            # -- vila 20110610
+        for hook in ConfigHooks['old_set']:
             hook(self, option, value)
 
     def _get_sections(self, name=None):
@@ -1211,9 +1221,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['set']:
-            # We're lying here pretending to be a Store until we get deprecated
-            # -- vila 20110610
+        for hook in ConfigHooks['old_set']:
             hook(self, option, value)
 
 
@@ -2118,9 +2126,7 @@
             except KeyError:
                 return default
         value = section_obj.get(name, default)
-        for hook in ConfigHooks['get']:
-            # We're lying here pretending to be a Stack until we get deprecated
-            # -- vila 20110613
+        for hook in ConfigHooks['old_get']:
             hook(self, name, value)        
         return value
 
@@ -2136,9 +2142,7 @@
             configobj[name] = value
         else:
             configobj.setdefault(section, {})[name] = value
-        for hook in ConfigHooks['set']:
-            # We're lying here pretending to be a Store until we get deprecated
-            # -- vila 20110610
+        for hook in ConfigHooks['old_set']:
             hook(self, name, value)
         self._set_configobj(configobj)
 
@@ -2148,18 +2152,14 @@
             del configobj[option_name]
         else:
             del configobj[section_name][option_name]
-        for hook in ConfigHooks['remove']:
-            # We're lying here pretending to be a Store until we get deprecated
-            # -- vila 20110613
+        for hook in ConfigHooks['old_remove']:
             hook(self, option_name, value)
         self._set_configobj(configobj)
 
     def _get_config_file(self):
         try:
             f = StringIO(self._transport.get_bytes(self._filename))
-            for hook in ConfigHooks['load']:
-                # We're lying here pretending to be a Store until we get
-                # deprecated -- vila 20110613
+            for hook in ConfigHooks['old_load']:
                 hook(self)
             return f
         except errors.NoSuchFile:
@@ -2177,9 +2177,7 @@
         configobj.write(out_file)
         out_file.seek(0)
         self._transport.put_file(self._filename, out_file)
-        for hook in ConfigHooks['save']:
-            # We're lying here pretending to be a Store until we get deprecated
-            # -- vila 20110613
+        for hook in ConfigHooks['old_save']:
             hook(self)
 
 



More information about the bazaar-commits mailing list