-
-
Save mottosso/863e97d6f9d08a0d9eee to your computer and use it in GitHub Desktop.
CVEI Example 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""An example of how CVEI plug-ins can work together | |
..without stepping on each others toes. Logging messages | |
are used for annotation, they won't actually print anything. | |
Data is collected from `scene`, a representation of a Maya, | |
Nuke or Houdini scene as a list of nodes. | |
It's then extracted and integrated onto `disk`, which is | |
a representation of a file-system. | |
""" | |
import pyblish.api | |
disk = {} | |
scene = [ | |
{ | |
"name": "Bruce", | |
"family": "model", | |
"objectColor": "blue" | |
} | |
] | |
class MyCollector(pyblish.api.Collector): | |
def process(self, context): | |
self.log.info("Accessing external data..") | |
for item in scene: | |
self.log.info("Converting jargon..") | |
item["color"] = item.pop("objectColor") | |
context.create_instance(**item) | |
class MyValidator(pyblish.api.Validator): | |
families = ["model"] | |
def process(self, instance): | |
self.log.info("Validating, without external access..") | |
assert instance.data("color") == "blue", ( | |
"Color of %s should be blue" % instance) | |
class MyExtractor(pyblish.api.Extractor): | |
families = ["model"] | |
def process(self, instance): | |
import json | |
import base64 | |
self.log.info("Transforming software-specific data " | |
"into something compatible with files") | |
serialised = base64.b64encode( | |
json.dumps(instance.data()) | |
) | |
self.log.info("If this is the first extractor, make some room") | |
if "/tmp/xfv53" not in disk: | |
disk["/tmp/xfv53"] = {} | |
disk["/tmp/xfv53"][instance.data("name")] = serialised | |
instance.set_data("commitDir", disk["/tmp/xfv53"]) | |
class MyIntegrator(pyblish.api.Integrator): | |
families = ["model"] | |
def process(self, instance): | |
# Nothing commited means nothing to integrate | |
assert "commitDir" in instance.data(), ( | |
"No commit directory found for %s, aborting.." % instance) | |
# Move from temporary to permanent location | |
location = "/projects/hulk/assets/%s" % instance | |
self.log.info("Moving staging area to %s" % location) | |
disk[location] = instance.data("commitDir") | |
if __name__ == '__main__': | |
for plugin in (MyCollector, MyValidator, MyExtractor, MyIntegrator): | |
pyblish.api.register_plugin(plugin) | |
import pyblish.util | |
pyblish.util.publish() | |
assert "/projects/hulk/assets/Bruce" in disk | |
print("Success") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment