You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.5 KiB

10 months ago
  1. # flake8: noqaq
  2. import inspect
  3. import re
  4. import importlib
  5. import warnings
  6. from collections import OrderedDict
  7. from functools import lru_cache
  8. from html import escape as html_escape
  9. # String that separates a name from its unique ID
  10. _UNIQUE_SEPARATOR = "_"
  11. _IDENTITY_LENGTH = 8
  12. _IDENTITY_TABLE = {}
  13. # If a property ends with this key, it is a pseudo-property which exists to
  14. # hold the data dependencies of another property value
  15. _DATA_DEPENDENCY_KEY_SUFFIX = "_PyConfDataDependencies"
  16. _FLOW_GRAPH_NODE_COLOUR = "aliceblue"
  17. _FLOW_GRAPH_INPUT_COLOUR = "deepskyblue1"
  18. _FLOW_GRAPH_OUTPUT_COLOUR = "coral1"
  19. def unique_name_ext_re():
  20. return "(?:%s[1234567890abcdef]{%s})?" % (_UNIQUE_SEPARATOR, _IDENTITY_LENGTH)
  21. def findRootObjByName(rootFile, name):
  22. """
  23. Finds the object with given name in the given root file,
  24. where name is a regular expression or a set of them separated by '/' in case directories are used
  25. """
  26. curObj = rootFile
  27. for n in name.split("/"):
  28. matches = [
  29. k.GetName() for k in curObj.GetListOfKeys() if re.fullmatch(n, k.GetName())
  30. ]
  31. if len(matches) > 1:
  32. raise Exception(
  33. "Collision of names in Root : found several objects with name matching %s inside %s : %s"
  34. % (n, curObj.GetName(), matches)
  35. )
  36. if len(matches) == 0:
  37. raise Exception(
  38. "Failed to find object with name %s inside %s" % (n, curObj.GetName())
  39. )
  40. curObj = curObj.Get(matches[0])
  41. return curObj