Skip to content

Commit 66eedee

Browse files
committed
change to metadata
1 parent 67a93f0 commit 66eedee

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

scripts/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ These steps allow you to get the updated behaviors.xml, which should happen ever
77

88
```bash
99
# In moveitpro repo when your REST API is running, get the generated XML data
10-
# Save it to scripts/ directory in moveit_pro_example_ws workspace
11-
curl -X GET http://localhost:3200/behaviors/data > scripts/behaviors_raw.xml
10+
curl -X GET http://localhost:3200/behaviors/data > behaviors_raw.xml
1211
```
1312

1413
### enrich_behaviors_with_usage.py
1514

16-
Enhances `behaviors_raw.xml` with usage information (`<UsedIn>` elements) showing which Objectives use each behavior.
15+
Enhances `behaviors_raw.xml` with usage information (Metadata fields with `used_in` attribute) showing which Objectives use each behavior.
1716

1817
**Run this script in `moveit_pro_example_ws` workspace.**
1918

@@ -36,11 +35,12 @@ python3 scripts/enrich_behaviors_with_usage.py --xml scripts/behaviors_raw.xml -
3635
- Discovers all robot configs in the workspace
3736
- Extracts which Objectives use which behaviors by parsing Objective XML files
3837
- Preserves all existing XML data (ports, metadata, etc.)
39-
- Adds `<UsedIn>` elements to each behavior in the XML showing:
38+
- Adds `Metadata` elements with `used_in` attribute to each behavior's `MetadataFields` showing:
4039
- Which configs use the behavior
4140
- Which Objectives use the behavior
4241
- The file path of each Objective
4342
- The usage type (Action, Control, Decorator, SubTree)
43+
- The `used_in` attribute contains a JSON array of usage objects
4444
- Outputs enhanced XML file ready for conversion to JSON
4545

4646
#### Requirements
@@ -73,7 +73,7 @@ python scripts/update_behaviors_from_xml.py /path/to/behaviors_with_usage.xml
7373

7474
- Extracts port information (input, output, input/output) from XML Action and SubTree elements
7575
- Extracts metadata (subcategory, description, deprecated status)
76-
- Extracts `used_in` information from `<UsedIn>` elements (if present)
76+
- Extracts `used_in` information from `Metadata` elements with `used_in` attribute (if present)
7777
- Updates existing behaviors in JSON or adds new ones
7878
- Preserves existing data like links and other fields
7979
- Updates the export date

scripts/enrich_behaviors_with_usage.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
"""
33
Enhance behaviors.xml with usage information from Objectives.
44
5-
This script reads behaviors.xml (from REST API) and adds <UsedIn> elements
6-
showing which Objectives use each behavior.
5+
This script reads behaviors.xml (from REST API) and adds Metadata fields
6+
with used_in information showing which Objectives use each behavior.
77
88
Run this script in moveit_pro_example_ws workspace.
99
"""
1010

1111
import argparse
12+
import json
1213
import os
1314
import sys
1415
from pathlib import Path
@@ -328,26 +329,29 @@ def enhance_behaviors_xml(
328329
traceback.print_exc()
329330
continue
330331

331-
# Add UsedIn elements to each behavior element
332+
# Add used_in Metadata to each behavior element
332333
print("Adding usage information to XML...", file=sys.stderr)
333334
behaviors_with_usage = 0
334335

335336
for behavior_id, elem in behavior_elements.items():
336-
# Remove existing UsedIn elements if any
337-
for used_in in elem.findall(".//UsedIn"):
338-
elem.remove(used_in)
339-
340-
# Add new UsedIn elements
337+
# Remove existing used_in Metadata if any
338+
metadata_fields = elem.find(".//MetadataFields")
339+
if metadata_fields is not None:
340+
for metadata in metadata_fields.findall(".//Metadata[@used_in]"):
341+
metadata_fields.remove(metadata)
342+
else:
343+
# Create MetadataFields if it doesn't exist
344+
metadata_fields = ET.SubElement(elem, "MetadataFields")
345+
346+
# Add new used_in Metadata
341347
if behavior_id in all_objective_usages:
342348
usages = all_objective_usages[behavior_id]
343-
used_in_container = ET.SubElement(elem, "UsedIn")
344-
345-
for usage in usages:
346-
usage_elem = ET.SubElement(used_in_container, "Usage")
347-
usage_elem.set("config", usage["config"])
348-
usage_elem.set("objective_id", usage["objective_id"])
349-
usage_elem.set("objective_file", usage["objective_file"])
350-
usage_elem.set("usage_type", usage["usage_type"])
349+
# Serialize usages to JSON string
350+
used_in_json = json.dumps(usages, ensure_ascii=False)
351+
352+
# Add Metadata element with used_in attribute
353+
used_in_metadata = ET.SubElement(metadata_fields, "Metadata")
354+
used_in_metadata.set("used_in", used_in_json)
351355

352356
behaviors_with_usage += 1
353357

0 commit comments

Comments
 (0)