Exemplo n.º 1
0
 def _start_background_tasks(self):
     """ Start all background tasks. """
     tasks = get_special_methods(self._plugin, 'background_task')
     for task in tasks:
         thread = Thread(target=PluginRuntime._run_background_task, args=(task,))
         thread.name = 'Background thread ({0})'.format(task.__name__)
         thread.daemon = True
         thread.start()
Exemplo n.º 2
0
 def _start_background_tasks(self):
     """ Start all background tasks. """
     tasks = get_special_methods(self._plugin, 'background_task')
     for task in tasks:
         thread = Thread(target=PluginRuntime._run_background_task,
                         args=(task, ))
         thread.name = 'Background thread ({0})'.format(task.__name__)
         thread.daemon = True
         thread.start()
Exemplo n.º 3
0
    def _init_plugin(self):
        plugin_root = os.path.dirname(self._path)
        plugin_dir = os.path.basename(self._path)

        # Add the plugin and it's eggs to the python path
        sys.path.insert(0, plugin_root)
        for egg_file in os.listdir(self._path):
            if egg_file.endswith('.egg'):
                sys.path.append(os.path.join(self._path, egg_file))

        # Expose plugins.base to the plugin
        sys.modules['plugins'] = sys.modules['__main__']
        sys.modules["plugins.base"] = base

        # Instanciate the plugin class
        plugin_class = get_plugin_class(plugin_dir)
        check_plugin(plugin_class)

        # Set the name, version, interfaces
        self._name = plugin_class.name
        self._version = plugin_class.version
        self._interfaces = plugin_class.interfaces

        # Initialze the plugin
        self._plugin = plugin_class(self._webinterface, IO._log)

        # Set the receivers
        receiver_mapping = {
            'input_status': self._input_status_receivers,
            'output_status': self._output_status_receivers,
            'shutter_status': self._shutter_status_receivers,
            'receive_events': self._event_receivers
        }

        for method_attribute, target in receiver_mapping.iteritems():
            for method in get_special_methods(self._plugin, method_attribute):
                target.append(method)

            if len(target) > 0:
                self._receivers.append(method_attribute)

        # Set the exposed methods
        for method in get_special_methods(self._plugin, 'om_expose'):
            self._exposes.append({
                'name':
                method.__name__,
                'auth':
                method.om_expose['auth'],
                'content_type':
                method.om_expose['content_type']
            })

        # Set the metric definitions
        if has_interface(plugin_class, 'metrics', '1.0'):
            if hasattr(plugin_class, 'metric_definitions'):
                self._metric_definitions = plugin_class.metric_definitions

        # Set the metric collectors
        for method in get_special_methods(self._plugin, 'om_metric_data'):
            self._metric_collectors.append({
                'name':
                method.__name__,
                'interval':
                method.om_metric_data['interval']
            })

        # Set the metric receivers
        for method in get_special_methods(self._plugin, 'om_metric_receive'):
            self._metric_receivers.append({
                'name':
                method.__name__,
                'source':
                method.om_metric_receive['source'],
                'metric_type':
                method.om_metric_receive['metric_type'],
                'interval':
                method.om_metric_receive['interval']
            })
Exemplo n.º 4
0
 def _handle_remove_callback(self):
     for method in get_special_methods(self._plugin, 'on_remove'):
         try:
             method()
         except Exception as exception:
             IO._log_exception('on remove', exception)
