From cf6db4d845d002dd7cf8fd5b4e98ce8d1231e66e Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Mon, 30 Jan 2012 08:23:51 +0100 Subject: [PATCH] Support [main] include --- tuned/controller.py | 5 ++--- tuned/daemon.py | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/tuned/controller.py b/tuned/controller.py index 195ec58..2496459 100644 --- a/tuned/controller.py +++ b/tuned/controller.py @@ -102,7 +102,7 @@ class Controller(exports.interfaces.ExportableInterface): def switch_profile(self, profile): cfg = "/etc/tune-profiles/%s/tuned.conf" % (profile) try: - config_file = cfg + self.config_file = cfg except ValueError as e: log.error("Unable to open profile's config file %s" % (cfg) ) return False @@ -111,8 +111,7 @@ class Controller(exports.interfaces.ExportableInterface): @exports.export("", "s") def active_profile(self): - # TODO - return "default" + return self.config_file.split("/")[-2] @exports.export("", "a{bb}") def status(self): diff --git a/tuned/daemon.py b/tuned/daemon.py index 94ea838..fa5b576 100644 --- a/tuned/daemon.py +++ b/tuned/daemon.py @@ -36,11 +36,18 @@ class Daemon(object): self._thread = None self._terminate = threading.Event() - def _load_plugins(self, manager): - cfg = ConfigParser.SafeConfigParser() - cfg.read(self._config_file) + # TODO: Move me to different class probably? + def _load_config(self, manager, config): + if not os.path.exists(config): + log.error("Config file %s does not exist" % (config)) + return + + cfg = ConfigParser.SafeConfigParser() + cfg.read(config) + + if cfg.has_option("main", "include"): + self._load_config(manager, cfg.get("main", "include")) - for section in cfg.sections(): if section == "main": continue @@ -54,7 +61,9 @@ class Daemon(object): del plugin_cfg["type"] p = manager.create(section, plugin, plugin_cfg) - + + def _load_plugins(self, manager): + self._load_config(manager, self._config_file) def _thread_code(self): self._terminate.clear()