Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. """Example pseudocode to collect dependencies and publish them in Avalon database.
  2.  
  3. - Collect dependencies of what is included/used as representation at time of publish (example shows Maya implementation)
  4. - Store in database under version[data][dependencies]
  5. - Debug print dependencies for a representation (see psuedocode at end)
  6.  
  7. """
  8.  
  9. import maya.cmds as mc
  10. import avalon.api as api
  11.  
  12.  
  13. def collect_container_dependencies(nodes):
  14. """Collect loaded container dependencies from nodes
  15.  
  16. This will return any loaded Avalon container that
  17. contains at least one of the nodes. As such, the
  18. Avalon container is a dependency. Or in short,
  19. there are member nodes of that container.
  20.  
  21. Returns:
  22. list: Depending avalon containers
  23.  
  24. """
  25.  
  26. # Lookup by node ids
  27. lookup = frozenset(mc.ls(nodes, uuid=True))
  28.  
  29. dependencies = []
  30. host = api.registered_host()
  31. for container in host.ls():
  32. node = container["objectName"]
  33. members = mc.sets(node, query=True)
  34. members_uuid = mc.ls(members, uuid=True)
  35.  
  36. # If there's an intersection
  37. if not lookup.isdisjoint(members_uuid):
  38. dependencies.append(container)
  39.  
  40. return dependencies
  41.  
  42.  
  43. for x in collect_container_dependencies(mc.ls(sl=1)):
  44. # Print the dependent loaded representation for a current selection in Maya
  45. print x["representation"]
  46.  
  47.  
  48. # todo: now collect this information as we publish (collect_dependencies.py)
  49. # todo: publish list or dependendent representations into the database as version.data["dependencies"] (integrate.py)
  50.  
  51. # then after we've published representations we can print our dependencies for a representation
  52. def print_dependencies(representation, depth=0):
  53. """Psuedocode to print dependencies
  54.  
  55. Prints:
  56. 5ced48f4a33d24abab7fb467
  57. '-- 5c123e63c479bb328472cb4b
  58. '-- 59ede406bda2cb8f634a0bea
  59. '-- 54zfe406kio2ilofa34a0cad
  60. '-- 54zfe406kio2ilofa34a0cad
  61.  
  62. """
  63.  
  64. # Print current entry
  65. indent = 0
  66. if depth != 0:
  67. indent = (" " * depth) + "'--"
  68. print(indent + representation["_id"])
  69.  
  70. # Print dependencies
  71. dependencies = representation.get("dependencies", [])
  72. for dependency in dependencies:
  73. print_dependencies(dependency, depth + 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement