Exemplo n.º 1
0
Arquivo: lib.py Projeto: 81819152/pype
def writes_version_sync():
    try:
        rootVersion = pype.get_version_from_path(nuke.root().name())
        padding = len(rootVersion)
        new_version = str("{" + ":0>{}".format(padding) + "}").format(
            int(rootVersion))
        log.info("new_version: {}".format(new_version))
    except Exception:
        return

    for each in nuke.allNodes():
        if each.Class() == 'Write':
            avalon_knob_data = get_avalon_knob_data(each)
            if avalon_knob_data['families'] not in ["render"]:
                log.info(avalon_knob_data['families'])
                continue
            try:
                node_file = each['file'].value()
                log.info("node_file: {}".format(node_file))

                node_version = pype.get_version_from_path(node_file)
                log.info("node_version: {}".format(node_version))

                node_new_file = node_file.replace(node_version, new_version)
                each['file'].setValue(node_new_file)
            except Exception as e:
                log.debug("Write node: `{}` has no version in path: {}".format(
                    each.name(), e))
Exemplo n.º 2
0
    def process(self, context):

        filename = os.path.basename(context.data.get('currentFile'))

        rootVersion = pype.get_version_from_path(filename)

        context.data['version'] = rootVersion

        self.log.info('Scene Version: %s' % context.data('version'))
Exemplo n.º 3
0
    def process(self, context):
        if "standalonepublisher" in context.data.get("host", []):
            return

        filename = os.path.basename(context.data.get('currentFile'))

        if '<shell>' in filename:
            return

        rootVersion = int(pype.get_version_from_path(filename))
        context.data['version'] = rootVersion
        self.log.info("{}".format(type(rootVersion)))
        self.log.info('Scene Version: %s' % context.data.get('version'))
Exemplo n.º 4
0
def writes_version_sync():
    ''' Callback synchronizing version of publishable write nodes
    '''
    # TODO: make it work with new write node group
    try:
        rootVersion = pype.get_version_from_path(nuke.root().name())
        padding = len(rootVersion)
        new_version = "v" + str("{" + ":0>{}".format(padding) + "}").format(
            int(rootVersion))
        log.debug("new_version: {}".format(new_version))
    except Exception:
        return

    for each in nuke.allNodes():
        if each.Class() == 'Write':
            avalon_knob_data = avalon.nuke.get_avalon_knob_data(
                each, ['avalon:', 'ak:'])

            try:
                if avalon_knob_data['families'] not in ["render"]:
                    log.debug(avalon_knob_data['families'])
                    continue

                node_file = each['file'].value()

                node_version = "v" + pype.get_version_from_path(node_file)
                log.debug("node_version: {}".format(node_version))

                node_new_file = node_file.replace(node_version, new_version)
                each['file'].setValue(node_new_file)
                if not os.path.isdir(os.path.dirname(node_new_file)):
                    log.warning("Path does not exist! I am creating it.")
                    os.makedirs(os.path.dirname(node_new_file), 0o766)
            except Exception as e:
                log.warning(
                    "Write node: `{}` has no version in path: {}".format(
                        each.name(), e))
Exemplo n.º 5
0
Arquivo: lib.py Projeto: 81819152/pype
def format_anatomy(data):
    from .templates import (get_anatomy)
    file = script_name()

    anatomy = get_anatomy()

    # TODO: perhaps should be in try!
    padding = anatomy.render.padding

    data.update({
        "hierarchy": pype.get_hierarchy(),
        "frame": "#" * padding,
        "version": pype.get_version_from_path(file)
    })

    # log.info("format_anatomy:anatomy: {}".format(anatomy))
    return anatomy.format(data)
