def execute(self, *args, **kwargs):
        filename = args[0]
        if not os.path.exists(filename):
            raise CommandError("File not found %s" % filename)
        filename = os.path.abspath(filename)

        parts = filename.strip(os.path.sep).split(os.path.sep)
        module_dir = os.path.sep + os.path.join(*parts[0:-1])
        if os.path.isdir(filename):
            # Dir name is module name
            module_name = parts[-1]
        else:
            # Strip off .py
            module_name = parts[-1][0:-3]

        if not module_dir in sys.path:
            sys.path.append(module_dir)

        settings.INSTALLED_STORAGE_PLUGINS = ["linux"]
        from chroma_core.lib.storage_plugin.manager import StoragePluginManager

        manager = StoragePluginManager()

        print("Validating plugin '%s'..." % module_name)
        errors = manager.validate_plugin(module_name)
        if errors:
            print("Validation errors:")
            for e in errors:
                print("  %s" % e)
        else:
            print("OK")

        # Returning does nothing when run normally, but is useful for testing
        return errors
Пример #2
0
    def _load_plugin(self, name):
        from chroma_core.lib.storage_plugin.manager import StoragePluginManager

        orginal_plugins = sys.modules["settings"].INSTALLED_STORAGE_PLUGINS
        sys.modules["settings"].INSTALLED_STORAGE_PLUGINS = [name]
        self.manager = StoragePluginManager()
        sys.modules["settings"].INSTALLED_STORAGE_PLUGINS = orginal_plugins
Пример #3
0
def load_plugins(mod_names):
    import sys
    import os
    import settings
    orig_path = sys.path
    sys.path.append(os.path.abspath(os.path.dirname(__file__)))
    orig_installed_plugins = settings.INSTALLED_STORAGE_PLUGINS
    settings.INSTALLED_STORAGE_PLUGINS = mod_names

    try:
        from chroma_core.lib.storage_plugin.manager import StoragePluginManager
        return StoragePluginManager()
    finally:
        sys.path = orig_path
        settings.INSTALLED_STORAGE_PLUGINS = orig_installed_plugins