Exemplo n.º 5
0
    def _init_plugin(self):
        plugin_root = os.path.dirname(self._path)
        plugin_dir = os.path.basename(self._path)

        # Add the plugin and it's eggs to the python path
        sys.path.insert(0, plugin_root)
        for egg_file in os.listdir(self._path):
            if egg_file.endswith('.egg'):
                sys.path.append(os.path.join(self._path, egg_file))

        # Expose plugins.base to the plugin
        sys.modules['plugins'] = sys.modules['__main__']
        sys.modules["plugins.base"] = base

        # Instanciate the plugin class
        plugin_class = get_plugin_class(plugin_dir)
        check_plugin(plugin_class)

        # Set the name, version, interfaces
        self._name = plugin_class.name
        self._version = plugin_class.version
        self._interfaces = plugin_class.interfaces

        # Initialze the plugin
        self._plugin = plugin_class(self._webinterface, IO._log)

        # Set the receivers
        receiver_mapping = {'input_status': self._input_status_receivers,
                            'output_status': self._output_status_receivers,
                            'shutter_status': self._shutter_status_receivers,
                            'receive_events': self._event_receivers}

        for method_attribute, target in receiver_mapping.iteritems():
            for method in get_special_methods(self._plugin, method_attribute):
                target.append(method)

            if len(target) > 0:
                self._receivers.append(method_attribute)

        # Set the exposed methods
        for method in get_special_methods(self._plugin, 'om_expose'):
            self._exposes.append({'name': method.__name__,
                                  'auth': method.om_expose['auth'],
                                  'content_type': method.om_expose['content_type']})

        # Set the metric definitions
        if has_interface(plugin_class, 'metrics', '1.0'):
            if hasattr(plugin_class, 'metric_definitions'):
                self._metric_definitions = plugin_class.metric_definitions

        # Set the metric collectors
        for method in get_special_methods(self._plugin, 'om_metric_data'):
            self._metric_collectors.append({'name': method.__name__,
                                            'interval': method.om_metric_data['interval']})

        # Set the metric receivers
        for method in get_special_methods(self._plugin, 'om_metric_receive'):
            self._metric_receivers.append({'name': method.__name__,
                                           'source': method.om_metric_receive['source'],
                                           'metric_type': method.om_metric_receive['metric_type'],
                                           'interval': method.om_metric_receive['interval']})
Exemplo n.º 6
0
 def _handle_remove_callback(self):
     for method in get_special_methods(self._plugin, 'on_remove'):
         try:
             method()
         except Exception as exception:
             IO._log_exception('on remove', exception)
Exemplo n.º 7
0
    def _init_plugin(self):
        # type: () -> None
        plugin_root = os.path.dirname(self._path)
        plugin_dir = os.path.basename(self._path)

        # Add the plugin and it's eggs to the python path
        sys.path.insert(0, plugin_root)
        for egg_file in os.listdir(self._path):
            if egg_file.endswith('.egg'):
                sys.path.append(os.path.join(self._path, egg_file))

        # Expose plugins.base to the plugin
        sys.modules['plugins'] = sys.modules['__main__']
        sys.modules["plugins.base"] = base

        # Instanciate the plugin class
        plugin_class = get_plugin_class(plugin_dir)
        check_plugin(plugin_class)

        # Set the name, version, interfaces
        self._name = plugin_class.name
        self._version = plugin_class.version
        self._interfaces = plugin_class.interfaces

        # Initialze the plugin
        self._plugin = plugin_class(self._webinterface, self._writer.log)

        for decorator_name, decorated_methods in six.iteritems(
                self._decorated_methods):
            for decorated_method, decorator_version in get_special_methods(
                    self._plugin, decorator_name):
                # only add if supported, raise if an unsupported version is found
                if decorator_version not in PluginRuntime.SUPPORTED_DECORATOR_VERSIONS[
                        decorator_name]:
                    raise NotImplementedError(
                        'Decorator {} version {} is not supported'.format(
                            decorator_name, decorator_version))
                decorated_methods.append(
                    decorated_method)  # add the decorated method to the list

        # Set the exposed methods
        for decorated_method, _ in get_special_methods(self._plugin,
                                                       'om_expose'):
            self._exposes.append({
                'name':
                decorated_method.__name__,
                'auth':
                decorated_method.om_expose['auth'],
                'content_type':
                decorated_method.om_expose['content_type']
            })

        # Set the metric collectors
        for decorated_method, _ in get_special_methods(self._plugin,
                                                       'om_metric_data'):
            self._metric_collectors.append({
                'name':
                decorated_method.__name__,
                'interval':
                decorated_method.om_metric_data['interval']
            })

        # Set the metric receivers
        for decorated_method, _ in get_special_methods(self._plugin,
                                                       'om_metric_receive'):
            self._metric_receivers.append({
                'name':
                decorated_method.__name__,
                'source':
                decorated_method.om_metric_receive['source'],
                'metric_type':
                decorated_method.om_metric_receive['metric_type'],
                'interval':
                decorated_method.om_metric_receive['interval']
            })

        # Set the metric definitions
        if has_interface(plugin_class, 'metrics', '1.0'):
            if hasattr(plugin_class, 'metric_definitions'):
                self._metric_definitions = plugin_class.metric_definitions