Permalink
Browse files

Updated to Pyblish 1.1

  • Loading branch information...
mottosso committed Aug 3, 2015
1 parent facec4c commit 42948562b8a40d14e28997ef61805a8acdb92b58
View
@@ -6,12 +6,17 @@
log = logging.getLogger('pyblish.napoleon')
module_path = sys.modules[__name__].__file__
package_path = os.path.dirname(module_path)
plugin_path = os.path.join(package_path, 'plugins')
def register_plugins():
"""Expose Napoleon plugins to Pyblish"""
module_path = sys.modules[__name__].__file__
package_path = os.path.dirname(module_path)
plugin_path = os.path.join(package_path, 'plugins')
pyblish.api.register_plugin_path(plugin_path)
log.info("Registered %s" % plugin_path)
def deregister_plugins():
pyblish.api.deregister_plugin_path(plugin_path)
log.info("Deregistered %s" % plugin_path)
View
@@ -5,14 +5,15 @@
import tempfile
import contextlib
import pyblish.api as pyblish
import pyblish.lib
import pyblish.api
Selector = pyblish.Selector
Validator = pyblish.Validator
Selector = pyblish.api.Selector
Validator = pyblish.api.Validator
class Extractor(pyblish.Extractor):
class Extractor(pyblish.api.Extractor):
@contextlib.contextmanager
def temp_dir(self):
"""Provide a temporary directory in which to store files"""
@@ -23,6 +24,74 @@ def temp_dir(self):
shutil.rmtree(self._temp_dir)
self._temp_dir = None
def compute_commit_directory(self, instance):
"""Return commit directory for `instance`
The commit directory is derived from a template, located within
the configuration. The following variables are substituted at
run-time:
- pyblish: With absolute path to pyblish package directory
- prefix: With Config["prefix"]
- date: With date embedded into `instance`
- family: With instance embedded into `instance`
- instance: Name of `instance`
- user: Currently logged on user, as derived from `instance`
Arguments:
instance (Instance): Instance for which to compute a directory
Returns:
Absolute path to directory as string
Raises:
ExtractorError: When data is missing from `instance`
"""
workspace_dir = instance.context.data("workspace_dir")
if not workspace_dir:
# Project has not been set. Files will
# instead end up next to the working file.
current_file = instance.context.data("current_file")
workspace_dir = os.path.dirname(current_file)
date = instance.context.data("date")
date = pyblish.api.format_filename(date)
# This is assumed from default plugins
assert date, "Context did not have a date"
assert workspace_dir, (
"Could not determine commit directory. "
"Instance MUST supply either \"current_file\" or "
"\"workspace_dir\" as data prior to commit")
# Remove invalid characters from output name
name = instance.data("name")
valid_name = pyblish.api.format_filename(name)
if name != valid_name:
self.log.info("Formatting instance name: "
"\"%s\" -> \"%s\""
% (name, valid_name))
name = valid_name
variables = {"pyblish": pyblish.lib.main_package_path(),
"prefix": "published",
"date": date,
"family": instance.data("family"),
"instance": name,
"user": instance.data("user")}
# Restore separators to those native to the current OS
commit_template = "{prefix}/{date}/{family}/{instance}"
commit_template = commit_template.replace("/", os.sep)
commit_dir = commit_template.format(**variables)
commit_dir = os.path.join(workspace_dir, commit_dir)
return commit_dir
def commit(self, instance):
"""Move `instance` relative current workspace
@@ -31,10 +100,10 @@ def commit(self, instance):
"""
if not self._temp_dir:
raise pyblish.ExtractionError("Cannot commit outside of "
"temporary directory. Use "
"self.temp_dir() first")
assert self._temp_dir, (
"Cannot commit outside of "
"temporary directory. Use "
"self.temp_dir() first")
temp_dir = self._temp_dir
commit_dir = self.compute_commit_directory(instance=instance)
@@ -86,7 +155,7 @@ def copy(self, src, dst):
shutil.copytree(src, dst)
class Conformer(pyblish.Conformer):
class Conformer(pyblish.api.Conformer):
def copy(self, src, dst):
"""Copy directory `src` to directory `dst`
@@ -5,7 +5,7 @@
@pyblish.api.log
class SelectNapoleonInstances(napoleon.plugin.Selector):
class CollectNapoleonInstances(napoleon.plugin.Collector):
"""Identify publishable instances via objectSets
In a nutshell, this selector looks for instances with
@@ -16,9 +16,9 @@ class SelectNapoleonInstances(napoleon.plugin.Selector):
hosts = ['maya']
version = (0, 1, 0)
name = 'Select via Object Set'
label = 'Select via Object Set'
def process_context(self, context):
def process(self, context):
for objset in cmds.ls("*.id",
objectsOnly=True,
type='objectSet',
@@ -20,21 +20,21 @@ class ConformNapoleonAnimation(napoleon.plugin.Conformer):
"""
hosts = ['maya']
hosts = ["maya"]
version = (0, 1, 0)
families = ['napoleon.animation.curves',
'napoleon.animation.review',
'napoleon.animation.points']
name = 'Conform Animation'
families = ["napoleon.animation.curves",
"napoleon.animation.review",
"napoleon.animation.points"]
label = "Conform Animation"
def process_instance(self, instance):
commit_dir = instance.data('commit_dir')
def process(self, instance):
commit_dir = instance.data("commit_dir")
if not commit_dir:
raise pyblish.api.ConformError(
"Cannot conform what hasn't "
"been committed: \"%s\"" % instance)
conform_dir = instance.data('conform_dir')
conform_dir = instance.data("conform_dir")
if not conform_dir:
conform_dir = self.compute_conform_dir(root=commit_dir,
@@ -43,16 +43,16 @@ def process_instance(self, instance):
self.log.info("Moving from %s to %s" % (commit_dir, conform_dir))
self.copy(src=commit_dir, dst=conform_dir)
instance.set_data('conform_dir', conform_dir)
instance.set_data("conform_dir", conform_dir)
def compute_conform_dir(self, root, instance):
# Look in other instances first
for instance in instance.context:
if instance.has_data('conform_dir'):
return instance.data('conform_dir')
if instance.has_data("conform_dir"):
return instance.data("conform_dir")
parent_asset_dir = cquery.first_match(root,
selector='.Shot',
selector=".Shot",
direction=cquery.UP)
if not parent_asset_dir:
raise pyblish.api.ConformError(
@@ -62,7 +62,7 @@ def compute_conform_dir(self, root, instance):
self.log.info("Parent shot: %s" % parent_asset_dir)
public_dir = napoleon.pipeline.public_dir(parent_asset_dir)
name = instance.data('name')
name = instance.data("name")
try:
# Use namespace as name of instance by default
@@ -71,7 +71,7 @@ def compute_conform_dir(self, root, instance):
except ValueError:
pass
family = instance.data('family')
family = instance.data("family")
assert family
instance_dir = os.path.join(public_dir, name, family)
@@ -21,9 +21,9 @@ class ConformNapoleonAsset(napoleon.plugin.Conformer):
families = ['napoleon.asset.rig',
'napoleon.asset.model',
'napoleon.asset.review']
name = 'Conform Asset'
label = 'Conform Asset'
def process_context(self, context):
def process(self, context):
"""Conform asset into a new version within a public repository"""
current_file = context.data('current_file')
@@ -6,11 +6,11 @@
@pyblish.api.log
class PostConformerFirebase(pyblish.api.Conformer):
order = pyblish.api.Conformer.order + 0.5
order = pyblish.api.Conformer.order + 0.1
families = ['*']
hosts = ['maya']
def process_context(self, context):
def process(self, context):
results = context.data("results")
endpoint = "https://pyblish.firebaseio.com/af/successes.json"
time = datetime.datetime.today().strftime("%a %b %d %H:%M:%S %Y")
@@ -30,7 +30,21 @@ class ExtractNapoleonCurves(napoleon.plugin.Extractor):
hosts = ['maya']
version = (0, 0, 1)
optional = True
name = 'Extract Animation as Curves'
label = 'Extract Animation as Curves'
def process(self, instance):
"""Overridden from Extractor"""
self.log.info("Extracting Atom..")
self.load_plugins()
options = self.options
self.override_options(options, instance=instance)
kwargs = self.file_kwargs(options)
self.log.info("Extracting {0} locally..".format(instance))
self.export(instance=instance, kwargs=kwargs)
self.log.info("Extraction successful")
@property
def options(self):
@@ -53,20 +67,6 @@ def options(self):
'-hierarchy none -controlPoints 0')
}
def process_instance(self, instance):
"""Overridden from Extractor"""
self.log.info("Extracting Atom..")
self.load_plugins()
options = self.options
self.override_options(options, instance=instance)
kwargs = self.file_kwargs(options)
self.log.info("Extracting {0} locally..".format(instance))
self.export(instance=instance, kwargs=kwargs)
self.log.info("Extraction successful")
def file_kwargs(self, options):
"""cmds.file() key-word arguments"""
return {
@@ -14,10 +14,10 @@ class ExtractNapoleonMb(napoleon.plugin.Extractor):
hosts = ['maya']
version = (0, 1, 0)
optional = False
name = 'Extract Model as Maya Binary'
label = 'Extract Model as Maya Binary'
representation = 'maya'
def process_instance(self, instance):
def process(self, instance):
"""Returns list of value and exception"""
self.log.info("Extracting mb..".format(instance))
previous_selection = cmds.ls(selection=True)
@@ -13,7 +13,7 @@ class ExtractNapoleonMetadata(napoleon.plugin.Extractor):
hosts = ['maya']
version = (0, 1, 0)
def process_instance(self, instance):
def process(self, instance):
data = dict()
for source, target in {'current_file': 'source',
@@ -16,7 +16,17 @@ class ExtractNapoleonPointcache(napoleon.plugin.Extractor):
hosts = ['maya']
version = (0, 0, 1)
optional = True
name = 'Extract Animation as Pointcache'
label = 'Extract Animation as Pointcache'
def process(self, instance):
self.log.info("Extracting Alembic..")
self.load_plugins()
options = self.default_options
options = self.parse_overrides(instance, options)
self.log.info("Extracting {0} locally..".format(instance))
self.export(instance, options)
@property
def options(self):
@@ -64,16 +74,6 @@ def default_options(self):
'frameRange': "%s %s" % (start_frame, end_frame)
}
def process_instance(self, instance):
self.log.info("Extracting Alembic..")
self.load_plugins()
options = self.default_options
options = self.parse_overrides(instance, options)
self.log.info("Extracting {0} locally..".format(instance))
self.export(instance, options)
def parse_overrides(self, instance, options):
"""Inspect data of instance to determine overridden options
@@ -36,7 +36,7 @@ class ExtractNapoleonReview(napoleon.plugin.Extractor):
representation = 'review'
def process_instance(self, instance):
def process(self, instance):
"""Extract capture per camera"""
self.log.info("Extracting capture..")
@@ -12,11 +12,11 @@ class ValidateNapoleonDefaults(pyblish.api.Validator):
families = ['napoleon.asset.rig']
hosts = ['maya']
version = (0, 1, 0)
name = "Validate Asset Defaults"
label = "Validate Asset Defaults"
CONTROLS = "controls_SEL"
def process_instance(self, instance):
def process(self, instance):
# An instance of family 'napoleon.asset.rig'
# is guaranteed to have the 'controls_SEL' objectSet.
if not cmds.objExists(self.CONTROLS):
@@ -20,7 +20,7 @@ class ValidateNapoleonAssetSets(napoleon.plugin.Validator):
hosts = ['maya']
version = (0, 0, 1)
def process_instance(self, instance):
def process(self, instance):
all_objsets = {
'napoleon.asset.model': ['geometry_SEL'],
'napoleon.asset.rig': ['pointcache_SEL',
@@ -34,7 +34,7 @@ def process_instance(self, instance):
missing = list()
for objset in objsets:
if not objset in instance:
if objset not in instance:
missing.append(objset)
if missing:
Oops, something went wrong.

0 comments on commit 4294856

Please sign in to comment.