Skip to content
Snippets Groups Projects
Commit fee3418e authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

ENH: added function that describes the diff objects

parent 1e37be5b
No related branches found
No related tags found
No related merge requests found
......@@ -532,8 +532,8 @@ COMPARED = ["name", "role", "datatype", "description", "importance"]
def compare_entities(old_entity, new_entity):
olddiff = {"properties": {}, "parents": {}}
newdiff = {"properties": {}, "parents": {}}
olddiff = {"properties": {}, "parents": []}
newdiff = {"properties": {}, "parents": []}
if old_entity is new_entity:
return (olddiff, newdiff)
......@@ -596,10 +596,41 @@ def compare_entities(old_entity, new_entity):
for parent in old_entity.parents:
if len([0 for p in new_entity.parents if p.name == parent.name]) == 0:
olddiff["parents"][parent.name] = {}
olddiff["parents"].append(parent.name)
for parent in new_entity.parents:
if len([0 for p in old_entity.parents if p.name == parent.name]) == 0:
newdiff["parents"][parent.name] = {}
newdiff["parents"].append(parent.name)
return (olddiff, newdiff)
def describe_diff(olddiff, newdiff, as_update=True):
description = "## Difference between the old and the new version of {}\n\n"
for attr in list(set(list(olddiff.keys)+list(newdiff.keys))):
if attr == "parents" or attr == "properties":
continue
description += "{} differs:\n".format(attr)
description += "old version: {}\n".format(
olddiff[attr] if attr in olddiff else "not set")
description += "new version: {}\n\n".format(
newdiff[attr] if attr in newdiff else "not set")
if len(olddiff["parents"]) > 0:
description += ("Parents that are only in the old version:\n"
+ ", ".join(olddiff["parents"]))
if len(newdiff["parents"]) > 0:
description += ("Parents that are only in the new version:\n"
+ ", ".join(olddiff["parents"]))
for prop in list(set(list(olddiff["properties"].keys)
+ list(newdiff["properties"].keys))):
description += "property {} differs:\n".format(prop)
description += "old version: {}\n".format(
olddiff["properties"][prop] if prop
in olddiff["properties"] else "has none")
description += "new version: {}\n\n".format(
newdiff["properties"][prop] if prop
in newdiff["properties"] else "has none")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment