Created
November 8, 2023 19:30
-
-
Save BigRoy/c4d2d04a799513e60a36cb2d3e91d04b to your computer and use it in GitHub Desktop.
OpenPype Extractor Mixin
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
class ExtractorMixin: | |
"""OpenPype Extractor helper methods""" | |
def add_representation(self, instance, name, | |
files, staging_dir, ext=None, | |
output_name=None, | |
frame_start=None, | |
frame_end=None, | |
colorspace=False): | |
"""Add a representation to publish and integrate. | |
A representation must exist of either a single file or a | |
single file sequence. It can *not* contain multiple files. | |
For the integration to succeed the instance must provide the context | |
for asset, frame range, etc. even though the representation can | |
override some parts of it. | |
Arguments: | |
instance (pyblish.api.Instance): Publish instance | |
name (str): The representation name | |
ext (Optional[str]): Explicit extension for the output | |
output_name (Optional[str]): Output name suffix for the | |
destination file to ensure the file is unique if | |
multiple representations share the same extension. | |
Returns: | |
dict: Representation data for integration. | |
""" | |
if ext is None: | |
# TODO: Use filename | |
ext = name | |
representation = { | |
"name": name, | |
"ext": ext, | |
"stagingDir": staging_dir, | |
"files": files | |
} | |
if output_name: | |
representation["outputName"] = output_name | |
if frame_start is not None: | |
representation["frameStart"] = int(frame_start) | |
if frame_end is not None: | |
representation["frameEnd"] = int(frame_end) | |
if colorspace is not False: | |
self.set_representation_colorspace(representation, | |
colorspace=colorspace) | |
instance.data.setdefault("representations", []).append( | |
representation | |
) | |
return representation | |
def add_transfer(self, instance, source, destination): | |
"""Add a file transfer to the integration | |
This can be used e.g. for resource files to a publish that | |
do not need to be a representation of its own and avoids | |
any publish template renaming of the files at destination. | |
Arguments | |
instance (pyblish.api.Instance): Publish instance | |
source (str): Full path to source file | |
destination (str): Full or relative path to destination | |
If destination is relative path, then it will | |
be transfered relative to instance's `publishDir` | |
Returns: | |
tuple: The registered transfer | |
""" | |
if not os.path.isabs(destination): | |
destination = os.path.join(instance.data["publishDir"], destination) | |
transfer = src, destination | |
instance.data.setdefault("transfers", []).append(transfer) | |
return transfer | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage example: