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.


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")["dirname"] =["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 =["dirname"]
        for target in pyblish.api.registered_targets():
            dstdir = os.path.join(home, target)

            except OSError:
                pass  # Dir already exists

  "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))
      "Copying %s -> %s" % (src, dst))
                shutil.copy(src, dst)


# Comment these out to simply not integrate anywhere

if __name__ == '__main__':
    import pyblish.util
    context = pyblish.util.publish()

    # Report
    for result in["results"]:
        print("%s" % result["plugin"])
        for record in result["records"]:
            print("\t %s" % record.msg)


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?


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.