mininet-sample/topos/__init__.py

23 lines
571 B
Python
Raw Permalink Normal View History

2020-06-24 10:28:44 +00:00
import importlib
import pkgutil
import os
from core.topo import Topo, TopoConfig
pkg_dir = os.path.dirname(__file__)
for (module_loader, name, ispkg) in pkgutil.iter_modules([pkg_dir]):
importlib.import_module('.' + name, __package__)
2020-07-08 12:25:24 +00:00
# Track indirect inheritance
TOPO_CONFIGS = {}
TOPOS = {}
def _get_all_subclasses(BaseClass, dico):
for cls in BaseClass.__subclasses__():
if hasattr(cls, "NAME"):
dico[cls.NAME] = cls
_get_all_subclasses(cls, dico)
_get_all_subclasses(TopoConfig, TOPO_CONFIGS)
_get_all_subclasses(Topo, TOPOS)