mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
switch_item moved to fusion.lib as it's only place where is used
This commit is contained in:
parent
c116e8042b
commit
36cd349c6a
5 changed files with 84 additions and 86 deletions
|
|
@ -2,7 +2,7 @@ import sys
|
||||||
|
|
||||||
from avalon.vendor.Qt import QtGui
|
from avalon.vendor.Qt import QtGui
|
||||||
import avalon.fusion
|
import avalon.fusion
|
||||||
|
from avalon import io
|
||||||
|
|
||||||
self = sys.modules[__name__]
|
self = sys.modules[__name__]
|
||||||
self._project = None
|
self._project = None
|
||||||
|
|
@ -59,3 +59,84 @@ def get_additional_data(container):
|
||||||
return {"color": QtGui.QColor.fromRgbF(tile_color["R"],
|
return {"color": QtGui.QColor.fromRgbF(tile_color["R"],
|
||||||
tile_color["G"],
|
tile_color["G"],
|
||||||
tile_color["B"])}
|
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
|
||||||
|
|
|
||||||
|
|
@ -234,7 +234,7 @@ def switch(asset_name, filepath=None, new=True):
|
||||||
representations = []
|
representations = []
|
||||||
for container in containers:
|
for container in containers:
|
||||||
try:
|
try:
|
||||||
representation = pype.switch_item(
|
representation = fusion_lib.switch_item(
|
||||||
container,
|
container,
|
||||||
asset_name=asset_name)
|
asset_name=asset_name)
|
||||||
representations.append(representation)
|
representations.append(representation)
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ from .deprecated import (
|
||||||
from .avalon_context import (
|
from .avalon_context import (
|
||||||
is_latest,
|
is_latest,
|
||||||
any_outdated,
|
any_outdated,
|
||||||
switch_item,
|
|
||||||
get_asset,
|
get_asset,
|
||||||
get_hierarchy,
|
get_hierarchy,
|
||||||
get_linked_assets,
|
get_linked_assets,
|
||||||
|
|
@ -50,7 +49,6 @@ __all__ = [
|
||||||
|
|
||||||
"is_latest",
|
"is_latest",
|
||||||
"any_outdated",
|
"any_outdated",
|
||||||
"switch_item",
|
|
||||||
"get_asset",
|
"get_asset",
|
||||||
"get_hierarchy",
|
"get_hierarchy",
|
||||||
"get_linked_assets",
|
"get_linked_assets",
|
||||||
|
|
|
||||||
|
|
@ -62,87 +62,6 @@ def any_outdated():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
def get_asset(asset_name=None):
|
def get_asset(asset_name=None):
|
||||||
""" Returning asset document from database """
|
""" Returning asset document from database """
|
||||||
if not asset_name:
|
if not asset_name:
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,7 @@ def switch(asset_name, filepath=None, new=True):
|
||||||
representations = []
|
representations = []
|
||||||
for container in containers:
|
for container in containers:
|
||||||
try:
|
try:
|
||||||
representation = pype.switch_item(container,
|
representation = fusion_lib.switch_item(container,
|
||||||
asset_name=asset_name)
|
asset_name=asset_name)
|
||||||
representations.append(representation)
|
representations.append(representation)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue