core: plugins can now be loaded from a directory:
A plugin can now be a directory with a name starting by `plugin_`. It will then be loaded as a module. The `__init__.py` file must contain the `PLUGIN_INFO` dict with metadata.
This commit is contained in:
parent
72501fd596
commit
c47ebb39a0
1 changed files with 22 additions and 11 deletions
|
|
@ -16,7 +16,6 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from glob import glob
|
||||
import sys
|
||||
import os.path
|
||||
import uuid
|
||||
|
|
@ -273,17 +272,29 @@ class SAT(service.Service):
|
|||
# TODO: do not import all plugins if no needed: component plugins are not needed
|
||||
# if we just use a client, and plugin blacklisting should be possible in
|
||||
# sat.conf
|
||||
plugins_path = os.path.dirname(sat.plugins.__file__)
|
||||
plugin_glob = "plugin*." + C.PLUGIN_EXT
|
||||
plug_lst = [
|
||||
os.path.splitext(plugin)[0]
|
||||
for plugin in map(
|
||||
os.path.basename, glob(os.path.join(plugins_path, plugin_glob))
|
||||
)
|
||||
]
|
||||
plugins_path = Path(sat.plugins.__file__).parent
|
||||
plugins_to_import = {} # plugins we still have to import
|
||||
for plug in plug_lst:
|
||||
plugin_path = "sat.plugins." + plug
|
||||
for plug_path in plugins_path.glob("plugin_*"):
|
||||
if plug_path.is_dir():
|
||||
init_path = plug_path / f"__init__.{C.PLUGIN_EXT}"
|
||||
if not init_path.exists():
|
||||
log.warning(
|
||||
f"{plug_path} doesn't appear to be a package, can't load it")
|
||||
continue
|
||||
plug_name = plug_path.name
|
||||
elif plug_path.is_file():
|
||||
if plug_path.suffix != f".{C.PLUGIN_EXT}":
|
||||
continue
|
||||
plug_name = plug_path.stem
|
||||
else:
|
||||
log.warning(
|
||||
f"{plug_path} is not a file or a dir, ignoring it")
|
||||
continue
|
||||
if not plug_name.isidentifier():
|
||||
log.warning(
|
||||
f"{plug_name!r} is not a valid name for a plugin, ignoring it")
|
||||
continue
|
||||
plugin_path = f"sat.plugins.{plug_name}"
|
||||
try:
|
||||
__import__(plugin_path)
|
||||
except exceptions.MissingModule as e:
|
||||
|
|
|
|||
Loading…
Reference in a new issue