Skip to content

Commit

Permalink
fixup! scripts: add merge and diff
Browse files Browse the repository at this point in the history
  • Loading branch information
flomonster committed Jun 1, 2023
1 parent 28a323a commit ceb0ee2
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion scripts/diff-infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ def create_payload(obj_type: str, value: Dict) -> Dict:
"railjson": value,
}

def as_sets(obj):
"""
Return a copy of the object but all inner lists are transform to sets.
"""
res = obj
if isinstance(obj, dict):
res = {k: as_sets(v) for (k, v) in res.items()}
elif isinstance(obj, list):
if obj and isinstance(obj[0], dict):
print(obj)
res = {as_sets(e) for e in obj}
return res


def diff(rjs_base: Dict, rjs_cur: Dict) -> List[Dict]:
"""
Expand All @@ -63,8 +76,10 @@ def diff(rjs_base: Dict, rjs_cur: Dict) -> List[Dict]:
continue
value_base = objects_base[obj_key]
value_cur = objects_cur[obj_key]
sets_base = as_sets(value_base)
sets_cur = as_sets(value_cur)
# Updated object
if value_cur != value_base:
if sets_base != sets_cur:
payload.append(del_payload(obj_type, obj_key))
payload.append(create_payload(obj_type, value_cur))
return payload
Expand Down

0 comments on commit ceb0ee2

Please sign in to comment.