Recursively process all MJCF/XML files in the given folder and its subfolders. Args: folder_path (str): Path to the folder containing MJCF/XML files Returns: list[ConversionResult]: List of conversion results
(folder_path)
| 15 | |
| 16 | |
| 17 | def process_folder(folder_path): |
| 18 | """ |
| 19 | Recursively process all MJCF/XML files in the given folder and its subfolders. |
| 20 | |
| 21 | Args: |
| 22 | folder_path (str): Path to the folder containing MJCF/XML files |
| 23 | |
| 24 | Returns: |
| 25 | list[ConversionResult]: List of conversion results |
| 26 | """ |
| 27 | results = [] |
| 28 | folder_path = Path(folder_path) |
| 29 | |
| 30 | xml_files = list(folder_path.rglob("*.xml")) + list(folder_path.rglob("*.mjcf")) |
| 31 | xml_files.sort() |
| 32 | |
| 33 | for input_file in xml_files: |
| 34 | result = ConversionResult(str(input_file), False) |
| 35 | |
| 36 | try: |
| 37 | output_file = input_file.with_suffix(".urdf") |
| 38 | result.output_file = str(output_file) |
| 39 | |
| 40 | output_file.parent.mkdir(parents=True, exist_ok=True) |
| 41 | |
| 42 | mjcf_to_urdf(str(input_file), str(output_file)) |
| 43 | |
| 44 | result.success = True |
| 45 | print(f"Successfully converted: {input_file}") |
| 46 | |
| 47 | except Exception as e: |
| 48 | result.error_msg = str(e) |
| 49 | print(f"Failed to convert {input_file}: {e!s}") |
| 50 | |
| 51 | results.append(result) |
| 52 | |
| 53 | return results |
| 54 | |
| 55 | |
| 56 | def generate_log(results, folder_path): |
no test coverage detected