forked from pyblish/pyblish-magenta
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate injecting context data into instance to `collect_instance_da…
…ta.py` to simplify Collectors. - Change `familyId` to `family` - Refactor implementation for Integrator from `plugin.py` to `integrate_asset.py` plug-in.
- Loading branch information
Showing
6 changed files
with
82 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import pyblish.api | ||
|
||
|
||
@pyblish.api.log | ||
class CollectInstanceData(pyblish.api.Collector): | ||
"""Inject all instances with the Context's asset data. | ||
This transfers data from the Context to each Instance. | ||
""" | ||
order = pyblish.api.Collector.order + 0.49 | ||
|
||
def process(self, context, instance): | ||
|
||
for key in ['root', 'asset', 'container', 'workFile']: | ||
|
||
value = context.data(key, None) | ||
if value is not None: | ||
instance.set_data(key, value) | ||
else: | ||
self.log.debug("Context does not have data '{0}'".format(key)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,58 @@ | ||
import pyblish_magenta.plugin | ||
import os | ||
import shutil | ||
|
||
import pyblish.api | ||
import pyblish_magenta | ||
|
||
class IntegrateAsset(pyblish_magenta.plugin.Integrator): | ||
|
||
class IntegrateAsset(pyblish.api.Integrator): | ||
label = "Integrate Asset" | ||
|
||
def process(self, instance): | ||
self.integrate(instance) | ||
|
||
def compute_integrate_dir(self, instance): | ||
# Get instance data | ||
data = {'root': instance.data('root'), | ||
'container': instance.data('container', None), | ||
'asset': instance.data('asset')} | ||
|
||
family = instance.data('family') | ||
if not family: | ||
raise pyblish.api.ConformError( | ||
"No family found on instance. Can't resolve asset path.") | ||
|
||
# Get asset directory | ||
schema = pyblish_magenta.schema.load() | ||
output_template = "{0}.asset".format(family) | ||
dir_path = schema.get(output_template).format(data) | ||
|
||
return dir_path | ||
|
||
def integrate(self, instance): | ||
|
||
# Get the extracted directory | ||
extract_dir = instance.data('extractDir') | ||
if not extract_dir: | ||
raise pyblish.api.ConformError("Cannot integrate if no `extractDir` " | ||
"temporary directory found.") | ||
|
||
# Define the integrate directory | ||
integrate_dir = self.compute_integrate_dir(instance) | ||
instance.set_data('integrateDir', value=integrate_dir) | ||
|
||
# Copy the files/directories from extract directory to the integrate directory | ||
self.log.info("Integrating extracted files for '{0}'..".format(instance)) | ||
if os.path.isdir(integrate_dir): | ||
self.log.info("Existing directory found, merging..") | ||
for fname in os.listdir(extract_dir): | ||
abspath = os.path.join(extract_dir, fname) | ||
commit_path = os.path.join(integrate_dir, fname) | ||
shutil.copy(abspath, commit_path) | ||
else: | ||
self.log.info("No existing directory found, creating..") | ||
shutil.copytree(extract_dir, integrate_dir) | ||
|
||
self.log.info("Integrated to directory '{0}'".format(integrate_dir)) | ||
|
||
return integrate_dir |