Beispiel #1
0
def register_plugin(path_to_plugin, enable_on_install=False):

    if os.path.isfile(PLUGIN_PATH + _sep + path_to_plugin + _sep + "__init__.py"):

        try:
            added_plugin = importlib.import_module("data.plugins." + path_to_plugin)
        except SystemError:
            raise PluginImportError("Plugin at " + PLUGIN_PATH + _sep +
                path_to_plugin + " could not be registered.")
        else:

            try:
                existing_plugin = Plugin.select().where(
                    Plugin.path == path_to_plugin).get()
            except Plugin.DoesNotExist:

                new_plugin = Plugin(
                    name=path_to_plugin,
                    friendly_name=added_plugin.__plugin_name__,
                    path=path_to_plugin,
                    priority=1,
                    enabled=enable_on_install)

                new_plugin.save()

                _stddebug ("Plugin registered: " + added_plugin.__plugin_name__ + "\n")

                return new_plugin

            else:
                raise PluginImportError("Plugin at " + PLUGIN_FILE_PATH +
                    "/" + path_to_plugin + " is already registered.")
Beispiel #2
0
def register_plugin(path_to_plugin, **ka):

    if os.path.isfile(_join(PLUGIN_PATH, path_to_plugin, "__init__.py")):
        try:
            added_plugin = importlib.import_module("data.plugins." +
                                                   path_to_plugin)
        except SystemError:
            raise PluginImportError("Plugin at " +
                                    _join(PLUGIN_PATH, path_to_plugin) +
                                    " could not be registered.")
        else:

            try:
                existing_plugin = Plugin.select().where(
                    Plugin.path == path_to_plugin).get()
            except Plugin.DoesNotExist:

                new_plugin = Plugin(name=path_to_plugin,
                                    friendly_name=added_plugin.__plugin_name__,
                                    path=path_to_plugin,
                                    priority=1,
                                    enabled=ka.get('enable', False))

                new_plugin.save()

                plugin_data = added_plugin.install()

                try:
                    plugin_settings = plugin_data.get(['settings'])
                except (AttributeError, TypeError):
                    pass
                except Exception as e:
                    raise e
                else:

                    from core.models import PluginData
                    for n in plugin_settings:
                        # TODO: instead: iter through __dict__
                        # if dict item not in field list, don't add
                        settings_data = PluginData(
                            plugin=new_plugin,
                            key=n.get('key'),
                            text_value=n.get('text_value'),
                            int_value=n.get('int_value'),
                            blog=n.get('blog'),
                            site=n.get('site'),
                            parent=n.get('parent'))
                        settings_data.save()

                _stddebug("Plugin registered: " +
                          added_plugin.__plugin_name__ + "\n")

                return new_plugin

            else:
                raise PluginImportError("Plugin at " + PLUGIN_FILE_PATH + "/" +
                                        path_to_plugin +
                                        " is already registered.")
Beispiel #3
0
def register_plugin(path_to_plugin, **ka):

    if os.path.isfile(_join(PLUGIN_PATH, path_to_plugin, "__init__.py")):
        try:
            added_plugin = importlib.import_module("data.plugins." + path_to_plugin)
        except SystemError:
            raise PluginImportError("Plugin at " +
                _join(PLUGIN_PATH, path_to_plugin) + " could not be registered.")
        else:

            try:
                existing_plugin = Plugin.select().where(
                    Plugin.path == path_to_plugin).get()
            except Plugin.DoesNotExist:

                new_plugin = Plugin(
                    name=path_to_plugin,
                    friendly_name=added_plugin.__plugin_name__,
                    path=path_to_plugin,
                    priority=1,
                    enabled=ka.get('enable', False)
                    )

                new_plugin.save()

                plugin_data = added_plugin.install()

                try:
                    plugin_settings = plugin_data.get(['settings'])
                except (AttributeError, TypeError):
                    pass
                except Exception as e:
                    raise e
                else:

                    from core.models import PluginData
                    for n in plugin_settings:
                        # TODO: instead: iter through __dict__
                        # if dict item not in field list, don't add
                        settings_data = PluginData(
                            plugin=new_plugin,
                            key=n.get('key'),
                            text_value=n.get('text_value'),
                            int_value=n.get('int_value'),
                            blog=n.get('blog'),
                            site=n.get('site'),
                            parent=n.get('parent')
                            )
                        settings_data.save()

                _stddebug ("Plugin registered: " + added_plugin.__plugin_name__ + "\n")

                return new_plugin

            else:
                raise PluginImportError("Plugin at " + PLUGIN_FILE_PATH +
                    "/" + path_to_plugin + " is already registered.")
