Newer
Older
Import / projects / Gameloft / bne_lib / build / scripts / CheckGameDBForDeletions.py
#!/usr/bin/python

#
# Does a diff between two gamedb.json files to check for any critical deletions
#
# Example usage:
#
#       ./CheckGameDBForDeletions.py original-gamedb.json new-gamedb.json

import sys, json, os

if len(sys.argv) != 3:
  print "ERROR: GameDB deletion validation FAILURE: Bad number of arguments. "
  sys.exit(1)

print "LOG: GameDB deletion validation INFO: old gameDB file: " + sys.argv[1]
print "LOG: GameDB deletion validation INFO: new gameDB file: " + sys.argv[2]

oldData = json.load(open(sys.argv[1], 'rb')) if os.path.isfile(sys.argv[1]) else {}
newData = json.load(open(sys.argv[2], 'rb')) if os.path.isfile(sys.argv[2]) else {}

print "LOG: GameDB deletion validation INFO: opened gameDB files"

# These are the GameDB tables where items of these types could be referenced in a player profile and are therefore critical.
# If this is not correct, please adjust this list accordingly. (BuildingLevel and CharacterUnlock I'm not sure about)
tables = [
  "Achievement",
  "BuildingLevel",
  "BuildingType",
  "CharacterType",
  "CharacterUnlock",
  "CraftedItemSlots",
  "DLCSettings",
  "DebrisType",
  "DefaultProfile",
  "DropDescription",
  "EffectType",
  "Experience",
  "GachaRewardSettings",
  "GachaSettings",
  "GameFlowManager",
  "GameFlowStep",
  "GameSettings",
  "InitialLoadSettings",
  "InventoryItem",
  "LevelReward",
  "LocalisedString",
  "MiniGame",
  "PushNotificationSettings",
  "Quest",
  "ResourceType",
  "RewardEvent",
  "SimulationSettings",
  "TierReward",
  "TycoonSettings",
  "WeaponType"
]

criticalMissingData = 0

for tab in tables:
  if not tab in oldData:
    print("WARNING: GameDB deletion validation WARNING: new table added to GameDB: " + tab)
    continue
  if not tab in newData:
    print("ERROR: GameDB deletion validation FAILURE: Missing table in new GameDB: " + tab)
    criticalMissingData = criticalMissingData + 1
    continue
  oldArr = oldData[tab]
  newArr = newData[tab]
  for item in oldArr:
    uid = item["uid"]
    found = False
    for newItem in newArr:
      if uid == newItem["uid"]:
        found = True
        break
    if not found:
      # checking if the uid is in the substitution table or not
      foundReplacement = False
      replacementObj = ""
      if "AssetMapper" in newData:
        for mapper in newData["AssetMapper"]:
          if "replacements" in mapper:
            for replacement in mapper["replacements"]:
              if uid == replacement["key"]:
                foundReplacement = True
                replacementObj = replacement["obj"]
                print("LOG: GameDB deletion validation INFO: Found potential replacement for deleted object: " + uid + " replacement: " + replacementObj)
                break
      # now checking if the replacement is in the new data or not
      if foundReplacement:
        for newItem in newArr:
          if replacementObj == newItem["uid"]:
            found = True
            break
        if not found:
          print("LOG: GameDB deletion validation INFO: Replacement for deleted object was not found: " + uid + " replacement: " + replacementObj)
        else:
          print("LOG: GameDB deletion validation INFO: Replacement for deleted object was found: " + uid + " replacement: " + replacementObj)
    if not found:
      print("ERROR: GameDB deletion validation FAILURE: Deletion from table: " + tab + " uid: " + uid)
      criticalMissingData = criticalMissingData + 1
 
if criticalMissingData != 0:
  print("ERROR: GameDB deletion validation FAILURE: Found " + str(criticalMissingData) + " critical items missing in the new GameDB.")
  sys.exit(1)
else:
  print("LOG: GameDB deletion validation PASSED: No critical data missing in new GameDB.")
  sys.exit(0)