Exemplo n.º 6
0
    def process(self, instance):

        grpn = instance[0]

        # add family to familiess
        instance.data["families"].insert(0, instance.data["family"])
        # make label nicer
        instance.data["label"] = "{0} ({1} nodes)".format(
            grpn.name(),
            len(instance) - 1)

        # Get frame range
        handle_start = instance.context.data["handleStart"]
        handle_end = instance.context.data["handleEnd"]
        first_frame = int(nuke.root()["first_frame"].getValue())
        last_frame = int(nuke.root()["last_frame"].getValue())

        # get version
        version = pype.get_version_from_path(nuke.root().name())
        instance.data['version'] = version

        # Add version data to instance
        version_data = {
            "handles": handle_start,
            "handleStart": handle_start,
            "handleEnd": handle_end,
            "frameStart": first_frame + handle_start,
            "frameEnd": last_frame - handle_end,
            "colorspace": nuke.root().knob('workingSpaceLUT').value(),
            "version": int(version),
            "families": [instance.data["family"]] + instance.data["families"],
            "subset": instance.data["subset"],
            "fps": instance.context.data["fps"]
        }

        instance.data.update({
            "versionData": version_data,
            "frameStart": first_frame,
            "frameEnd": last_frame
        })
        self.log.info("Gizmo content collected: `{}`".format(instance[:]))
        self.log.info("Gizmo instance collected: `{}`".format(instance))
Exemplo n.º 7
0
def format_anatomy(data):
    ''' Helping function for formating of anatomy paths

    Arguments:
        data (dict): dictionary with attributes used for formating

    Return:
        path (str)
    '''
    # TODO: perhaps should be nonPublic

    anatomy = get_anatomy()
    log.debug("__ anatomy.templates: {}".format(anatomy.templates))

    try:
        padding = int(anatomy.templates['render']['padding'])
    except KeyError as e:
        log.error("`padding` key is not in `render` "
                  "Anatomy template. Please, add it there and restart "
                  "the pipeline (padding: \"4\"): `{}`".format(e))

    version = data.get("version", None)
    if not version:
        file = script_name()
        data["version"] = pype.get_version_from_path(file)
    project_document = pype.get_project()
    data.update({
        "root": api.Session["AVALON_PROJECTS"],
        "subset": data["avalon"]["subset"],
        "asset": data["avalon"]["asset"],
        "task": api.Session["AVALON_TASK"].lower(),
        "family": data["avalon"]["family"],
        "project": {
            "name": project_document["name"],
            "code": project_document["data"].get("code", '')
        },
        "representation": data["nuke_dataflow_writes"]["file_type"],
        "app": data["application"]["application_dir"],
        "hierarchy": pype.get_hierarchy(),
        "frame": "#" * padding,
    })
    return anatomy.format(data)
Exemplo n.º 8
0
    def process(self, context):
        root = nuke.root()

        knob_data = get_avalon_knob_data(root)

        add_publish_knob(root)

        family = "workfile"
        # creating instances per write node
        file_path = context.data["currentFile"]
        staging_dir = os.path.dirname(file_path)
        base_name = os.path.basename(file_path)
        subset = "{0}_{1}".format(os.getenv("AVALON_TASK", None), family)

        # get version string
        version = pype.get_version_from_path(base_name)

        # Get frame range
        first_frame = int(root["first_frame"].getValue())
        last_frame = int(root["last_frame"].getValue())

        handle_start = int(knob_data.get("handleStart", 0))
        handle_end = int(knob_data.get("handleEnd", 0))

        # Get format
        format = root['format'].value()
        resolution_width = format.width()
        resolution_height = format.height()
        pixel_aspect = format.pixelAspect()

        # Create instance
        instance = context.create_instance(subset)
        instance.add(root)

        script_data = {
            "asset": os.getenv("AVALON_ASSET", None),
            "version": version,
            "frameStart": first_frame + handle_start,
            "frameEnd": last_frame - handle_end,
            "resolutionWidth": resolution_width,
            "resolutionHeight": resolution_height,
            "pixelAspect": pixel_aspect,

            # backward compatibility
            "handles": handle_start,

            "handleStart": handle_start,
            "handleEnd": handle_end,
            "step": 1,
            "fps": root['fps'].value(),
        }
        context.data.update(script_data)

        # creating instance data
        instance.data.update({
            "subset": subset,
            "label": base_name,
            "name": base_name,
            "publish": root.knob('publish').value(),
            "family": family,
            "families": [family],
            "representations": list()
        })

        # adding basic script data
        instance.data.update(script_data)

        # creating representation
        representation = {
            'name': 'nk',
            'ext': 'nk',
            'files': base_name,
            "stagingDir": staging_dir,
        }

        instance.data["representations"].append(representation)

        self.log.info('Publishing script version')
        context.data["instances"].append(instance)
