def _scan(self):
        plugins = []
        dirs = []

        # initial pass, read
        for name in os.listdir(self.root):
            if name in (".", "..",):
                continue

            path = os.path.join(self.root, name)
            if (os.path.isdir(path) and
                    os.path.isfile(os.path.join(path, '__init__.py'))):
                # no conflict
                if path not in sys.path:
                    dirs.append((name, path))
                    sys.path.insert(0, os.path.join(self.root, '..',
                        name))
                    sys.path.insert(0, os.path.join(self.root,  name))

        for (name, d) in dirs:
            try:
                for f in os.listdir(d):
                    if f.endswith(".py") and f != "__init__.py":
                        plugins.append(("%s.%s" % (name, f[:-3]), d))
            except __HOLE__:
                sys.stderr.write("error, loading %s" % f)
                sys.stderr.flush()
                continue

        mod = None
        for (name, d) in plugins:
            mod = importlib.import_module(name)
            if hasattr(mod, "__all__"):
                for attr in mod.__all__:
                    plug = getattr(mod, attr)
                    if issubclass(plug, Plugin):
                        self._load_plugin(plug())
dataset/ETHPy150Open benoitc/gaffer/gaffer/gafferd/plugins.py/PluginDir._scan