1
0
Fork 0

Removed unused code from profile.py

This commit is contained in:
Jan Kaluza 2012-04-16 12:29:05 +02:00
parent 4c8d64f98a
commit 916c0157f0

View file

@ -52,6 +52,15 @@ class Profile(object):
return name
def _apply_config(self):
pp = pprint.PrettyPrinter(indent=4)
log.debug("Loaded config: %s" % (pp.pformat(self._plugin_configs)))
for name, cfg in self._plugin_configs.iteritems():
plugin = cfg["type"]
del cfg["type"]
p = self._manager.create(name, plugin, cfg)
def _disable_plugin(self, name, plugin_cfg):
# Iterates over already loaded plugins.
# If the already loaded plugin contains the same device as the newly
@ -80,34 +89,6 @@ class Profile(object):
log.debug("Removing plugin %s because it is useless after disabling" % (plugin))
del self._plugin_configs[plugin]
def _replace_plugin(self, name, plugin_cfg):
# Iterates over already loaded plugins.
# If the already loaded plugin contains the same device as the newly
# loaded one, remove the device from the already loaded one.
plugins_to_remove = []
for plugin, cfg in self._plugin_configs.iteritems():
if cfg["type"] != plugin_cfg["type"]:
continue
if cfg.has_key("devices") and cfg["devices"] != None:
for device in plugin_cfg["devices"]:
if device in cfg["devices"]:
cfg["devices"].remove(device)
log.debug("Replacing plugin %s device %s by %s" % (plugin, device, name))
# If we removed all devices, this plugin is not useful anymore,
# so we should remove it too:
if (len(cfg["devices"]) == 0):
plugins_to_remove.append(plugin)
else:
# If the plugin does not have any device set, it can be
# run only once, so remove previous occurence
log.debug("Replacing plugin %s by %s" % (plugin, name))
plugins_to_remove.append(plugin)
for plugin in plugins_to_remove:
log.debug("Removing plugin %s because it is useless after replace" % (plugin))
del self._plugin_configs[plugin]
def _merge_plugin(self, name, plugin_cfg):
# Iterates over already loaded plugins.
# Merges the option of two plugins with the same types together
@ -132,12 +113,18 @@ class Profile(object):
log.debug("Removing plugin %s because it is useless after merge" % (plugin))
del self._plugin_configs[plugin]
def _store_plugin_config(self, name, plugin_cfg):
plugin = plugin_cfg["type"]
# Check if the plugin is supported on this HW
if not tuned.plugins.get_repository().is_supported(plugin):
log.info("Plugin %s is not supported on this HW" % (plugin))
try:
if not tuned.plugins.get_repository().is_supported(plugin):
log.info("Plugin %s is not supported on this HW" % (plugin))
return
except:
e.log()
log.error("unable to create unit %s" % plugin)
return
# If there are no devices set, set all tunable_devices as default
@ -156,22 +143,13 @@ class Profile(object):
return
if plugin_cfg.has_key("replace"):
self._replace_plugin(name, plugin_cfg)
self._disable_plugin(name, plugin_cfg)
del plugin_cfg["replace"]
else:
self._merge_plugin(name, plugin_cfg)
self._plugin_configs[name] = plugin_cfg
def _apply_config(self):
pp = pprint.PrettyPrinter(indent=4)
log.debug("Loaded config: %s" % (pp.pformat(self._plugin_configs)))
for name, cfg in self._plugin_configs.iteritems():
plugin = cfg["type"]
del cfg["type"]
p = self._manager.create(name, plugin, cfg)
def _get_unique_name(self, name):
def _get_unique_plugin_name(self, name):
i = 1
n = name
while n in self._plugin_configs.keys():
@ -179,7 +157,19 @@ class Profile(object):
i += 1
return n
def _load_config(self, manager, config):
def _load_plugins(self, cfg, load_path):
for section in cfg.sections():
if section == "main":
continue
if not cfg.has_option(section, "type"):
log.info("No 'type' option for %s plugin, will treat '%s' as a plugin type" % (section, section))
cfg.set(section, "type", section)
cfg.set(section, "_load_path", load_path)
self._store_plugin_config(self._get_unique_plugin_name(section), dict(cfg.items(section)))
return True
def _load_config(self, config):
if not os.path.exists(config):
log.error("Config file %s does not exist" % (config))
return False
@ -189,23 +179,13 @@ class Profile(object):
if cfg.has_option("main", "include"):
included_cfg = self.find_profile(cfg.get("main", "include"))
self._load_config(manager, included_cfg)
if not self._load_config(included_cfg):
return False
for section in cfg.sections():
if section == "main":
continue
if not cfg.has_option(section, "type"):
log.info("No 'type' option for %s plugin, will treat '%s' as a plugin type" % (section, section))
cfg.set(section, "type", section)
cfg.set(section, "_load_path", os.path.dirname(config))
self._store_plugin_config(self._get_unique_name(section), dict(cfg.items(section)))
return True
return self._load_plugins(cfg, os.path.dirname(config))
def load(self):
return (self._load_config(self._manager, self._config_file) and
self._apply_config())
return (self._load_config(self._config_file) and self._apply_config())
def cleanup(self):
pass