Skip to content

Commit 7af1b5d

Browse files
committed
Merge remote-tracking branch 'keshav-space/datasource_registry' into vulntotal-clean
2 parents cad9501 + edf2d61 commit 7af1b5d

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

vulntotal/datasources/__init__.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,27 @@
2121
# VulnTotal is a free software tool from nexB Inc. and others.
2222
# Visit https://github.com/nexB/vulnerablecode/ for support and download.
2323

24+
import glob
25+
import importlib
26+
import inspect
27+
from os.path import basename
28+
from os.path import dirname
29+
from os.path import isfile
30+
from os.path import join
2431

25-
DATASOURCE_REGISTRY = []
32+
from vulntotal.validator import DataSource
2633

27-
DATASOURCE_REGISTRY = {x.__module__.split(".")[-1]: x for x in DATASOURCE_REGISTRY}
34+
DATASOURCE_REGISTRY = {}
35+
files = glob.glob(join(dirname(__file__), "*.py"))
36+
modules = [
37+
f"vulntotal.datasources.{basename(f)[:-3]}"
38+
for f in files
39+
if isfile(f) and not f.endswith("__init__.py")
40+
]
41+
42+
43+
for module in modules:
44+
for name, cls in inspect.getmembers(importlib.import_module(module), inspect.isclass):
45+
if cls.__module__ == module and cls.__base__ == DataSource:
46+
DATASOURCE_REGISTRY[cls.__module__.split(".")[-1]] = cls
47+
break

0 commit comments

Comments
 (0)