Skip to content

Commit

Permalink
Update set_metadata logic to clear out old metadata before setting ne…
Browse files Browse the repository at this point in the history
…w one
  • Loading branch information
kumar-sanjeeev committed Jan 4, 2025
1 parent 7f6a76d commit 3236da0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
10 changes: 10 additions & 0 deletions pyrobosim/pyrobosim/core/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ def add_metadata(cls, filename):

cls.metadata.add(filename)

@classmethod
def clearout_metadata(cls):
"""
Clear out old location metadata.
"""
if not hasattr(cls, "metadata"):
cls.metadata = EntityMetadata()
cls.metadata.data = {}
cls.metadata.sources = []

def __init__(
self,
name=None,
Expand Down
10 changes: 10 additions & 0 deletions pyrobosim/pyrobosim/core/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ def add_metadata(cls, filename):

cls.metadata.add(filename)

@classmethod
def clearout_metadata(cls):
"""
Clear out old object metadata.
"""
if not hasattr(cls, "metadata"):
cls.metadata = EntityMetadata()
cls.metadata.data = {}
cls.metadata.sources = []

def __init__(
self,
name=None,
Expand Down
14 changes: 4 additions & 10 deletions pyrobosim/pyrobosim/core/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,11 @@ def set_metadata(self, locations=None, objects=None):
:param objects: Path(s) to object metadata YAML file(s).
:type objects: str | list[str] | None
"""
if isinstance(locations, list):
for location in locations:
Location.add_metadata(location)
elif isinstance(locations, str):
Location.add_metadata(locations)
# Clear out old metadata
Location.clearout_metadata()
Object.clearout_metadata()

if isinstance(objects, list):
for object in objects:
Object.add_metadata(object)
elif isinstance(objects, str):
Object.add_metadata(objects)
self.add_metadata(locations, objects)

def add_metadata(self, locations=None, objects=None):
"""
Expand Down

0 comments on commit 3236da0

Please sign in to comment.