Deprecate.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from collections import deque
  2. import TestScripts.Parser
  3. # When deprecation is forced on some nodes
  4. # we ensure that a parent of a valid node is also valid
  5. def correctDeprecation(node):
  6. current = node.data["deprecated"]
  7. for c in node.children:
  8. if not correctDeprecation(c):
  9. current = False
  10. node.data["deprecated"] = current
  11. return(current)
  12. def deprecateRec(root,others,deprecated):
  13. if others:
  14. newOthers=others.copy()
  15. newOthers.popleft()
  16. if root.kind == TestScripts.Parser.TreeElem.TEST:
  17. if others[0].isdigit() and int(root.id) == int(others[0]):
  18. root.data["deprecated"]=False
  19. for c in root.children:
  20. deprecateRec(c,newOthers,False)
  21. else:
  22. root.data["deprecated"]=True
  23. for c in root.children:
  24. deprecateRec(c,others,deprecated)
  25. else:
  26. if root.data["class"] == others[0]:
  27. root.data["deprecated"]=False
  28. for c in root.children:
  29. deprecateRec(c,newOthers,False)
  30. else:
  31. root.data["deprecated"]=deprecated
  32. for c in root.children:
  33. deprecateRec(c,others,deprecated)
  34. def deprecate(root,others):
  35. if others:
  36. deprecateRec(root,deque(others),True)
  37. correctDeprecation(root)