Merge branch 'develop' into 3.0/feature/pype_refactor_start

This commit is contained in:
iLLiCiTiT 2020-06-01 18:37:34 +02:00
commit 939e408bb6
12 changed files with 420 additions and 3 deletions

19
.github/workflows/automate-projects.yml vendored Normal file
View file

@ -0,0 +1,19 @@
name: Automate Projects
on:
issues:
types: [opened, labeled]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
assign_one_project:
runs-on: ubuntu-latest
name: Assign to One Project
steps:
- name: Assign NEW bugs to triage
uses: srggrs/assign-one-project-github-action@1.2.0
if: contains(github.event.issue.labels.*.name, 'bug')
with:
project: 'https://github.com/pypeclub/pype/projects/2'
column_name: 'Needs triage'

39
pype/harmony/__init__.py Normal file
View file

@ -0,0 +1,39 @@
import os
from avalon import api, harmony
import pyblish.api
def install():
print("Installing Pype config...")
plugins_directory = os.path.join(
os.path.dirname(os.path.dirname(__file__)), "plugins", "harmony"
)
pyblish.api.register_plugin_path(
os.path.join(plugins_directory, "publish")
)
api.register_plugin_path(
api.Loader, os.path.join(plugins_directory, "load")
)
api.register_plugin_path(
api.Creator, os.path.join(plugins_directory, "create")
)
pyblish.api.register_callback(
"instanceToggled", on_pyblish_instance_toggled
)
def on_pyblish_instance_toggled(instance, old_value, new_value):
"""Toggle node enabling on instance toggles."""
func = """function func(args)
{
node.setEnable(args[0], args[1])
}
func
"""
harmony.send(
{"function": func, "args": [instance[0], new_value]}
)

View file

@ -22,7 +22,7 @@ class ExtractReview(pyblish.api.InstancePlugin):
label = "Extract Review"
order = pyblish.api.ExtractorOrder + 0.02
families = ["review"]
hosts = ["nuke", "maya", "shell", "nukestudio", "premiere"]
hosts = ["nuke", "maya", "shell", "nukestudio", "premiere", "harmony"]
# Supported extensions
image_exts = ["exr", "jpg", "jpeg", "png", "dpx"]

View file

