Created
July 12, 2019 08:44
-
-
Save BigRoy/1235a2107c036ef9f37a3290bfe21b15 to your computer and use it in GitHub Desktop.
A Deadline job script that will trigger a Pyblish publish with only the instances by name defined in env. var. PYBLISH_ACTIVE_INSTANCES
This file contains hidden or 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
try: | |
import logging | |
import pyblish.api | |
import pyblish.util | |
except ImportError as exc: | |
# Ensure Deadline fails by output an error that contains "Fatal Error:" | |
raise ImportError("Fatal Error: %s" % exc) | |
handler = logging.basicConfig() | |
log = logging.getLogger("Publish active instances") | |
log.setLevel(logging.DEBUG) | |
class CollectInstancesActiveState(pyblish.api.ContextPlugin): | |
"""Collect instance active state from PYBLISH_ACTIVE_INSTANCES. | |
This will read the PYBLISH_ACTIVE_INSTANCES environment variable and split | |
the string by comma. Only those instances that match by name with the | |
entries in that list will remain active for publishing, the rest will | |
be deactivated. | |
""" | |
order = pyblish.api.CollectorOrder + 0.499 | |
def process(self, context): | |
active = os.environ.get("PYBLISH_ACTIVE_INSTANCES") | |
if not active: | |
raise RuntimeError("No registered active instances to process" | |
" in PYBLISH_ACTIVE_INSTANCES.") | |
# Make set of valid entries, split by comma | |
active = set(name.strip() for name in active.split(",") if | |
name.strip()) | |
for instance in context: | |
# Set the state per instance | |
state = instance.name in active | |
instance.data["active"] = state | |
instance.data["publish"] = state | |
def publish(): | |
# First register the plug-in that ensures only the instances defined in | |
# PYBLISH_ACTIVE_INSTANCES remain enabled directly after collection. | |
pyblish.api.register_plugin(CollectInstancesActiveState) | |
context = pyblish.util.publish() | |
# Cleanup afterwards, just to be sure. This is not so important if this | |
# runs in a standalone process that dies after publishing anyway. | |
pyblish.api.deregister_plugin(CollectInstancesActiveState) | |
if not context: | |
log.warning("Fatal Error: Nothing collected.") | |
sys.exit(1) | |
# Collect errors, {plugin name: error} | |
error_results = [r for r in context.data["results"] if r["error"]] | |
if error_results: | |
log.error("Fatal Error: Errors occurred ...") | |
error_format = "Failed {plugin.__name__}: {error} -- {error.traceback}" | |
for result in error_results: | |
log.error(error_format.format(**result)) | |
sys.exit(2) | |
if __name__ == "__main__": | |
publish() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment