#!/usr/bin/env python3 """Check that the warehouse world resolves all of its bundled model assets.""" from pathlib import Path from xml.etree import ElementTree as ET ROOT = Path(__file__).resolve().parents[1] MODELS = ROOT / "models" ERRORS = [] def inside(path, directory): try: path.resolve().relative_to(directory.resolve()) return True except ValueError: return False def check_uri(uri, source): if not uri.startswith("model://"): ERRORS.append(f"{source}: external asset URI {uri}") return relative = uri[len("model://"):] path = MODELS / relative if not relative or not inside(path, MODELS): ERRORS.append(f"{source}: model URI escapes this package: {uri}") return if not path.exists(): ERRORS.append(f"{source}: missing {uri}") def check_file(path, candidates, source, model_dir): if not any(inside(candidate, model_dir) and candidate.is_file() for candidate in candidates): ERRORS.append(f"{source}: missing or external asset {path}") def main(): world = ET.parse(ROOT / "worlds" / "two_floor_elevator.world").getroot() world_uris = world.findall(".//uri") world_uris += world.findall(".//actor/skin/filename") world_uris += world.findall(".//actor/animation/filename") used_names = set() for element in world_uris: uri = (element.text or "").strip() check_uri(uri, "world") if uri.startswith("model://"): used_names.add(uri[len("model://"):].split("/", 1)[0]) # The actor mesh is visual only unless its locally built plugin enables # Gazebo's bone collisions. Check the world-to-library contract here. actor_plugin = "libtwo_floor_elevator_walking_actor_collision_plugin.so" for actor in world.findall(".//actor"): plugin = actor.find("plugin") bones = set() if plugin is None else { (item.text or "").strip() for item in plugin.findall("collision") } if plugin is None or plugin.get("filename") != actor_plugin: ERRORS.append(f"{actor.get('name')}: missing local collision plugin") if not {"LeftLeg_LeftFoot_collision", "RightLeg_RightFoot_collision"} <= bones: ERRORS.append(f"{actor.get('name')}: missing lower-leg collision scales") for name in used_names: model_dir = MODELS / name for filename in ("model.config", "model.sdf"): if not (model_dir / filename).is_file(): ERRORS.append(f"{name}: missing {filename}") config = model_dir / "model.config" if config.is_file(): for sdf_path in ET.parse(config).getroot().findall(".//sdf"): candidate = model_dir / (sdf_path.text or "").strip() if not inside(candidate, model_dir) or not candidate.is_file(): ERRORS.append(f"{config}: missing or external SDF {sdf_path.text}") for model_dir in MODELS.iterdir(): if model_dir.is_symlink(): ERRORS.append(f"external symlink: {model_dir}") if not model_dir.is_dir(): continue for sdf in model_dir.glob("*.sdf"): for element in ET.parse(sdf).getroot().findall(".//uri"): check_uri((element.text or "").strip(), sdf) for mesh in MODELS.rglob("*"): if mesh.is_symlink(): ERRORS.append(f"external symlink: {mesh}") if not mesh.is_file(): continue model_dir = mesh.parent.parent if mesh.suffix.lower() == ".dae": dae = ET.parse(mesh).getroot() for image in dae.findall(".//{*}library_images/{*}image"): element = image.find("{*}init_from") if element is None or not element.text: continue texture = element.text.strip() check_file(texture, (mesh.parent / texture, model_dir / "materials" / "textures" / texture, model_dir / texture), mesh, model_dir) elif mesh.suffix.lower() == ".obj": for line in mesh.read_text(errors="replace").splitlines(): if line.startswith("mtllib "): library = line.split(None, 1)[1].strip() check_file(library, (mesh.parent / library,), mesh, model_dir) elif mesh.suffix.lower() == ".mtl": for line in mesh.read_text(errors="replace").splitlines(): if line.startswith(("map_Kd ", "map_Ka ", "map_Bump ", "bump ")): texture = line.split(None, 1)[1].strip() check_file(texture, (mesh.parent / texture, model_dir / "materials" / "textures" / texture), mesh, model_dir) package_xml = (ROOT / "package.xml").read_text() if "factory_ss_demo" in package_xml: ERRORS.append("package.xml still depends on factory_ss_demo") package = ET.parse(ROOT / "package.xml").getroot() gazebo_export = package.find("export/gazebo_ros") if gazebo_export is None or gazebo_export.get("gazebo_model_path") != "${prefix}/models": ERRORS.append("package.xml does not export the bundled Gazebo model path") cmake = (ROOT / "CMakeLists.txt").read_text() if "install(DIRECTORY action config docs launch licenses maps models" not in cmake: ERRORS.append("CMakeLists.txt does not install the models directory") if "add_library(two_floor_elevator_walking_actor_collision_plugin SHARED" not in cmake: ERRORS.append("CMakeLists.txt does not build the actor collision plugin") if not (ROOT / "src" / "walking_actor_collision_plugin.cpp").is_file(): ERRORS.append("missing local actor collision plugin source") if "add_library(two_floor_elevator_gazebo_plugin SHARED" not in cmake: ERRORS.append("CMakeLists.txt does not build the elevator plugin") if not (ROOT / "src" / "elevator_gazebo_plugin.cpp").is_file(): ERRORS.append("missing local elevator plugin source") for error in ERRORS: print("ERROR:", error) if ERRORS: raise SystemExit(1) print(f"PASS: {len(used_names)} bundled model directories and all mesh textures resolve locally") if __name__ == "__main__": main()