Beispiel #4
0
def system_plugins(errormsg=None):
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)

    plugins = Plugin.select()

    return listing(request, None, plugins,
                   'plugins', 'system_plugins',
                   user=user)
Beispiel #5
0
def activate_plugins():

    _stddebug("Activating plugins.\n")

    plugin_errors = []

    plugins_to_activate = Plugin.select().where(Plugin.enabled == True)

    for n in plugins_to_activate:

        try:
            added_plugin = importlib.import_module("data.plugins." + n.path)
        except ImportError as e:
            plugin_errors.append("\nPlugin " + n.friendly_name +
                " could not be activated. The path '" + PLUGIN_FILE_PATH + _sep + n.path +
                "' may be wrong. ({})".format(str(e)))
            continue
        except SystemError as e:
            plugin_errors.append("\nPlugin at '" + PLUGIN_FILE_PATH + _sep + n.path +
                "' could not be activated. The plugin may be improperly installed.".format(e))
            continue

        try:
            for m in plugin_attributes:
                p_a = added_plugin.__getattribute__(m)
        except AttributeError as e:
            plugin_errors.append("\nPlugin at '" + PLUGIN_FILE_PATH + _sep + n.path +
                "' is missing one or more of its configuration attributes. The plugin may be damaged or improperly installed. ({})".format(e))
            continue

        plugin_list[added_plugin.__short_name__] = added_plugin

        try:
            plugin_loader = added_plugin.load()

            for func in plugin_loader:
                action = plugin_action[func['action']]
                module = importlib.import_module(func['module'])
                func_to_wrap = module.__dict__[func['function']]
                if action == 'exec':
                    func_to_wrap(**func['data'])
                else:
                    func_wrapper = func['wrap']
                    module.__dict__[func['function']] = action(func_wrapper)(func_to_wrap)

        except BaseException as e:
            plugin_errors.append("\nPlugin at '" + PLUGIN_FILE_PATH + _sep + n.path +
                "' could not be activated. Its source may be damaged. ({})".format(e))
            continue

        _stddebug("Plugin activated: " + added_plugin.__plugin_name__ + "\n")

    if len(plugin_errors) > 0:
        raise PluginImportError(''.join(plugin_errors))

    _stddebug("\n")
Beispiel #6
0
def disable_plugin(plugin_id):
    with db.atomic():
        try:
            plugin_to_disable = Plugin.select().where(Plugin.id == plugin_id).get()
        except BaseException:
            raise ("Plugin not found")
        else:
            if plugin_to_disable.enabled is True:
                plugin_to_disable.enabled = False
                plugin_to_disable.save()
Beispiel #7
0
def activate_plugins():

    _stddebug("Activating plugins.\n")

    plugin_errors = []

    plugins_to_activate = Plugin.select().where(Plugin.enabled == True)

    for n in plugins_to_activate:

        try:
            added_plugin = importlib.import_module("data.plugins." + n.path)
        except ImportError as e:
            plugin_errors.append("\nPlugin " + n.friendly_name +
                " could not be activated. The path '" + _join(PLUGIN_FILE_PATH, n.path) +
                "' may be wrong. ({})".format(str(e)))
            continue
        except SystemError as e:
            plugin_errors.append("\nPlugin at '" + _join(PLUGIN_FILE_PATH , n.path) +
                "' could not be activated. The plugin may be improperly installed.".format(e))
            continue

        try:
            for m in plugin_attributes:
                p_a = added_plugin.__getattribute__(m)
        except AttributeError as e:
            plugin_errors.append("\nPlugin at '" + _join(PLUGIN_FILE_PATH , n.path) +
                "' is missing one or more of its configuration attributes. The plugin may be damaged or improperly installed. ({})".format(e))
            continue

        plugin_list[n.id] = added_plugin

        try:
            plugin_loader = added_plugin.load()

            for func in plugin_loader:
                action = plugin_action[func['action']]
                module = importlib.import_module(func['module'])
                func_to_wrap = module.__dict__[func['function']]
                if action == 'exec':
                    func_to_wrap(**func['kwargs'])
                else:
                    func_wrapper = func['wrap']
                    module.__dict__[func['function']] = action(func_wrapper)(func_to_wrap)

        except BaseException as e:
            plugin_errors.append("\nPlugin at '" + _join(PLUGIN_FILE_PATH, n.path) +
                "' could not be activated. Its source may be damaged. ({})".format(e))
            continue
        _stddebug("Plugin activated: " + added_plugin.__plugin_name__ + "\n")

    if len(plugin_errors) > 0:
        raise PluginImportError(''.join(plugin_errors))

    _stddebug("\n")
