Hi all,
@Lars_van_der_Bijl recently implemented a new feature for you to give a whirl. It’s meant to facilitate redirecting the output of a publish to one or more locations, such as global to a studio, local to a project or person.
Example
Here is an example of integrating to two targets at once.
"""Publish to multiple targets"""
import os
import glob
import shutil
import pyblish.api
class Collect(pyblish.api.ContextPlugin):
"""Collect .exe files from cwd"""
order = pyblish.api.CollectorOrder
def process(self, context):
instance = context.create_instance("MyInstance")
instance.data["dirname"] = context.data["cwd"]
instance[:] = glob.glob("./*.exe")
class Integrate(pyblish.api.InstancePlugin):
"""Integrate to multiple targets"""
order = pyblish.api.IntegratorOrder
def process(self, instance):
home = os.path.expanduser("~")
srcdir = instance.data["dirname"]
for target in pyblish.api.registered_targets():
dstdir = os.path.join(home, target)
try:
os.makedirs(dstdir)
except OSError:
pass # Dir already exists
self.log.info("Integrating \"%s\" to \"%s\"" % (srcdir, dstdir))
for fname in instance:
src = os.path.join(srcdir, os.path.basename(fname))
dst = os.path.join(dstdir, os.path.basename(fname))
self.log.info("Copying %s -> %s" % (src, dst))
shutil.copy(src, dst)
pyblish.api.register_plugin(Collect)
pyblish.api.register_plugin(Integrate)
# Comment these out to simply not integrate anywhere
pyblish.plugin.register_target("studio")
pyblish.plugin.register_target("home")
if __name__ == '__main__':
import pyblish.util
context = pyblish.util.publish()
# Report
for result in context.data["results"]:
print("%s" % result["plugin"])
for record in result["records"]:
print("\t %s" % record.msg)
Discussion
Have a look at the GitHub issue for thought and motivation for this feature, along with some of the remaining questions, especially with regards to its graphical representation.