allow _get_packages_for_state() to reuse single commands from other packages
for example:
if state == AtRemote.at_remote:
available = {TextualDevice.cmds: ['moler.cmd.at', 'moler.cmd.unix.ctrl_c']}
@@ -464,8 +464,21 @@ class TextualDevice(AbstractDevice):
def _load_cmds_from_package(self, package_name):
available_cmds = dict()
basic_module = importlib.import_module(package_name)
- for importer, modname, is_pkg in pkgutil.iter_modules(basic_module.__path__):
+ try:
+ mod_path = basic_module.__path__
+ for importer, modname, is_pkg in pkgutil.iter_modules(mod_path):
module_name = "{}.{}".format(package_name, modname)
+ module_available_cmds = self._load_cmds_from_module(module_name)
+ available_cmds.update(module_available_cmds)
+ except AttributeError:
+ module_available_cmds = self._load_cmds_from_module(module_name=package_name)
+ available_cmds.update(module_available_cmds)
+
+ return available_cmds
+
+ def _load_cmds_from_module(self, module_name):
+ available_cmds = dict()
+
module = importlib.import_module(module_name)
for (cmd_class_name, cmd_module_name) in inspect.getmembers(module, inspect.isclass):
if cmd_module_name.__module__ == module_name:
