New Feature - Target

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.

1 Like

Well done @Lars_van_der_Bijl:)

Am I understanding this correct, that we should store different paths in the targets?

pyblish.plugin.register_target("K:/")
pyblish.plugin.register_target("L:/")

Could do, but they are more about conceptual targets, such as whether to publish studio-wide, or just for a particular show, or both.

Storing the absolute root of any integration paths might also work!

ahh, I see. Guessing eventually this will be in pyblish-qml, meaning that have an absolute path isn’t very user friendly.