mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Merge pull request #251 from tokejepsen/2.x/feature/harmony_publish_workfile
Publish workfile
This commit is contained in:
commit
1f0b72a803
5 changed files with 112 additions and 61 deletions
|
|
@ -1,61 +0,0 @@
|
|||
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):
|
||||
# Make backdrops from metadata.
|
||||
backdrops = context["representation"]["data"].get("backdrops", [])
|
||||
|
||||
func = """function func(args)
|
||||
{
|
||||
Backdrop.addBackdrop("Top", args[0]);
|
||||
}
|
||||
func
|
||||
"""
|
||||
for backdrop in backdrops:
|
||||
harmony.send({"function": func, "args": [backdrop]})
|
||||
|
||||
# Import template.
|
||||
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)
|
||||
28
pype/plugins/harmony/publish/collect_workfile.py
Normal file
28
pype/plugins/harmony/publish/collect_workfile.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import pyblish.api
|
||||
import os
|
||||
|
||||
|
||||
class CollectWorkfile(pyblish.api.ContextPlugin):
|
||||
"""Collect current script for publish."""
|
||||
|
||||
order = pyblish.api.CollectorOrder + 0.1
|
||||
label = "Collect Workfile"
|
||||
hosts = ["harmony"]
|
||||
|
||||
def process(self, context):
|
||||
family = "workfile"
|
||||
task = os.getenv("AVALON_TASK", None)
|
||||
subset = family + task.capitalize()
|
||||
basename = os.path.basename(context.data["currentFile"])
|
||||
|
||||
# Create instance
|
||||
instance = context.create_instance(subset)
|
||||
instance.data.update({
|
||||
"subset": subset,
|
||||
"label": basename,
|
||||
"name": basename,
|
||||
"family": family,
|
||||
"families": [],
|
||||
"representations": [],
|
||||
"asset": os.environ["AVALON_ASSET"]
|
||||
})
|
||||
13
pype/plugins/harmony/publish/extract_save_scene.py
Normal file
13
pype/plugins/harmony/publish/extract_save_scene.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import pyblish.api
|
||||
from avalon import harmony
|
||||
|
||||
|
||||
class ExtractSaveScene(pyblish.api.ContextPlugin):
|
||||
"""Save scene for extraction."""
|
||||
|
||||
label = "Extract Save Scene"
|
||||
order = pyblish.api.ExtractorOrder - 0.49
|
||||
hosts = ["harmony"]
|
||||
|
||||
def process(self, instance):
|
||||
harmony.save_scene()
|
||||
33
pype/plugins/harmony/publish/extract_workfile.py
Normal file
33
pype/plugins/harmony/publish/extract_workfile.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import os
|
||||
import shutil
|
||||
|
||||
import pype.api
|
||||
|
||||
|
||||
class ExtractWorkfile(pype.api.Extractor):
|
||||
"""Extract the connected nodes to the composite instance."""
|
||||
|
||||
label = "Extract Workfile"
|
||||
hosts = ["harmony"]
|
||||
families = ["workfile"]
|
||||
|
||||
def process(self, instance):
|
||||
file_path = instance.context.data["currentFile"]
|
||||
staging_dir = self.staging_dir(instance)
|
||||
|
||||
os.chdir(staging_dir)
|
||||
shutil.make_archive(
|
||||
instance.name,
|
||||
"zip",
|
||||
os.path.dirname(file_path)
|
||||
)
|
||||
zip_path = os.path.join(staging_dir, instance.name + ".zip")
|
||||
self.log.info(f"Output zip file: {zip_path}")
|
||||
|
||||
representation = {
|
||||
"name": "tpl",
|
||||
"ext": "zip",
|
||||
"files": "{}.zip".format(instance.name),
|
||||
"stagingDir": staging_dir
|
||||
}
|
||||
instance.data["representations"] = [representation]
|
||||
38
pype/plugins/harmony/publish/increment_workfile.py
Normal file
38
pype/plugins/harmony/publish/increment_workfile.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import os
|
||||
|
||||
import pyblish.api
|
||||
from pype.action import get_errored_plugins_from_data
|
||||
from pype.lib import version_up
|
||||
from avalon import harmony
|
||||
|
||||
|
||||
class IncrementWorkfile(pyblish.api.InstancePlugin):
|
||||
"""Increment the current workfile.
|
||||
|
||||
Saves the current scene with an increased version number.
|
||||
"""
|
||||
|
||||
label = "Increment Workfile"
|
||||
order = pyblish.api.IntegratorOrder + 9.0
|
||||
hosts = ["harmony"]
|
||||
families = ["workfile"]
|
||||
optional = True
|
||||
|
||||
def process(self, instance):
|
||||
errored_plugins = get_errored_plugins_from_data(instance.context)
|
||||
if errored_plugins:
|
||||
raise RuntimeError(
|
||||
"Skipping incrementing current file because submission to"
|
||||
" deadline failed."
|
||||
)
|
||||
|
||||
scene_dir = version_up(
|
||||
os.path.dirname(instance.context.data["currentFile"])
|
||||
)
|
||||
scene_path = os.path.join(
|
||||
scene_dir, os.path.basename(scene_dir) + ".xstage"
|
||||
)
|
||||
|
||||
harmony.save_scene_as(scene_path)
|
||||
|
||||
self.log.info("Incremented workfile to: {}".format(scene_path))
|
||||
Loading…
Add table
Add a link
Reference in a new issue