Beispiel #8
0
def disable_plugin(plugin_id):
    with db.atomic():
        try:
            plugin_to_disable = Plugin.select().where(
                Plugin.id == plugin_id).get()
        except BaseException:
            raise ("Plugin not found")
        else:
            if plugin_to_disable.enabled is True:
                plugin_to_disable.enabled = False
                plugin_to_disable.save()
Beispiel #9
0
def system_plugins(errormsg=None):
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)

    plugins = Plugin.select()

    return listing(request,
                   None,
                   plugins,
                   'plugins',
                   'system_plugins',
                   user=user)
Beispiel #10
0
def plugin_settings(plugin_id, errormsg=None):
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)
    plugin = Plugin.get(Plugin.id == plugin_id)

    tags = template_tags(user=user)

    tpl = template('system/plugin',
                   plugin_ui=plugin.ui(),
                   search_context=(search_contexts['sites'], None),
                   menu=generate_menu('system_plugin_data', plugin),
                   **tags.__dict__)

    return tpl
Beispiel #11
0
def disable_plugin(plugin_id):
    with db.atomic():
        try:
            plugin_to_disable = Plugin.select().where(Plugin.id == plugin_id).get()
        except BaseException:
            raise ("Plugin not found")
        else:
            if plugin_to_disable.enabled is False:
                bottle.redirect(BASE_PATH + "/system/plugins")
            else:
                plugin_to_disable.enabled = False
                plugin_to_disable.save()
    from core.boot import reboot
    reboot()
Beispiel #12
0
def plugin_settings(plugin_id, errormsg=None):
    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)
    plugin = Plugin.get(Plugin.id == plugin_id)

    tags = template_tags(
        user=user)

    tpl = template('system/plugin',
        plugin_ui=plugin.ui(),
        search_context=(search_contexts['sites'], None),
        menu=generate_menu('system_plugin_data', plugin),
        **tags.__dict__)

    return tpl
Beispiel #13
0
 def create_plugins(self, plugin_names=[], commit=True):
     """
     Create plugins from the given plugins list.
     If no plugin is given, all are created.
     """
     from core.models import Plugin
     plugins = self.get_plugin_list()
     new_ps = []
     for p in plugins:
         if p in plugin_names or plugin_names == []:
             if not Plugin.objects.filter(name=p, host=self).exists():
                 new_p = Plugin(name=p, host=self)
                 new_ps.append(new_p)
             else:
                 new_ps.append(Plugin.objects.get(name=p, host=self))
     if commit:
         [p.save() for p in new_ps]
     return new_ps
Beispiel #14
0
def reset_plugin(plugin_id):
    existing_plugin = Plugin.load(plugin_id, 'reset')
    existing_plugin.reset()
Beispiel #15
0
def unregister_plugin(plugin_id):
    existing_plugin = Plugin.load(plugin_id, 'remove')
    existing_plugin.clear_data()
    existing_plugin.delete_instance()
Beispiel #16
0
def reset_plugin(plugin_id):
    existing_plugin = Plugin.load(plugin_id, 'reset')
    existing_plugin.reset()
Beispiel #17
0
def unregister_plugin(plugin_id):
    existing_plugin = Plugin.load(plugin_id, 'remove')
    existing_plugin.clear_data()
    existing_plugin.delete_instance()