Example #1
0
    def decorator(plugin):
        plugin_id = "%s.%s" % (plugin.__module__, plugin.__name__)
        if not name:
            raise ValueError("The name of the plugin %s cannot be empty." %
                             plugin_id)
        if "@" in name:
            raise ValueError("The name of the plugin cannot contain @ symbol" %
                             plugin_id)

        plugin._meta_init()
        try:
            existing_plugin = plugin._get_base().get(name=name,
                                                     platform=platform,
                                                     allow_hidden=True)
        except exceptions.PluginNotFound:
            plugin._meta_set("name", name)
            plugin._meta_set("platform", platform)
        else:
            plugin.unregister()
            raise exceptions.PluginWithSuchNameExists(
                name=name,
                platform=existing_plugin.get_platform(),
                existing_path=(
                    sys.modules[existing_plugin.__module__].__file__),
                new_path=sys.modules[plugin.__module__].__file__)
        plugin._meta_set("hidden", hidden)
        return plugin
Example #2
0
 def _set_name_and_namespace(cls, name, namespace):
     try:
         Plugin.get(name, namespace=namespace)
     except exceptions.PluginNotFound:
         cls._meta_set("name", name)
         cls._meta_set("namespace", namespace)
     else:
         raise exceptions.PluginWithSuchNameExists(name=name,
                                                   namespace=namespace)
Example #3
0
 def _set_name_and_namespace(cls, name, namespace):
     try:
         existing_plugin = Plugin.get(name, namespace=namespace)
     except exceptions.PluginNotFound:
         cls._meta_set("name", name)
         cls._meta_set("namespace", namespace)
     else:
         raise exceptions.PluginWithSuchNameExists(
             name=name, namespace=namespace,
             existing_path=(
                 sys.modules[existing_plugin.__module__].__file__),
             new_path=sys.modules[cls.__module__].__file__
         )
Example #4
0
    def _set_name_and_namespace(cls, name, namespace):
        try:
            existing_plugin = cls._get_base().get(name=name,
                                                  namespace=namespace,
                                                  allow_hidden=True,
                                                  fallback_to_default=False)

        except exceptions.PluginNotFound:
            cls._meta_set("name", name)
            cls._meta_set("namespace", namespace)
        else:
            raise exceptions.PluginWithSuchNameExists(
                name=name,
                namespace=existing_plugin.get_namespace(),
                existing_path=(
                    sys.modules[existing_plugin.__module__].__file__),
                new_path=sys.modules[cls.__module__].__file__)
Example #5
0
    def _configure(cls, name, namespace="default"):
        """Init plugin and set common meta information.

        For now it sets only name of plugin, that is actually identifier.
        Plugin name should be unique, otherwise exception is raised.

        :param name: Plugin name
        :param namespace: Plugins with the same name are allowed only if they
                          are in various namespaces.
        """
        cls._meta_init()

        try:
            Plugin.get(name, namespace=namespace)
        except exceptions.PluginNotFound:
            cls._meta_set("name", name)
            cls._meta_set("namespace", namespace)
        else:
            raise exceptions.PluginWithSuchNameExists(name=name,
                                                      namespace=namespace)
        return cls
Example #6
0
    def decorator(plugin):
        if name is None:
            plugin_id = "%s.%s" % (plugin.__module__, plugin.__name__)
            raise ValueError("The name of the plugin %s cannot be None." %
                             plugin_id)

        plugin._meta_init()
        try:
            existing_plugin = plugin._get_base().get(
                name=name, platform=platform, allow_hidden=True,
                fallback_to_default=False)
        except exceptions.PluginNotFound:
            plugin._meta_set("name", name)
            plugin._meta_set("platform", platform)
        else:
            plugin.unregister()
            raise exceptions.PluginWithSuchNameExists(
                name=name, platform=existing_plugin.get_platform(),
                existing_path=(
                    sys.modules[existing_plugin.__module__].__file__),
                new_path=sys.modules[plugin.__module__].__file__
            )
        plugin._meta_set("hidden", hidden)
        return plugin