From 4e8d08f221ae2af1807be986a1bb1acf322d18d7 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Sat, 27 Jun 2009 18:58:42 +0200 Subject: [PATCH] [entropy.core] improve plugins support, add post_setup method It is now possible to run post SystemSettings setup stuff in SystemSettingsPlugin instances. This could be handy to hook code that needs SystemSettings complete metadata itself. --- libraries/entropy/core.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/libraries/entropy/core.py b/libraries/entropy/core.py index dd5bbe092..10c13e714 100644 --- a/libraries/entropy/core.py +++ b/libraries/entropy/core.py @@ -182,6 +182,20 @@ class SystemSettingsPlugin: system_settings_instance[plugin_id] = {} system_settings_instance[plugin_id][parser_id] = data + def post_setup(self, system_settings_instance): + """ + This method is called by SystemSettings instance + after having built all the SystemSettings metadata. + You can reimplement this and hook your refinement code + into this method. + + @param system_settings_instance: SystemSettings instance + @type system_settings_instance: SystemSettings instance + @return: None + @rtype: None + """ + pass + class SystemSettings(Singleton): """ @@ -378,16 +392,24 @@ class SystemSettings(Singleton): @rtype: None """ + def enforce_persistent(): + # merge persistent settings back + self.__data.update(self.__persistent_settings) + # restore backed-up settings + self.__data.update(self.__persistent_settings['backed_up'].copy()) + self.__parse() + enforce_persistent() # plugins support for plugin_id in sorted(self.__plugins): self.__plugins[plugin_id].parse(self) - # merge persistent settings back - self.__data.update(self.__persistent_settings) - # restore backed-up settings - self.__data.update(self.__persistent_settings['backed_up'].copy()) + enforce_persistent() + + # run post-SystemSettings setup, plugins hook + for plugin_id in sorted(self.__plugins): + self.__plugins[plugin_id].post_setup(self) def __setitem__(self, mykey, myvalue): """