Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Lib from illicit part 2 #700

Merged
merged 13 commits into from
Nov 12, 2020
2 changes: 0 additions & 2 deletions pype/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
version_up,
get_asset,
get_hierarchy,
get_subsets,
get_version_from_path,
get_last_version_from_path,
modified_environ,
Expand Down Expand Up @@ -89,7 +88,6 @@
"version_up",
"get_hierarchy",
"get_asset",
"get_subsets",
"get_version_from_path",
"get_last_version_from_path",
"modified_environ",
Expand Down
83 changes: 82 additions & 1 deletion pype/hosts/fusion/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from avalon.vendor.Qt import QtGui
import avalon.fusion

from avalon import io

self = sys.modules[__name__]
self._project = None
Expand Down Expand Up @@ -59,3 +59,84 @@ def get_additional_data(container):
return {"color": QtGui.QColor.fromRgbF(tile_color["R"],
tile_color["G"],
tile_color["B"])}


def switch_item(container,
asset_name=None,
subset_name=None,
representation_name=None):
"""Switch container asset, subset or representation of a container by name.

It'll always switch to the latest version - of course a different
approach could be implemented.

Args:
container (dict): data of the item to switch with
asset_name (str): name of the asset
subset_name (str): name of the subset
representation_name (str): name of the representation

Returns:
dict

"""

if all(not x for x in [asset_name, subset_name, representation_name]):
raise ValueError("Must have at least one change provided to switch.")

# Collect any of current asset, subset and representation if not provided
# so we can use the original name from those.
if any(not x for x in [asset_name, subset_name, representation_name]):
_id = io.ObjectId(container["representation"])
representation = io.find_one({"type": "representation", "_id": _id})
version, subset, asset, project = io.parenthood(representation)

if asset_name is None:
asset_name = asset["name"]

if subset_name is None:
subset_name = subset["name"]

if representation_name is None:
representation_name = representation["name"]

# Find the new one
asset = io.find_one({
"name": asset_name,
"type": "asset"
})
assert asset, ("Could not find asset in the database with the name "
"'%s'" % asset_name)

subset = io.find_one({
"name": subset_name,
"type": "subset",
"parent": asset["_id"]
})
assert subset, ("Could not find subset in the database with the name "
"'%s'" % subset_name)

version = io.find_one(
{
"type": "version",
"parent": subset["_id"]
},
sort=[('name', -1)]
)

assert version, "Could not find a version for {}.{}".format(
asset_name, subset_name
)

representation = io.find_one({
"name": representation_name,
"type": "representation",
"parent": version["_id"]}
)

assert representation, ("Could not find representation in the database "
"with the name '%s'" % representation_name)

avalon.api.switch(container, representation)

return representation
2 changes: 1 addition & 1 deletion pype/hosts/fusion/scripts/fusion_switch_shot.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def switch(asset_name, filepath=None, new=True):
representations = []
for container in containers:
try:
representation = pype.switch_item(
representation = fusion_lib.switch_item(
container,
asset_name=asset_name)
representations.append(representation)
Expand Down
33 changes: 22 additions & 11 deletions pype/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
set_io_database
)

from .avalon_context import (
is_latest,
any_outdated,
get_asset,
get_hierarchy,
get_linked_assets,
get_latest_version,
BuildWorkfile
)

from .hooks import PypeHook, execute_hook

from .applications import (
Expand All @@ -20,38 +30,39 @@
_subprocess,
get_paths_from_environ,
get_ffmpeg_tool_path,
get_hierarchy,
add_tool_to_environment,
modified_environ,
pairwise,
grouper,
is_latest,
any_outdated,
_rreplace,
version_up,
switch_item,
_get_host_name,
get_asset,
get_version_from_path,
get_last_version_from_path,
get_subsets,
get_linked_assets,
BuildWorkfile,
ffprobe_streams,
source_hash,
get_latest_version
)
from .ffmpeg_utils import ffprobe_streams

__all__ = [
"get_avalon_database",
"set_io_database",

"is_latest",
"any_outdated",
"get_asset",
"get_hierarchy",
"get_linked_assets",
"get_latest_version",
"BuildWorkfile",

"PypeHook",
"execute_hook",

"ApplicationLaunchFailed",
"launch_application",
"ApplicationAction",

"filter_pyblish_plugins"
"filter_pyblish_plugins",

"ffprobe_streams"
]
Loading