How to use the safeeyes.Utility.SYSTEM_PLUGINS_DIR function in safeeyes

To help you get started, we’ve selected a few safeeyes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github slgobinath / SafeEyes / safeeyes / PluginManager.py View on Github external
Executes once the plugin.py is loaded as a module
 - disable()
    Executes if the plugin is disabled at the runtime by the user
 - on_exit()
    Executes before Safe Eyes exits
"""

import importlib
import inspect
import logging
import os
import sys

from safeeyes import Utility

sys.path.append(os.path.abspath(Utility.SYSTEM_PLUGINS_DIR))
sys.path.append(os.path.abspath(Utility.USER_PLUGINS_DIR))

HORIZONTAL_LINE_LENGTH = 64


class PluginManager(object):
    """
    Imports the Safe Eyes plugins and calls the methods defined in those plugins.
    """

    def __init__(self, context, config):
        logging.info('Load all the plugins')
        self.__plugins = {}
        self.__plugins_on_init = []
        self.__plugins_on_start = []
        self.__plugins_on_stop = []
github slgobinath / SafeEyes / safeeyes / PluginManager.py View on Github external
if not plugin_obj['break_override_allowed']:
                # Remaining methods also should be removed
                self.__remove_if_exists(self.__plugins_on_init, plugin_obj)
                self.__remove_if_exists(self.__plugins_on_pre_break, plugin_obj)
                self.__remove_if_exists(self.__plugins_on_start_break, plugin_obj)
                self.__remove_if_exists(self.__plugins_on_stop_break, plugin_obj)
                self.__remove_if_exists(self.__plugins_on_countdown, plugin_obj)
                self.__remove_if_exists(self.__widget_plugins, plugin_obj)
                self.__remove_if_exists(self.__tray_actions_plugins, plugin_obj)
                del self.__plugins[plugin['id']]
            return

        # Look for plugin.py
        plugin_dir = None
        if os.path.isfile(os.path.join(Utility.SYSTEM_PLUGINS_DIR, plugin['id'], 'plugin.py')):
            plugin_dir = Utility.SYSTEM_PLUGINS_DIR
        elif os.path.isfile(os.path.join(Utility.USER_PLUGINS_DIR, plugin['id'], 'plugin.py')):
            plugin_dir = Utility.USER_PLUGINS_DIR
        else:
            logging.error('plugin.py not found for the plugin: %s', plugin['id'])
            return
        # Look for config.json
        plugin_path = os.path.join(plugin_dir, plugin['id'])
        plugin_config_path = os.path.join(plugin_path, 'config.json')
        if not os.path.isfile(plugin_config_path):
            logging.error('config.json not found for the plugin: %s', plugin['id'])
            return
        plugin_config = Utility.load_json(plugin_config_path)
        if plugin_config is None:
            return
github slgobinath / SafeEyes / safeeyes / PluginManager.py View on Github external
if not plugin_obj['break_override_allowed']:
                # Remaining methods also should be removed
                self.__remove_if_exists(self.__plugins_on_init, plugin_obj)
                self.__remove_if_exists(self.__plugins_on_pre_break, plugin_obj)
                self.__remove_if_exists(self.__plugins_on_start_break, plugin_obj)
                self.__remove_if_exists(self.__plugins_on_stop_break, plugin_obj)
                self.__remove_if_exists(self.__plugins_on_countdown, plugin_obj)
                self.__remove_if_exists(self.__widget_plugins, plugin_obj)
                self.__remove_if_exists(self.__tray_actions_plugins, plugin_obj)
                del self.__plugins[plugin['id']]
            return

        # Look for plugin.py
        plugin_dir = None
        if os.path.isfile(os.path.join(Utility.SYSTEM_PLUGINS_DIR, plugin['id'], 'plugin.py')):
            plugin_dir = Utility.SYSTEM_PLUGINS_DIR
        elif os.path.isfile(os.path.join(Utility.USER_PLUGINS_DIR, plugin['id'], 'plugin.py')):
            plugin_dir = Utility.USER_PLUGINS_DIR
        else:
            logging.error('plugin.py not found for the plugin: %s', plugin['id'])
            return
        # Look for config.json
        plugin_path = os.path.join(plugin_dir, plugin['id'])
        plugin_config_path = os.path.join(plugin_path, 'config.json')
        if not os.path.isfile(plugin_config_path):
            logging.error('config.json not found for the plugin: %s', plugin['id'])
            return
        plugin_config = Utility.load_json(plugin_config_path)
        if plugin_config is None:
            return

        if (plugin_enabled or plugin_config.get('break_override_allowed', False)):