implement ability to load external extractor classes

- -X/--extractors
- extractor.module-sources
This commit is contained in:
Mike Fährmann
2023-01-30 20:07:18 +01:00
parent 9ec627c760
commit c2bc70593e
6 changed files with 80 additions and 26 deletions

View File

@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2022 Mike Fährmann
# Copyright 2015-2023 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
import sys
import re
modules = [
@@ -217,20 +218,33 @@ def extractors():
# --------------------------------------------------------------------
# internals
_cache = []
_module_iter = iter(modules)
def _list_classes():
"""Yield all available extractor classes"""
"""Yield available extractor classes"""
yield from _cache
globals_ = globals()
for module_name in _module_iter:
module = __import__(module_name, globals_, None, (), 1)
for module in _module_iter:
yield from add_module(module)
globals_["_list_classes"] = lambda : _cache
globals()["_list_classes"] = lambda : _cache
def _modules_internal():
globals_ = globals()
for module_name in modules:
yield __import__(module_name, globals_, None, (), 1)
def _modules_path(path, files):
sys.path.insert(0, path)
try:
return [
__import__(name[:-3])
for name in files
if name.endswith(".py")
]
finally:
del sys.path[0]
def _get_classes(module):
@@ -240,3 +254,7 @@ def _get_classes(module):
hasattr(cls, "pattern") and cls.__module__ == module.__name__
)
]
_cache = []
_module_iter = _modules_internal()