3 Copyright (c) 2011-2015 ARM Limited
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
17 Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
21 """ Simple class used to register and store
22 host test plugins for further usage
28 """! Prints error directly on console
30 @param text Error message text message
32 print(
"Plugin load failed. Reason: %s"% text)
35 """! Registers and stores plugin inside registry for further use.
37 @param plugin Plugin name
39 @return True if plugin setup was successful and plugin can be registered, else False
41 @details Method also calls plugin's setup() function to configure plugin if needed.
42 Note: Different groups of plugins may demand different extra parameter. Plugins
43 should be at least for one type of plugin configured with the same parameters
44 because we do not know which of them will actually use particular parameter.
48 if plugin.name
not in self.
PLUGINSPLUGINS:
50 self.
PLUGINSPLUGINS[plugin.name] = plugin
53 self.
print_errorprint_error(
"%s setup failed"% plugin.name)
55 self.
print_errorprint_error(
"%s already loaded"% plugin.name)
59 """! Execute plugin functionality respectively to its purpose
60 @param type Plugin type
61 @param capability Plugin capability name
62 @param args Additional plugin parameters
63 @param kwargs Additional plugin parameters
64 @return Returns result from plugin's execute() method
66 for plugin_name
in self.
PLUGINSPLUGINS:
67 plugin = self.
PLUGINSPLUGINS[plugin_name]
68 if plugin.type == type
and capability
in plugin.capabilities:
69 return plugin.execute(capability, *args, **kwargs)
73 """! Returns list of all capabilities for plugin family with the same type
74 @param type Plugin type
75 @return Returns list of capabilities for plugin. If there are no capabilities empty list is returned
78 for plugin_name
in self.
PLUGINSPLUGINS:
79 plugin = self.
PLUGINSPLUGINS[plugin_name]
80 if plugin.type == type:
81 result.extend(plugin.capabilities)
85 """! Used to load module from system (by import)
86 @param name name of the module to import
87 @return Returns result of __import__ operation
89 mod = __import__(
"module_%s"% name)
93 """! User friendly printing method to show hooked plugins
94 @return Returns string formatted with PrettyTable
96 from prettytable
import PrettyTable, HEADER
97 column_names = [
'name',
'type',
'capabilities',
'stable',
'os_support',
'required_parameters']
98 pt = PrettyTable(column_names, junction_char=
"|", hrules=HEADER)
99 for column
in column_names:
100 pt.align[column] =
'l'
101 for plugin_name
in sorted(self.
PLUGINSPLUGINS.keys()):
102 name = self.
PLUGINSPLUGINS[plugin_name].name
103 type = self.
PLUGINSPLUGINS[plugin_name].type
104 stable = self.
PLUGINSPLUGINS[plugin_name].stable
105 capabilities =
', '.join(self.
PLUGINSPLUGINS[plugin_name].capabilities)
106 is_os_supported = self.
PLUGINSPLUGINS[plugin_name].is_os_supported()
107 required_parameters =
', '.join(self.
PLUGINSPLUGINS[plugin_name].required_parameters)
108 row = [name, type, capabilities, stable, is_os_supported, required_parameters]
110 return pt.get_string()
113 column_names = [
'name',
'type',
'capabilities',
'stable']
115 for plugin_name
in sorted(self.
PLUGINSPLUGINS.keys()):
116 name = self.
PLUGINSPLUGINS[plugin_name].name
117 type = self.
PLUGINSPLUGINS[plugin_name].type
118 stable = self.
PLUGINSPLUGINS[plugin_name].stable
119 capabilities = self.
PLUGINSPLUGINS[plugin_name].capabilities
120 is_os_supported = self.
PLUGINSPLUGINS[plugin_name].is_os_supported()
121 required_parameters = self.
PLUGINSPLUGINS[plugin_name].required_parameters
122 result[plugin_name] = {
126 "capabilities" : capabilities,
127 "os_support" : is_os_supported,
128 "required_parameters" : required_parameters
def call_plugin(self, type, capability, *args, **kwargs)
Execute plugin functionality respectively to its purpose.
def print_error(self, text)
Prints error directly on console.
def get_plugin_caps(self, type)
Returns list of all capabilities for plugin family with the same type.
def register_plugin(self, plugin)
Registers and stores plugin inside registry for further use.
def load_plugin(self, name)
Used to load module from system (by import)
def get_string(self)
User friendly printing method to show hooked plugins.