import os
from modules.element import Element
[docs]class Tool (Element) :
"""tools are elements which are used on the host"""
def __init__ (self, name, config=None, default_path=None, bare=False) :
self._config = config
if config is None :
global_conf = {}
else :
global_conf = config.get_global_dict ()
Element.__init__ (self, name, 'tools', global_conf, default_path, bare)
[docs] def get_builder(self) :
# TODO: shouldn't be removed ? why a builder for a tool ?
builders = self._config.get_plugins_for('get_selected_tools')
configured_builders = [ builder for builder in builders if self._name in builder.get_selected_tools () ]
if not configured_builders :
return None
# Tool can be compiled by only one builder
elif len (configured_builders) == 1 :
return configured_builders [0]
else :
raise ConfigError ("There are more than one builder for %s" % self._name)
[docs] def get_path(self) :
if not self._bare :
builder = self.get_builder ()
if builder :
return builder.get_element_path (self._name)
path = self._conf.get ('path')
if path :
return path
if self._default_path :
return self._default_path
if self._config :
return os.path.join (self._config.get_top_dir (), 'tools', self._name)