diff --git a/pype/api.py b/pype/api.py index 2227236fd3..bcbf5eb8de 100644 --- a/pype/api.py +++ b/pype/api.py @@ -40,6 +40,7 @@ from .templates import ( ) from .lib import ( + version_up, get_handle_irregular, get_project_data, get_asset_data, diff --git a/pype/plugins/nukestudio/publish/collect_current_file.py b/pype/plugins/nukestudio/publish/collect_current_file.py index 0c194e8d3d..c0c217dd23 100644 --- a/pype/plugins/nukestudio/publish/collect_current_file.py +++ b/pype/plugins/nukestudio/publish/collect_current_file.py @@ -1,5 +1,4 @@ import pyblish.api -import pype.api as pype class CollectCurrentFile(pyblish.api.ContextPlugin): """Inject the current working file into context""" @@ -8,10 +7,7 @@ class CollectCurrentFile(pyblish.api.ContextPlugin): def process(self, context): - """Todo, inject the current working file""" project = context.data('activeProject') context.data["currentFile"] = path = project.path() - context.data["version"] = pype.get_version_from_path(path) self.log.info("currentFile: {}".format(context.data["currentFile"])) - self.log.info("version: {}".format(context.data["version"])) diff --git a/pype/plugins/nukestudio/publish/collect_workfile_version.py b/pype/plugins/nukestudio/publish/collect_workfile_version.py new file mode 100644 index 0000000000..3904c22f52 --- /dev/null +++ b/pype/plugins/nukestudio/publish/collect_workfile_version.py @@ -0,0 +1,15 @@ +import pyblish.api +import pype.api as pype + +class CollectWorkfileVersion(pyblish.api.ContextPlugin): + """Inject the current working file version into context""" + + order = pyblish.api.CollectorOrder - 0.1 + label = "Collect workfile version" + + def process(self, context): + + project = context.data('activeProject') + path = project.path() + context.data["version"] = pype.get_version_from_path(path) + self.log.info("version: {}".format(context.data["version"])) diff --git a/pype/plugins/nukestudio/publish/validate_version.py b/pype/plugins/nukestudio/publish/validate_version.py new file mode 100644 index 0000000000..194b270d51 --- /dev/null +++ b/pype/plugins/nukestudio/publish/validate_version.py @@ -0,0 +1,74 @@ +import pyblish +from avalon import io +from pype.action import get_errored_instances_from_context +import pype.api as pype + +@pyblish.api.log +class RepairNukestudioVersionUp(pyblish.api.Action): + label = "Version Up Workfile" + on = "failed" + icon = "wrench" + + def process(self, context, plugin): + + errored_instances = get_errored_instances_from_context(context) + + # Apply pyblish logic to get the instances for the plug-in + instances = pyblish.api.instances_by_plugin(errored_instances, plugin) + + if instances: + project = context.data["activeProject"] + path = context.data.get("currentFile") + + new_path = pype.version_up(path) + + if project: + project.saveAs(new_path) + + self.log.info("Project workfile version was fixed") + + +class ValidateVersion(pyblish.api.InstancePlugin): + """Validate clip's versions. + + """ + + order = pyblish.api.ValidatorOrder + families = ["plate"] + label = "Validate Version" + actions = [RepairNukestudioVersionUp] + hosts = ["nukestudio"] + + def process(self, instance): + version = int(instance.data.get("version", 0)) + asset_name = instance.data.get("asset", None) + subset_name = instance.data.get("subset", None) + + assert version, "The file is missing version string! example: filename_v001.hrox `{}`" + + self.log.debug("Collected version: `{0}`".format(version)) + + found_v = 0 + try: + io.install() + project = io.find_one({"type": "project"}) + + asset = io.find_one({"type": "asset", + "name": asset_name, + "parent": project["_id"]}) + + subset = io.find_one({"type": "subset", + "parent": asset["_id"], + "name": subset_name}) + + version_db = io.find_one({ + 'type': 'version', + 'parent': subset["_id"], + 'name': version + }) or {} + found_v = version_db.get("name", 0) + self.log.debug("Found version: `{0}`".format(found_v)) + except Exception as e: + self.log.debug("Problem to get data from database for asset `{0}` subset `{1}`. Error: `{2}`".format(asset_name, subset_name, e)) + + assert (found_v != version), "Version must not be the same as in database `{0}`, Versions file: `{1}`, db: `{2}`".format(asset_name, version, found_v) diff --git a/pype/plugins/nukestudio/publish/version_up_workfile.py b/pype/plugins/nukestudio/publish/version_up_workfile.py new file mode 100644 index 0000000000..195099dd09 --- /dev/null +++ b/pype/plugins/nukestudio/publish/version_up_workfile.py @@ -0,0 +1,23 @@ +from pyblish import api +import pype.api as pype + + +class VersionUpWorkfile(api.ContextPlugin): + """Save as new workfile version""" + + order = api.IntegratorOrder + 10.1 + label = "Version-up Workfile" + hosts = ["nukestudio"] + + optional = True + active = True + + def process(self, context): + project = context.data["activeProject"] + path = context.data.get("currentFile") + new_path = pype.version_up(path) + + if project: + project.saveAs(new_path) + + self.log.info("Project workfile was versioned up")