Exemplo n.º 9
0
    def process(self, context):
        for instance in context.data["instances"]:

            if not instance.data["publish"]:
                continue

            node = instance[0]

            if node.Class() != "Write":
                continue

            self.log.debug("checking instance: {}".format(instance))

            # Determine defined file type
            ext = node["file_type"].value()

            # Determine output type
            output_type = "img"
            if ext == "mov":
                output_type = "mov"

            # Get frame range
            first_frame = int(nuke.root()["first_frame"].getValue())
            last_frame = int(nuke.root()["last_frame"].getValue())

            if node["use_limit"].getValue():
                first_frame = int(node["first"].getValue())
                last_frame = int(node["last"].getValue())

            # get path
            path = nuke.filename(node)
            output_dir = os.path.dirname(path)
            self.log.debug('output dir: {}'.format(output_dir))

            # get version
            version = pype.get_version_from_path(path)
            instance.data['version'] = version
            self.log.debug('Write Version: %s' % instance.data('version'))

            # create label
            name = node.name()
            # Include start and end render frame in label
            label = "{0} ({1}-{2})".format(name, int(first_frame),
                                           int(last_frame))

            # preredered frames
            # collect frames by try
            # collect families in next file
            if "files" not in instance.data:
                instance.data["files"] = list()
            try:
                collected_frames = os.listdir(output_dir)
                self.log.debug("collected_frames: {}".format(label))
                instance.data["files"].append(collected_frames)

            except Exception:
                self.log.debug("couldn't collect frames: {}".format(label))

            instance.data.update({
                "path": path,
                "outputDir": output_dir,
                "ext": ext,
                "label": label,
                "startFrame": first_frame,
                "endFrame": last_frame,
                "outputType": output_type,
                "colorspace": node["colorspace"].value(),
            })

            self.log.debug("instance.data: {}".format(instance.data))

        self.log.debug("context: {}".format(context))
Exemplo n.º 10
0
    def process(self, context):

        project = context.data('activeProject')
        path = project.path()
        context.data["version"] = int(pype.get_version_from_path(path))
        self.log.info("version: {}".format(context.data["version"]))
Exemplo n.º 11
0
    def process(self, instance):

        node = None
        for x in instance:
            if x.Class() == "Write":
                node = x

        if node is None:
            return

        self.log.debug("checking instance: {}".format(instance))

        # Determine defined file type
        ext = node["file_type"].value()

        # Determine output type
        output_type = "img"
        if ext == "mov":
            output_type = "mov"

        # Get frame range
        handles = instance.context.data['handles']
        handle_start = instance.context.data["handleStart"]
        handle_end = instance.context.data["handleEnd"]
        first_frame = int(nuke.root()["first_frame"].getValue())
        last_frame = int(nuke.root()["last_frame"].getValue())

        if node["use_limit"].getValue():
            handles = 0
            first_frame = int(node["first"].getValue())
            last_frame = int(node["last"].getValue())

        # get path
        path = nuke.filename(node)
        output_dir = os.path.dirname(path)
        self.log.debug('output dir: {}'.format(output_dir))

        # get version
        version = pype.get_version_from_path(nuke.root().name())
        instance.data['version'] = version
        self.log.debug('Write Version: %s' % instance.data('version'))

        # create label
        name = node.name()
        # Include start and end render frame in label
        label = "{0} ({1}-{2})".format(name, int(first_frame), int(last_frame))

        if 'render' in instance.data['families']:
            if "representations" not in instance.data:
                instance.data["representations"] = list()

                representation = {
                    'name': ext,
                    'ext': ext,
                    "stagingDir": output_dir,
                    "anatomy_template": "render"
                }

            try:
                collected_frames = os.listdir(output_dir)
                if collected_frames:
                    representation['frameStart'] = "%0{}d".format(
                        len(str(last_frame))) % first_frame
                representation['files'] = collected_frames
                instance.data["representations"].append(representation)
            except Exception:
                instance.data["representations"].append(representation)
                self.log.debug("couldn't collect frames: {}".format(label))

        # Add version data to instance
        version_data = {
            "handles": handle_start,
            "handleStart": handle_start,
            "handleEnd": handle_end,
            "frameStart": first_frame + handle_start,
            "frameEnd": last_frame - handle_end,
            "version": int(version),
            "colorspace": node["colorspace"].value(),
            "families": [instance.data["family"]],
            "subset": instance.data["subset"],
            "fps": instance.context.data["fps"]
        }

        group_node = [x for x in instance if x.Class() == "Group"][0]
        deadlineChunkSize = 1
        if "deadlineChunkSize" in group_node.knobs():
            deadlineChunkSize = group_node["deadlineChunkSize"].value()

        deadlinePriority = 50
        if "deadlinePriority" in group_node.knobs():
            deadlinePriority = group_node["deadlinePriority"].value()

        instance.data.update({
            "versionData": version_data,
            "path": path,
            "outputDir": output_dir,
            "ext": ext,
            "label": label,
            "handles": handles,
            "frameStart": first_frame,
            "frameEnd": last_frame,
            "outputType": output_type,
            "colorspace": node["colorspace"].value(),
            "deadlineChunkSize": deadlineChunkSize,
            "deadlinePriority": deadlinePriority
        })

        self.log.debug("instance.data: {}".format(instance.data))
Exemplo n.º 12
0
    def process(self, context):
        root = nuke.root()

        current_file = os.path.normpath(nuke.root().name())

        knob_data = anlib.get_avalon_knob_data(root)

        anlib.add_publish_knob(root)

        family = "workfile"
        task = os.getenv("AVALON_TASK", None)
        # creating instances per write node
        staging_dir = os.path.dirname(current_file)
        base_name = os.path.basename(current_file)
        subset = family + task.capitalize()

        # Get frame range
        first_frame = int(root["first_frame"].getValue())
        last_frame = int(root["last_frame"].getValue())

        handle_start = int(knob_data.get("handleStart", 0))
        handle_end = int(knob_data.get("handleEnd", 0))

        # Get format
        format = root['format'].value()
        resolution_width = format.width()
        resolution_height = format.height()
        pixel_aspect = format.pixelAspect()

        # Create instance
        instance = context.create_instance(subset)
        instance.add(root)

        script_data = {
            "asset": os.getenv("AVALON_ASSET", None),
            "frameStart": first_frame + handle_start,
            "frameEnd": last_frame - handle_end,
            "resolutionWidth": resolution_width,
            "resolutionHeight": resolution_height,
            "pixelAspect": pixel_aspect,

            # backward compatibility
            "handles": handle_start,
            "handleStart": handle_start,
            "handleEnd": handle_end,
            "step": 1,
            "fps": root['fps'].value(),
            "currentFile": current_file,
            "version": int(pype.get_version_from_path(current_file)),
            "host": pyblish.api.current_host(),
            "hostVersion": nuke.NUKE_VERSION_STRING
        }
        context.data.update(script_data)

        # creating instance data
        instance.data.update({
            "subset": subset,
            "label": base_name,
            "name": base_name,
            "publish": root.knob('publish').value(),
            "family": family,
            "families": [family],
            "representations": list()
        })

        # adding basic script data
        instance.data.update(script_data)

        # creating representation
        representation = {
            'name': 'nk',
            'ext': 'nk',
            'files': base_name,
            "stagingDir": staging_dir,
        }

        instance.data["representations"].append(representation)

        self.log.info('Publishing script version')

        # create instances in context data if not are created yet
        if not context.data.get("instances"):
            context.data["instances"] = list()

        context.data["instances"].append(instance)