Robot Framework Integrated Development Environment (RIDE)
pluginconnector.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 from .. import utils
17 from ..context import LOG
18 
19 
20 def PluginFactory(application, plugin_class):
21  try:
22  plugin = plugin_class(application)
23  except Exception:
24  msg, traceback = utils.get_error_details()
25  return BrokenPlugin(msg, traceback, plugin_class)
26  else:
27  return PluginConnector(plugin, application)
28 
29 
31 
32  def __init__(self, name, doc='', error=None):
33  self.namename = name
34  self.docdoc = doc
35  self.errorerror = error
36  self.enabledenabled = False
37  self.metadatametadata = {}
38  self.config_panelconfig_panel = lambda self: None
39 
40 
42 
43  def __init__(self, plugin, application):
44  _PluginConnector.__init__(self, plugin.name, plugin.doc)
45  self._plugin_plugin = plugin
46  self._settings_settings = application.settings['Plugins'].add_section(plugin.name)
47  self.config_panelconfig_panelconfig_panel = plugin.config_panel
48  self.metadatametadatametadata = plugin.metadata
49 
50  def enable_on_startup(self):
51  if self._settings_settings.get('_enabled', self._plugin_plugin.initially_enabled):
52  self.enableenable()
53 
54  def enable(self):
55  self._settings_settings.set('_enabled', True)
56  self.enabledenabledenabled = True
57  self._plugin_plugin.enable()
58 
59  def disable(self):
60  if self.enabledenabledenabled:
61  self._settings_settings.set('_enabled', False)
62  self.enabledenabledenabled = False
63  self._plugin_plugin.disable()
64 
65 
67 
68  def __init__(self, error_msg, traceback, plugin_class):
69  name = utils.name_from_class(plugin_class, 'Plugin')
70  doc = 'This plugin is disabled because it failed to load properly.\n' \
71  + 'Error: ' + error_msg + '\n' + traceback
72  _PluginConnector.__init__(self, name, doc=doc, error=error_msg)
73  LOG.error("Taking %s plugin into use failed:\n%s" % (name, error_msg))
74 
75  def enable_on_startup(self):
76  pass
def __init__(self, error_msg, traceback, plugin_class)
def __init__(self, name, doc='', error=None)
def PluginFactory(application, plugin_class)