From 0e7933ff0b3a575acd66791611792d6294df7348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Mon, 3 Apr 2017 17:01:13 +0200 Subject: [PATCH] variables: support inheritance of variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resolves: rhbz#1374168 Signed-off-by: Jaroslav Škarvada --- tuned/profiles/loader.py | 20 ++++++++++---------- tuned/profiles/variables.py | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tuned/profiles/loader.py b/tuned/profiles/loader.py index a1b6455b..5ee7bed2 100644 --- a/tuned/profiles/loader.py +++ b/tuned/profiles/loader.py @@ -57,6 +57,9 @@ def load(self, profile_names): final_profile = profiles[0] final_profile.name = " ".join(profile_names) + if "variables" in final_profile.units: + self._variables.add_from_cfg(final_profile.units["variables"].options) + del(final_profile.units["variables"]) return final_profile def _load_profile(self, profile_names, profiles, processed_files): @@ -85,16 +88,13 @@ def _load_config_data(self, file_name): config = collections.OrderedDict() for section in config_obj.keys(): - if section == "variables": - self._variables.add_from_cfg(config_obj[section], os.path.dirname(file_name)) - else: - config[section] = collections.OrderedDict() - try: - keys = config_obj[section].keys() - except AttributeError: - raise InvalidProfileException("Error parsing section '%s' in file '%s'." % (section, file_name)) - for option in keys: - config[section][option] = config_obj[section][option] + config[section] = collections.OrderedDict() + try: + keys = config_obj[section].keys() + except AttributeError: + raise InvalidProfileException("Error parsing section '%s' in file '%s'." % (section, file_name)) + for option in keys: + config[section][option] = config_obj[section][option] dir_name = os.path.dirname(file_name) # TODO: Could we do this in the same place as the expansion of other functions? diff --git a/tuned/profiles/variables.py b/tuned/profiles/variables.py index a871ad99..5d85c8dc 100644 --- a/tuned/profiles/variables.py +++ b/tuned/profiles/variables.py @@ -59,10 +59,10 @@ def add_from_file(self, filename): else: self.add_variable(item, config[item]) - def add_from_cfg(self, cfg, dir_name): + def add_from_cfg(self, cfg): for item in cfg: if str(item) == "include": - self.add_from_file(os.path.normpath(os.path.join(dir_name, cfg[item]))) + self.add_from_file(os.path.normpath(cfg[item])) else: self.add_variable(item, cfg[item])