-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from BigRoy/master
Separating Collectors + Extractor/Integrator separation for model
- Loading branch information
Showing
13 changed files
with
694 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import os | ||
import shutil | ||
import tempfile | ||
import contextlib | ||
|
||
import pyblish.api | ||
import pyblish_magenta.schema | ||
|
||
|
||
class Extractor(pyblish.api.Extractor): | ||
def temp_dir(self, instance): | ||
"""Provide a (temporary) directory in which to store files""" | ||
extract_dir = instance.data('extractDir') | ||
|
||
if not extract_dir: | ||
extract_dir = tempfile.mkdtemp() | ||
instance.set_data('extractDir', value=extract_dir) | ||
|
||
return extract_dir | ||
|
||
|
||
class Integrator(pyblish.api.Integrator): | ||
|
||
def compute_integrate_dir(self, instance): | ||
# Get instance data | ||
data = {'root': instance.data('root'), | ||
'container': instance.data('container'), | ||
'asset': instance.data('asset')} | ||
family_id = instance.data('familyId') | ||
|
||
if not family_id: | ||
raise pyblish.api.ConformError("No family id found on instance. Can't resolve asset path.") | ||
|
||
# Get asset directory | ||
schema = pyblish_magenta.schema.load() | ||
output_template = "{0}.asset".format(family_id) | ||
dir_path = schema.get(output_template).format(data) | ||
|
||
return dir_path | ||
|
||
def integrate(self, instance): | ||
|
||
extract_dir = instance.data('extractDir') | ||
if not extract_dir: | ||
raise pyblish.api.ConformError("Cannot integrate if no `commitDir`" | ||
" temporary directory found.") | ||
|
||
integrate_dir = self.compute_integrate_dir(instance) | ||
|
||
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) | ||
|
||
# Persist path of commit within instance | ||
instance.set_data('integrateDir', value=integrate_dir) | ||
|
||
self.log.info("Integrated to directory '{0}'".format(integrate_dir)) | ||
|
||
return integrate_dir |
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,40 @@ | ||
import pyblish.api | ||
import pyblish_magenta.schema | ||
|
||
|
||
@pyblish.api.log | ||
class CollectAsset(pyblish.api.Collector): | ||
order = pyblish.api.Collector.order + 0.1 | ||
|
||
def process(self, context): | ||
self.log.info("Collecting Asset..") | ||
|
||
work_file = context.data('workFile') | ||
if not work_file: | ||
return | ||
|
||
# Ensure we use a path with forward slashes | ||
work_file = work_file.replace('\\', '/') | ||
|
||
# Parse with schema | ||
schema = pyblish_magenta.schema.load() | ||
data, template = schema.parse(work_file) | ||
|
||
# Note that this the family id retrieved from the template. | ||
# This is not a one-to-one copy of the 'family' used in the plug-ins. | ||
# That's why we store this information as 'familyId' to avoid confusion | ||
family_id = template.name.split('.')[0] | ||
context.set_data('familyId', family_id) | ||
|
||
# Store the project root's path | ||
root = data['root'] | ||
context.set_data('root', root) | ||
|
||
# Store the asset name | ||
asset = data['asset'] | ||
context.set_data('asset', asset) | ||
|
||
# Store the container's name | ||
container = data['container'] | ||
context.set_data('container', container) | ||
|
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,26 @@ | ||
import os | ||
import pyblish.api | ||
|
||
|
||
@pyblish.api.log | ||
class CollectConceptArt(pyblish.api.Collector): | ||
""" | ||
Collect Concept Art files from the current work directory. | ||
Any `.png` files in the `cwd` are considered to be artwork. | ||
""" | ||
def process(self, context): | ||
self.log.info("Selecting concept art..") | ||
|
||
cwd = context.data("cwd") | ||
for fname in os.listdir(cwd): | ||
if fname.lower().endswith(".png"): | ||
name = os.path.basename(fname.rsplit(".", 1)[0]) | ||
|
||
self.log.info("Creating instance: %s" % name) | ||
instance = context.create_instance(name) | ||
|
||
# Capture certain characteristics for validation | ||
instance.set_data("family", "conceptArt") | ||
instance.set_data("path", os.path.join(context.data("cwd"), fname)) | ||
instance.set_data("bytes", os.stat(fname).st_size) |
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,27 @@ | ||
import os | ||
|
||
import pyblish.api | ||
|
||
from maya import cmds | ||
|
||
|
||
@pyblish.api.log | ||
class CollectMayaCurrentFile(pyblish.api.Collector): | ||
hosts = ["maya"] | ||
|
||
def process(self, context): | ||
self.log.info("Collecting Maya Work File..") | ||
|
||
# File Path | ||
# --------- | ||
current_file = cmds.file(q=1, sceneName=True) | ||
if not current_file: | ||
# file not saved | ||
self.log.error("Scene has not been saved.") | ||
return | ||
|
||
# Maya returns forward-slashes by default | ||
current_file = os.path.normpath(current_file) | ||
|
||
context.set_data('workFile', value=current_file) | ||
|
10 changes: 5 additions & 5 deletions
10
pyblish_magenta/plugins/select_maya_units.py → ...ish_magenta/plugins/collect_maya_units.py
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,62 @@ | ||
import os | ||
import shutil | ||
import tempfile | ||
import subprocess | ||
import pyblish.api | ||
|
||
|
||
class ExtractGif(pyblish.api.Extractor): | ||
families = ["review"] | ||
optional = True | ||
order = pyblish.api.Extractor.order + 0.1 | ||
|
||
def process(self, context, instance): | ||
output_path = instance.data("outputPath") | ||
if not output_path: | ||
return self.log.info("No capture available for conversion.") | ||
|
||
self.log.info("Generating gif from %s" % output_path) | ||
|
||
fps = context.data("fps") or 24 | ||
width = context.data("width") or 512 | ||
|
||
generate_palette = ("ffmpeg -y -i {input} -vf " | ||
"\"fps={fps},scale={width}:-1:flags=lanczos,palettegen\" " | ||
"{palette}") | ||
|
||
generate_gif = ("ffmpeg -y -i {input} -i {palette} -filter_complex " | ||
"\"fps={fps},scale={width}:-1:flags=lanczos[x];[x][1:v]paletteuse\" " | ||
"{output}") | ||
try: | ||
tempdir = tempfile.mkdtemp() | ||
palette = os.path.join(tempdir, "palette.png") | ||
output = output_path.rsplit(".", 1)[0] + ".gif" | ||
self.log.info("Outputting to %s" % output) | ||
|
||
try: | ||
output_ = subprocess.check_output( | ||
generate_palette.format( | ||
input=output_path, | ||
fps=fps, | ||
width=width, | ||
palette=palette)) | ||
except subprocess.CalledProcessError: | ||
self.log.warning(output_) | ||
return self.log.warning("Could not generate palette") | ||
|
||
try: | ||
output_ = subprocess.call( | ||
generate_gif.format( | ||
input=output_path, | ||
fps=fps, | ||
width=width, | ||
palette=palette, | ||
output=output)) | ||
except subprocess.CalledProcessError: | ||
self.log.warning(output_) | ||
return self.log.warning("Could not generate gif") | ||
|
||
finally: | ||
shutil.rmtree(tempdir) | ||
|
||
self.log.info("Finished successfully") |
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
Oops, something went wrong.