tamaki.mes.backup.compare.compareEntityLists
Description
Compares two dictionaries of entity lists and identifies removed, added, and changed entities for each
entity type. Both inputs are first passed through flattenEntities so nested
structures are lifted into their own lists. Entity types present on only one side are reported as
added or removed; entity types present on both sides are compared entity-by-entity with
genericCompareEntities.
Syntax
tamaki.mes.backup.compare.compareEntityLists(oldEntityLists, newEntityLists)
Parameters
| Parameter | Type | Nullable | Description |
|---|---|---|---|
oldEntityLists | Dict | False | A mapping of entity type to a list of entity dictionaries, representing the old configuration state. |
newEntityLists | Dict | False | A mapping of entity type to a list of entity dictionaries, representing the new configuration state. |
Returns
A tuple (removedEntityTypes, addedEntityTypes, updatedEntityTypes):
| Element | Type | Description |
|---|---|---|
removedEntityTypes | List | ResultRow instances for entity types present only in the old state (changeType entity type remove). |
addedEntityTypes | List | ResultRow instances for entity types present only in the new state (changeType entity type add). |
updatedEntityTypes | Dict | Keyed by entity type present in both states; each value is a dict with removedEntities, addedEntities, and updatedEntities lists of ResultRow for that type. |
Code Examples
# Backup-compare view: compare an uploaded backup (or the live database) against another backup
if self.view.custom.compareAgainstDatabase:
backupBytes = system.mes.util.backup()
oldJsonData = tamaki.mes.backup.compare.extractJsonFromBytes(backupBytes)
else:
oldJsonData = self.view.custom.oldJsonData
newJsonData = self.view.custom.newJsonData
# Round-trip through JSON to get plain Python dicts/lists
newJsonData = system.util.jsonDecode(system.util.jsonEncode(newJsonData))
oldJsonData = system.util.jsonDecode(system.util.jsonEncode(oldJsonData))
removed, added, updated = tamaki.mes.backup.compare.compareEntityLists(oldJsonData, newJsonData)
self.view.custom.resultDatasets = tamaki.mes.backup.compare.resultsToDataSets(removed, added, updated)