@ -81,7 +81,8 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin):
"assembly",
"fbx",
"textures",
"action"
"action",
"harmony.template"
]
exclude_families = ["clip"]
db_representation_context_keys = [

View file

@ -0,0 +1,25 @@
from avalon import harmony
class CreateRender(harmony.Creator):
"""Composite node for publishing renders."""
name = "renderDefault"
label = "Render"
family = "render"
node_type = "WRITE"
def __init__(self, *args, **kwargs):
super(CreateRender, self).__init__(*args, **kwargs)
def setup_node(self, node):
func = """function func(args)
{
node.setTextAttr(args[0], "DRAWING_TYPE", 1, "PNG4");
node.setTextAttr(args[0], "DRAWING_NAME", 1, args[1]);
node.setTextAttr(args[0], "MOVIE_PATH", 1, args[1]);
}
func
"""
path = "{0}/{0}".format(node.split("/")[-1])
harmony.send({"function": func, "args": [node, path]})

View file

@ -0,0 +1,12 @@
from avalon import harmony
class CreateTemplate(harmony.Creator):
"""Composite node for publishing to templates."""
name = "templateDefault"
label = "Template"
family = "harmony.template"
def __init__(self, *args, **kwargs):
super(CreateTemplate, self).__init__(*args, **kwargs)

View file

@ -0,0 +1,48 @@
import tempfile
import zipfile
import os
import shutil
from avalon import api, harmony
class ImportTemplateLoader(api.Loader):
"""Import templates."""
families = ["harmony.template"]
representations = ["*"]
label = "Import Template"
def load(self, context, name=None, namespace=None, data=None):
temp_dir = tempfile.mkdtemp()
zip_file = api.get_representation_path(context["representation"])
template_path = os.path.join(temp_dir, "temp.tpl")
with zipfile.ZipFile(zip_file, "r") as zip_ref:
zip_ref.extractall(template_path)
func = """function func(args)
{
var template_path = args[0];
var drag_object = copyPaste.copyFromTemplate(
template_path, 0, 0, copyPaste.getCurrentCreateOptions()
);
copyPaste.pasteNewNodes(
drag_object, "", copyPaste.getCurrentPasteOptions()
);
}
func
"""
func = """function func(args)
{
var template_path = args[0];
var drag_object = copyPaste.pasteTemplateIntoGroup(
template_path, "Top", 1
);
}
func
"""
harmony.send({"function": func, "args": [template_path]})
shutil.rmtree(temp_dir)

View file

@ -0,0 +1,27 @@
import os
import pyblish.api
from avalon import harmony
class CollectCurrentFile(pyblish.api.ContextPlugin):
"""Inject the current working file into context"""
order = pyblish.api.CollectorOrder - 0.5
label = "Current File"
hosts = ["harmony"]
def process(self, context):
"""Inject the current working file"""
func = """function func()
{
return (
scene.currentProjectPath() + "/" +
scene.currentVersionName() + ".xstage"
);
}
func
"""
current_file = harmony.send({"function": func})["result"]
context.data["currentFile"] = os.path.normpath(current_file)

View file

@ -0,0 +1,56 @@
import json
import pyblish.api
from avalon import harmony
class CollectInstances(pyblish.api.ContextPlugin):
"""Gather instances by nodes metadata.
This collector takes into account assets that are associated with
a composite node and marked with a unique identifier;
Identifier:
id (str): "pyblish.avalon.instance"
"""
label = "Instances"
order = pyblish.api.CollectorOrder
hosts = ["harmony"]
families_mapping = {
"render": ["imagesequence", "review"],
"harmony.template": []
}
def process(self, context):
nodes = harmony.send(
{"function": "node.subNodes", "args": ["Top"]}
)["result"]
for node in nodes:
data = harmony.read(node)
# Skip non-tagged nodes.
if not data:
continue
# Skip containers.
if "container" in data["id"]:
continue
instance = context.create_instance(node.split("/")[-1])
instance.append(node)
instance.data.update(data)
instance.data["publish"] = harmony.send(
{"function": "node.getEnable", "args": [node]}
)["result"]
instance.data["families"] = self.families_mapping[data["family"]]
instance.data["families"].append("ftrack")
# Produce diagnostic message for any graphical
# user interface interested in visualising it.
self.log.info(
"Found: \"{0}\": \n{1}".format(
instance.data["name"], json.dumps(instance.data, indent=4)
)
)

View file

@ -0,0 +1,100 @@
import os
import tempfile
import pyblish.api
from avalon import harmony
import pype.lib
import clique
class ExtractRender(pyblish.api.InstancePlugin):
"""Produce a flattened image file from instance.
This plug-in only takes into account the nodes connected to the composite.
"""
label = "Extract Render"
order = pyblish.api.ExtractorOrder
hosts = ["harmony"]
families = ["render"]
def process(self, instance):
# Collect scene data.
func = """function func(write_node)
{
return [
about.getApplicationPath(),
scene.currentProjectPath(),
scene.currentScene(),
scene.getFrameRate(),
scene.getStartFrame(),
scene.getStopFrame()
]
}
func
"""
result = harmony.send(
{"function": func, "args": [instance[0]]}
)["result"]
application_path = result[0]
project_path = result[1]
scene_path = os.path.join(result[1], result[2] + ".xstage")
frame_rate = result[3]
frame_start = result[4]
frame_end = result[5]
# Set output path to temp folder.
path = tempfile.mkdtemp()
func = """function func(args)
{
node.setTextAttr(args[0], "DRAWING_NAME", 1, args[1]);
}
func
"""
result = harmony.send(
{
"function": func,
"args": [instance[0], path + "/" + instance.data["name"]]
}
)
harmony.save_scene()
# Execute rendering.
output = pype.lib._subprocess([application_path, "-batch", scene_path])
self.log.info(output)
# Collect rendered files.
files = os.listdir(path)
collections, remainder = clique.assemble(files, minimum_items=1)
assert not remainder, (
"There should not be a remainder for {0}: {1}".format(
instance[0], remainder
)
)
assert len(collections) == 1, (
"There should only be one image sequence in {}. Found: {}".format(
path, len(collections)
)
)
extension = os.path.splitext(list(collections[0])[0])[-1][1:]
representation = {
"name": extension,
"ext": extension,
"files": list(collections[0]),
"stagingDir": path,
"frameStart": frame_start,
"frameEnd": frame_end,
"fps": frame_rate,
"preview": True,
"tags": ["review"]
}
instance.data["representations"] = [representation]
self.log.info(frame_rate)
# Required for extract_review plugin (L222 onwards).
instance.data["frameStart"] = frame_start
instance.data["frameEnd"] = frame_end
instance.data["fps"] = frame_rate
self.log.info("Extracted {instance} to {path}".format(**locals()))

View file

@ -0,0 +1,90 @@
import os
import shutil
import pype.api
from avalon import harmony
class ExtractTemplate(pype.api.Extractor):
"""Extract the connected nodes to the composite instance."""
label = "Extract Template"
hosts = ["harmony"]
families = ["harmony.template"]
def process(self, instance):
staging_dir = self.staging_dir(instance)
self.log.info("Outputting template to %s" % staging_dir)
self.dependencies = []
self.get_dependencies(instance[0])
func = """function func(args)
{
var nodes = args[0];
selection.clearSelection();
for (var i = 0 ; i < nodes.length; i++)
{
selection.addNodeToSelection(nodes[i]);
}
}
func
"""
harmony.send({"function": func, "args": [self.dependencies]})
func = """function func(args)
{
copyPaste.createTemplateFromSelection(args[0], args[1]);
}
func
"""
harmony.send(
{
"function": func,
"args": ["{}.tpl".format(instance.name), staging_dir]
}
)
os.chdir(staging_dir)
shutil.make_archive(
"{}".format(instance.name),
"zip",
os.path.join(staging_dir, "{}.tpl".format(instance.name))
)
representation = {
"name": "tpl",
"ext": "zip",
"files": "{}.zip".format(instance.name),
"stagingDir": staging_dir,
}
instance.data["representations"] = [representation]
def get_dependencies(self, node):
func = """function func(args)
{
var target_node = args[0];
var numInput = node.numberOfInputPorts(target_node);
var dependencies = [];
for (var i = 0 ; i < numInput; i++)
{
dependencies.push(node.srcNode(target_node, i));
}
return dependencies;
}
func
"""
current_dependencies = harmony.send(
{"function": func, "args": [node]}
)["result"]
for dependency in current_dependencies:
if not dependency:
continue
if dependency in self.dependencies:
continue
self.dependencies.append(dependency)
self.get_dependencies(dependency)

View file

@ -1 +1 @@
__version__ = "2.8.0"
__version__ = "2.9.0"