Esempio n. 1
0
    def registerPaths(self, paths):
        """This function is helper function to register a list of paths.

        :param paths: A list of module or package paths, see registerByModule() and registerByPackage() for the path format.
        :type paths: list(str)
        """
        self.basePaths.extend(paths)
        for p in paths:
            if not p or p.endswith(".pyc"):
                continue
            importedModule = None
            if os.path.exists(p) and os.path.isdir(p):
                self.registerByPackage(p)
                continue
            elif os.path.isfile(p):
                try:
                    importedModule = modules.importModule(modules.asDottedPath(os.path.normpath(p)))
                except ImportError:
                    logger.error("Failed to import Plugin module: {}, skipped Load".format(p), exc_info=True)
                    continue
            elif modules.isDottedPath(p):
                try:
                    importedModule = modules.importModule(os.path.normpath(p))
                except ImportError:
                    logger.error("Failed to import Plugin module: {}, skipped Load".format(p), exc_info=True)
                    continue
            if importedModule:
                self.registerByModule(importedModule)
                continue
Esempio n. 2
0
    def registerMetaClasses(cls, paths):
        """This function is helper function to register a list of paths.

        :param paths: A list of module or package paths, see registerByModule() and registerByPackage() for the path format.
        :type paths: list(str)
        """
        for p in paths:
            if os.path.isdir(p):
                cls.registerByPackage(p)
                continue
            elif os.path.isfile(p):
                importedModule = modules.importModule(modules.asDottedPath(os.path.normpath(p)))
                if importedModule:
                    cls.registerByModule(importedModule)
                    continue
Esempio n. 3
0
    def registerByPackage(self, pkg):
        """This function is similar to registerByModule() but works on packages, this is an expensive operation as it
        requires a recursive search by importing all sub modules and and searching them.

        :param pkg: The package path to register eg. zoo.libs.apps
        :type pkg: str
        """
        for subModule in modules.iterModules(pkg):
            filename = os.path.splitext(os.path.basename(subModule))[0]
            if filename.startswith("__") or subModule.endswith(".pyc"):
                continue
            subModuleObj = modules.importModule(
                modules.asDottedPath(os.path.normpath(subModule)))
            for member in modules.iterMembers(subModuleObj,
                                              predicate=inspect.isclass):
                self.registerPlugin(member[1])
Esempio n. 4
0
    def registerPaths(self, paths):
        """This function is helper function to register a list of paths.

        :param paths: A list of module or package paths, see registerByModule() and registerByPackage() for the path format.
        :type paths: list(str)
        """
        self.basePaths.extend(paths)
        for p in paths:
            if not p or p.endswith(".pyc"):
                continue
            importedModule = None
            if os.path.exists(p) and os.path.isdir(p):
                self.registerByPackage(p)
                continue
            elif os.path.isfile(p):
                importedModule = modules.importModule(
                    modules.asDottedPath(os.path.normpath(p)))
            elif modules.isDottedPath(p):
                importedModule = modules.importModule(os.path.normpath(p))
            if importedModule:
                self.registerByModule(importedModule)
                continue