Skip to content
Snippets Groups Projects

Pre-v8.0 merge to master

Merged Eric Gallimore requested to merge devel into master
32 files
+ 501
384
Compare changes
  • Side-by-side
  • Inline
Files
32
import importlib
import pkgutil
import os
import rospy
import sys
default_codecs = {
name.split(".")[-1].split("_")[0]: importlib.import_module(name)
for finder, name, ispkg in pkgutil.iter_modules(__path__, __name__ + ".")
if name.endswith("_packet_codec") and name != "acomms_codecs.base_packet_codec"
}
custom_codecs = {}
custom_packet_codec_paths = rospy.get_param("custom_packet_codec_paths", None)
if custom_packet_codec_paths is not None:
try:
for codec in (
custom_packet_codec_paths
if isinstance(custom_packet_codec_paths, list)
else [custom_packet_codec_paths]
):
path, module_name = os.path.split(codec)
sys.path.append(path)
codec = importlib.import_module(module_name, path)
custom_codecs = {
name.split(".")[-1].split("_")[0]: importlib.import_module(name)
for finder, name, ispkg in pkgutil.walk_packages(
__path__, __name__ + "."
)
if name.endswith("_packet_codec")
}
except OSError as exception:
rospy.logerr(
f"OSError occured when loading custom packet codecs, check provided path: {exception}"
)
raise OSError(
"OSError occured when loading custom packet codecs, check provided path"
) from exception
except ImportError as exception:
rospy.logerr(
f"ImportError occured when loading custom packet codecs: {exception}"
)
raise ImportError(
"ImportError occured when loading custom packet codecs"
) from exception
except Exception as exception:
rospy.logerr(
f"An unhandled error occured while loading custom packet codecs: {exception}"
)
raise Exception(
"An unhandled error occured while loading custom packet codecs"
) from exception
else:
rospy.loginfo("No custom packet codecs specified, using defaults")
packet_codecs = {**default_codecs, **custom_codecs}
Loading