import os import os.path import sys def my_import(mod_name): module = __import__(mod_name) components = mod_name.split('.') for comp in components[1:]: module = getattr(module, comp) return module def iter_plugins(prefix): """ >>> "list" in [n for n,m in iter_plugins("becommands")] True >>> "plugin" in [n for n,m in iter_plugins("libbe")] True """ modfiles = os.listdir(os.path.join(plugin_path, prefix)) modfiles.sort() for modfile in modfiles: if modfile.endswith(".py") and modfile != "__init__.py": yield modfile[:-3], my_import(prefix+"."+modfile[:-3]) def get_plugin(prefix, name): """ >>> get_plugin("becommands", "asdf") is None True >>> q = repr(get_plugin("becommands", "list")) >>> q.startswith("