diff --git a/pype/hosts/celaction/__init__.py b/pype/hosts/celaction/__init__.py index 8c93d93738..e69de29bb2 100644 --- a/pype/hosts/celaction/__init__.py +++ b/pype/hosts/celaction/__init__.py @@ -1 +0,0 @@ -kwargs = None diff --git a/pype/hosts/celaction/api/__init__.py b/pype/hosts/celaction/api/__init__.py new file mode 100644 index 0000000000..8c93d93738 --- /dev/null +++ b/pype/hosts/celaction/api/__init__.py @@ -0,0 +1 @@ +kwargs = None diff --git a/pype/hosts/celaction/cli.py b/pype/hosts/celaction/api/cli.py similarity index 87% rename from pype/hosts/celaction/cli.py rename to pype/hosts/celaction/api/cli.py index 42f7a1a385..9f2d1a1fdb 100644 --- a/pype/hosts/celaction/cli.py +++ b/pype/hosts/celaction/api/cli.py @@ -11,18 +11,19 @@ import pyblish.util from pype.api import Logger import pype -from pype.hosts import celaction +import pype.hosts.celaction +from pype.hosts.celaction import api as celaction log = Logger().get_logger("Celaction_cli_publisher") publish_host = "celaction" -PUBLISH_PATH = os.path.join(pype.PLUGINS_DIR, publish_host, "publish") - -PUBLISH_PATHS = [ - PUBLISH_PATH, - os.path.join(pype.PLUGINS_DIR, "ftrack", "publish") -] +HOST_DIR = os.path.dirname(os.path.abspath(pype.hosts.celaction.__file__)) +PLUGINS_DIR = os.path.join(HOST_DIR, "plugins") +PUBLISH_PATH = os.path.join(PLUGINS_DIR, "publish") +LOAD_PATH = os.path.join(PLUGINS_DIR, "load") +CREATE_PATH = os.path.join(PLUGINS_DIR, "create") +INVENTORY_PATH = os.path.join(PLUGINS_DIR, "inventory") def cli(): diff --git a/pype/hosts/celaction/hooks/__init__.py b/pype/hosts/celaction/hooks/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pype/hooks/celaction/pre_celaction_registers.py b/pype/hosts/celaction/hooks/pre_celaction_registers.py similarity index 95% rename from pype/hooks/celaction/pre_celaction_registers.py rename to pype/hosts/celaction/hooks/pre_celaction_registers.py index 04ecf82c5c..1e836a2d63 100644 --- a/pype/hooks/celaction/pre_celaction_registers.py +++ b/pype/hosts/celaction/hooks/pre_celaction_registers.py @@ -2,7 +2,7 @@ import os import shutil import winreg from pype.lib import PreLaunchHook -from pype.hosts import celaction +from pype.hosts.celaction import api as celaction class CelactionPrelaunchHook(PreLaunchHook): @@ -37,7 +37,7 @@ class CelactionPrelaunchHook(PreLaunchHook): "Software\\CelAction\\CelAction2D\\User Settings", 0, winreg.KEY_ALL_ACCESS) - # TODO: change to root path and pyblish standalone to premiere way + # TODO: change to pype executable pype_root_path = os.getenv("PYPE_SETUP_PATH") path = os.path.join(pype_root_path, "pype.bat") @@ -94,11 +94,12 @@ class CelactionPrelaunchHook(PreLaunchHook): if not os.path.exists(workfile_path): # TODO add ability to set different template workfile path via # settings - pype_celaction_dir = os.path.dirname( + pype_celaction_dir = os.path.dirname(os.path.dirname( os.path.abspath(celaction.__file__) - ) + )) template_path = os.path.join( pype_celaction_dir, + "resources", "celaction_template_scene.scn" ) diff --git a/pype/hosts/celaction/plugins/__init__.py b/pype/hosts/celaction/plugins/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pype/plugins/celaction/publish/collect_audio.py b/pype/hosts/celaction/plugins/publish/collect_audio.py similarity index 97% rename from pype/plugins/celaction/publish/collect_audio.py rename to pype/hosts/celaction/plugins/publish/collect_audio.py index bab1203642..8d3c1568e6 100644 --- a/pype/plugins/celaction/publish/collect_audio.py +++ b/pype/hosts/celaction/plugins/publish/collect_audio.py @@ -1,126 +1,126 @@ -import os -import collections - -import pyblish.api -from avalon import io - -from pprint import pformat - - -class AppendCelactionAudio(pyblish.api.ContextPlugin): - - label = "Colect Audio for publishing" - order = pyblish.api.CollectorOrder + 0.1 - - def process(self, context): - self.log.info('Collecting Audio Data') - asset_doc = context.data["assetEntity"] - - # get all available representations - subsets = self.get_subsets( - asset_doc, - representations=["audio", "wav"] - ) - self.log.info(f"subsets is: {pformat(subsets)}") - - if not subsets.get("audioMain"): - raise AttributeError("`audioMain` subset does not exist") - - reprs = subsets.get("audioMain", {}).get("representations", []) - self.log.info(f"reprs is: {pformat(reprs)}") - - repr = next((r for r in reprs), None) - if not repr: - raise "Missing `audioMain` representation" - self.log.info(f"represetation is: {repr}") - - audio_file = repr.get('data', {}).get('path', "") - - if os.path.exists(audio_file): - context.data["audioFile"] = audio_file - self.log.info( - 'audio_file: {}, has been added to context'.format(audio_file)) - else: - self.log.warning("Couldn't find any audio file on Ftrack.") - - def get_subsets(self, asset_doc, representations): - """ - Query subsets with filter on name. - - The method will return all found subsets and its defined version - and subsets. Version could be specified with number. Representation - can be filtered. - - Arguments: - asset_doct (dict): Asset (shot) mongo document - representations (list): list for all representations - - Returns: - dict: subsets with version and representaions in keys - """ - - # Query all subsets for asset - subset_docs = io.find({ - "type": "subset", - "parent": asset_doc["_id"] - }) - # Collect all subset ids - subset_ids = [ - subset_doc["_id"] - for subset_doc in subset_docs - ] - - # Check if we found anything - assert subset_ids, ( - "No subsets found. Check correct filter. " - "Try this for start `r'.*'`: asset: `{}`" - ).format(asset_doc["name"]) - - # Last version aggregation - pipeline = [ - # Find all versions of those subsets - {"$match": { - "type": "version", - "parent": {"$in": subset_ids} - }}, - # Sorting versions all together - {"$sort": {"name": 1}}, - # Group them by "parent", but only take the last - {"$group": { - "_id": "$parent", - "_version_id": {"$last": "$_id"}, - "name": {"$last": "$name"} - }} - ] - last_versions_by_subset_id = dict() - for doc in io.aggregate(pipeline): - doc["parent"] = doc["_id"] - doc["_id"] = doc.pop("_version_id") - last_versions_by_subset_id[doc["parent"]] = doc - - version_docs_by_id = {} - for version_doc in last_versions_by_subset_id.values(): - version_docs_by_id[version_doc["_id"]] = version_doc - - repre_docs = io.find({ - "type": "representation", - "parent": {"$in": list(version_docs_by_id.keys())}, - "name": {"$in": representations} - }) - repre_docs_by_version_id = collections.defaultdict(list) - for repre_doc in repre_docs: - version_id = repre_doc["parent"] - repre_docs_by_version_id[version_id].append(repre_doc) - - output_dict = {} - for version_id, repre_docs in repre_docs_by_version_id.items(): - version_doc = version_docs_by_id[version_id] - subset_id = version_doc["parent"] - subset_doc = last_versions_by_subset_id[subset_id] - # Store queried docs by subset name - output_dict[subset_doc["name"]] = { - "representations": repre_docs, - "version": version_doc - } - - return output_dict +import os +import collections + +import pyblish.api +from avalon import io + +from pprint import pformat + + +class AppendCelactionAudio(pyblish.api.ContextPlugin): + + label = "Colect Audio for publishing" + order = pyblish.api.CollectorOrder + 0.1 + + def process(self, context): + self.log.info('Collecting Audio Data') + asset_doc = context.data["assetEntity"] + + # get all available representations + subsets = self.get_subsets( + asset_doc, + representations=["audio", "wav"] + ) + self.log.info(f"subsets is: {pformat(subsets)}") + + if not subsets.get("audioMain"): + raise AttributeError("`audioMain` subset does not exist") + + reprs = subsets.get("audioMain", {}).get("representations", []) + self.log.info(f"reprs is: {pformat(reprs)}") + + repr = next((r for r in reprs), None) + if not repr: + raise "Missing `audioMain` representation" + self.log.info(f"represetation is: {repr}") + + audio_file = repr.get('data', {}).get('path', "") + + if os.path.exists(audio_file): + context.data["audioFile"] = audio_file + self.log.info( + 'audio_file: {}, has been added to context'.format(audio_file)) + else: + self.log.warning("Couldn't find any audio file on Ftrack.") + + def get_subsets(self, asset_doc, representations): + """ + Query subsets with filter on name. + + The method will return all found subsets and its defined version + and subsets. Version could be specified with number. Representation + can be filtered. + + Arguments: + asset_doct (dict): Asset (shot) mongo document + representations (list): list for all representations + + Returns: + dict: subsets with version and representaions in keys + """ + + # Query all subsets for asset + subset_docs = io.find({ + "type": "subset", + "parent": asset_doc["_id"] + }) + # Collect all subset ids + subset_ids = [ + subset_doc["_id"] + for subset_doc in subset_docs + ] + + # Check if we found anything + assert subset_ids, ( + "No subsets found. Check correct filter. " + "Try this for start `r'.*'`: asset: `{}`" + ).format(asset_doc["name"]) + + # Last version aggregation + pipeline = [ + # Find all versions of those subsets + {"$match": { + "type": "version", + "parent": {"$in": subset_ids} + }}, + # Sorting versions all together + {"$sort": {"name": 1}}, + # Group them by "parent", but only take the last + {"$group": { + "_id": "$parent", + "_version_id": {"$last": "$_id"}, + "name": {"$last": "$name"} + }} + ] + last_versions_by_subset_id = dict() + for doc in io.aggregate(pipeline): + doc["parent"] = doc["_id"] + doc["_id"] = doc.pop("_version_id") + last_versions_by_subset_id[doc["parent"]] = doc + + version_docs_by_id = {} + for version_doc in last_versions_by_subset_id.values(): + version_docs_by_id[version_doc["_id"]] = version_doc + + repre_docs = io.find({ + "type": "representation", + "parent": {"$in": list(version_docs_by_id.keys())}, + "name": {"$in": representations} + }) + repre_docs_by_version_id = collections.defaultdict(list) + for repre_doc in repre_docs: + version_id = repre_doc["parent"] + repre_docs_by_version_id[version_id].append(repre_doc) + + output_dict = {} + for version_id, repre_docs in repre_docs_by_version_id.items(): + version_doc = version_docs_by_id[version_id] + subset_id = version_doc["parent"] + subset_doc = last_versions_by_subset_id[subset_id] + # Store queried docs by subset name + output_dict[subset_doc["name"]] = { + "representations": repre_docs, + "version": version_doc + } + + return output_dict diff --git a/pype/plugins/celaction/publish/collect_celaction_cli_kwargs.py b/pype/hosts/celaction/plugins/publish/collect_celaction_cli_kwargs.py similarity index 92% rename from pype/plugins/celaction/publish/collect_celaction_cli_kwargs.py rename to pype/hosts/celaction/plugins/publish/collect_celaction_cli_kwargs.py index f4a9ec341d..463805ce4b 100644 --- a/pype/plugins/celaction/publish/collect_celaction_cli_kwargs.py +++ b/pype/hosts/celaction/plugins/publish/collect_celaction_cli_kwargs.py @@ -1,23 +1,23 @@ -import pyblish.api -from pype.hosts import celaction - - -class CollectCelactionCliKwargs(pyblish.api.Collector): - """ Collects all keyword arguments passed from the terminal """ - - label = "Collect Celaction Cli Kwargs" - order = pyblish.api.Collector.order - 0.1 - - def process(self, context): - kwargs = celaction.kwargs.copy() - - self.log.info("Storing kwargs: %s" % kwargs) - context.set_data("kwargs", kwargs) - - # get kwargs onto context data as keys with values - for k, v in kwargs.items(): - self.log.info(f"Setting `{k}` to instance.data with value: `{v}`") - if k in ["frameStart", "frameEnd"]: - context.data[k] = kwargs[k] = int(v) - else: - context.data[k] = v +import pyblish.api +from pype.hosts.celaction import api as celaction + + +class CollectCelactionCliKwargs(pyblish.api.Collector): + """ Collects all keyword arguments passed from the terminal """ + + label = "Collect Celaction Cli Kwargs" + order = pyblish.api.Collector.order - 0.1 + + def process(self, context): + kwargs = celaction.kwargs.copy() + + self.log.info("Storing kwargs: %s" % kwargs) + context.set_data("kwargs", kwargs) + + # get kwargs onto context data as keys with values + for k, v in kwargs.items(): + self.log.info(f"Setting `{k}` to instance.data with value: `{v}`") + if k in ["frameStart", "frameEnd"]: + context.data[k] = kwargs[k] = int(v) + else: + context.data[k] = v diff --git a/pype/plugins/celaction/publish/collect_celaction_instances.py b/pype/hosts/celaction/plugins/publish/collect_celaction_instances.py similarity index 97% rename from pype/plugins/celaction/publish/collect_celaction_instances.py rename to pype/hosts/celaction/plugins/publish/collect_celaction_instances.py index d3d1d264c0..f393e471c4 100644 --- a/pype/plugins/celaction/publish/collect_celaction_instances.py +++ b/pype/hosts/celaction/plugins/publish/collect_celaction_instances.py @@ -1,96 +1,96 @@ -import os -from avalon import api -import pyblish.api - - -class CollectCelactionInstances(pyblish.api.ContextPlugin): - """ Adds the celaction render instances """ - - label = "Collect Celaction Instances" - order = pyblish.api.CollectorOrder + 0.1 - - def process(self, context): - task = api.Session["AVALON_TASK"] - current_file = context.data["currentFile"] - staging_dir = os.path.dirname(current_file) - scene_file = os.path.basename(current_file) - version = context.data["version"] - asset_entity = context.data["assetEntity"] - project_entity = context.data["projectEntity"] - - shared_instance_data = { - "asset": asset_entity["name"], - "frameStart": asset_entity["data"]["frameStart"], - "frameEnd": asset_entity["data"]["frameEnd"], - "handleStart": asset_entity["data"]["handleStart"], - "handleEnd": asset_entity["data"]["handleEnd"], - "fps": asset_entity["data"]["fps"], - "resolutionWidth": asset_entity["data"].get( - "resolutionWidth", - project_entity["data"]["resolutionWidth"]), - "resolutionHeight": asset_entity["data"].get( - "resolutionHeight", - project_entity["data"]["resolutionHeight"]), - "pixelAspect": 1, - "step": 1, - "version": version - } - - celaction_kwargs = context.data.get("kwargs", {}) - - if celaction_kwargs: - shared_instance_data.update(celaction_kwargs) - - # workfile instance - family = "workfile" - subset = family + task.capitalize() - # Create instance - instance = context.create_instance(subset) - - # creating instance data - instance.data.update({ - "subset": subset, - "label": scene_file, - "family": family, - "families": [family, "ftrack"], - "representations": list() - }) - - # adding basic script data - instance.data.update(shared_instance_data) - - # creating representation - representation = { - 'name': 'scn', - 'ext': 'scn', - 'files': scene_file, - "stagingDir": staging_dir, - } - - instance.data["representations"].append(representation) - - self.log.info('Publishing Celaction workfile') - - # render instance - family = "render.farm" - subset = f"render{task}Main" - instance = context.create_instance(name=subset) - # getting instance state - instance.data["publish"] = True - - # add assetEntity data into instance - instance.data.update({ - "label": "{} - farm".format(subset), - "family": family, - "families": [family], - "subset": subset - }) - - # adding basic script data - instance.data.update(shared_instance_data) - - self.log.info('Publishing Celaction render instance') - self.log.debug(f"Instance data: `{instance.data}`") - - for i in context: - self.log.debug(f"{i.data['families']}") +import os +from avalon import api +import pyblish.api + + +class CollectCelactionInstances(pyblish.api.ContextPlugin): + """ Adds the celaction render instances """ + + label = "Collect Celaction Instances" + order = pyblish.api.CollectorOrder + 0.1 + + def process(self, context): + task = api.Session["AVALON_TASK"] + current_file = context.data["currentFile"] + staging_dir = os.path.dirname(current_file) + scene_file = os.path.basename(current_file) + version = context.data["version"] + asset_entity = context.data["assetEntity"] + project_entity = context.data["projectEntity"] + + shared_instance_data = { + "asset": asset_entity["name"], + "frameStart": asset_entity["data"]["frameStart"], + "frameEnd": asset_entity["data"]["frameEnd"], + "handleStart": asset_entity["data"]["handleStart"], + "handleEnd": asset_entity["data"]["handleEnd"], + "fps": asset_entity["data"]["fps"], + "resolutionWidth": asset_entity["data"].get( + "resolutionWidth", + project_entity["data"]["resolutionWidth"]), + "resolutionHeight": asset_entity["data"].get( + "resolutionHeight", + project_entity["data"]["resolutionHeight"]), + "pixelAspect": 1, + "step": 1, + "version": version + } + + celaction_kwargs = context.data.get("kwargs", {}) + + if celaction_kwargs: + shared_instance_data.update(celaction_kwargs) + + # workfile instance + family = "workfile" + subset = family + task.capitalize() + # Create instance + instance = context.create_instance(subset) + + # creating instance data + instance.data.update({ + "subset": subset, + "label": scene_file, + "family": family, + "families": [family, "ftrack"], + "representations": list() + }) + + # adding basic script data + instance.data.update(shared_instance_data) + + # creating representation + representation = { + 'name': 'scn', + 'ext': 'scn', + 'files': scene_file, + "stagingDir": staging_dir, + } + + instance.data["representations"].append(representation) + + self.log.info('Publishing Celaction workfile') + + # render instance + family = "render.farm" + subset = f"render{task}Main" + instance = context.create_instance(name=subset) + # getting instance state + instance.data["publish"] = True + + # add assetEntity data into instance + instance.data.update({ + "label": "{} - farm".format(subset), + "family": family, + "families": [family], + "subset": subset + }) + + # adding basic script data + instance.data.update(shared_instance_data) + + self.log.info('Publishing Celaction render instance') + self.log.debug(f"Instance data: `{instance.data}`") + + for i in context: + self.log.debug(f"{i.data['families']}") diff --git a/pype/plugins/celaction/publish/collect_render_path.py b/pype/hosts/celaction/plugins/publish/collect_render_path.py similarity index 100% rename from pype/plugins/celaction/publish/collect_render_path.py rename to pype/hosts/celaction/plugins/publish/collect_render_path.py diff --git a/pype/plugins/celaction/publish/integrate_version_up.py b/pype/hosts/celaction/plugins/publish/integrate_version_up.py similarity index 96% rename from pype/plugins/celaction/publish/integrate_version_up.py rename to pype/hosts/celaction/plugins/publish/integrate_version_up.py index e15c5d5bf6..140878e2b9 100644 --- a/pype/plugins/celaction/publish/integrate_version_up.py +++ b/pype/hosts/celaction/plugins/publish/integrate_version_up.py @@ -1,20 +1,20 @@ -import shutil -import pype -import pyblish.api - - -class VersionUpScene(pyblish.api.ContextPlugin): - order = pyblish.api.IntegratorOrder + 0.5 - label = 'Version Up Scene' - families = ['workfile'] - optional = True - active = True - - def process(self, context): - current_file = context.data.get('currentFile') - v_up = pype.lib.version_up(current_file) - self.log.debug('Current file is: {}'.format(current_file)) - self.log.debug('Version up: {}'.format(v_up)) - - shutil.copy2(current_file, v_up) - self.log.info('Scene saved into new version: {}'.format(v_up)) +import shutil +import pype +import pyblish.api + + +class VersionUpScene(pyblish.api.ContextPlugin): + order = pyblish.api.IntegratorOrder + 0.5 + label = 'Version Up Scene' + families = ['workfile'] + optional = True + active = True + + def process(self, context): + current_file = context.data.get('currentFile') + v_up = pype.lib.version_up(current_file) + self.log.debug('Current file is: {}'.format(current_file)) + self.log.debug('Version up: {}'.format(v_up)) + + shutil.copy2(current_file, v_up) + self.log.info('Scene saved into new version: {}'.format(v_up)) diff --git a/pype/plugins/celaction/publish/submit_celaction_deadline.py b/pype/hosts/celaction/plugins/publish/submit_celaction_deadline.py similarity index 100% rename from pype/plugins/celaction/publish/submit_celaction_deadline.py rename to pype/hosts/celaction/plugins/publish/submit_celaction_deadline.py diff --git a/pype/hosts/celaction/celaction_template_scene.scn b/pype/hosts/celaction/resources/celaction_template_scene.scn similarity index 100% rename from pype/hosts/celaction/celaction_template_scene.scn rename to pype/hosts/celaction/resources/celaction_template_scene.scn