mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
feat(global): adding get_subsets() for quering all last versions of representations for subsets of given asset
This commit is contained in:
parent
30f4f13809
commit
814e7cd204
1 changed files with 69 additions and 0 deletions
69
pype/lib.py
69
pype/lib.py
|
|
@ -483,3 +483,72 @@ def filter_pyblish_plugins(plugins):
|
||||||
option, value, plugin.__name__))
|
option, value, plugin.__name__))
|
||||||
|
|
||||||
setattr(plugin, option, value)
|
setattr(plugin, option, value)
|
||||||
|
|
||||||
|
|
||||||
|
def get_subsets(asset_name,
|
||||||
|
regex_filter=None,
|
||||||
|
version="last",
|
||||||
|
representations=["exr", "dpx"]):
|
||||||
|
"""
|
||||||
|
Query subsets with filter on name.
|
||||||
|
|
||||||
|
The method will return all found subsets and its defined version and subsets. Version could be specified with number. Representation can be filtered.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
asset_name (str): asset (shot) name
|
||||||
|
regex_filter (raw): raw string with filter pattern
|
||||||
|
version (str or int): `last` or number of version
|
||||||
|
representations (list): list for all representations
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: subsets with version and representaions in keys
|
||||||
|
"""
|
||||||
|
from avalon import io
|
||||||
|
|
||||||
|
# query asset from db
|
||||||
|
asset_io = io.find_one({"type": "asset",
|
||||||
|
"name": asset_name})
|
||||||
|
|
||||||
|
# check if anything returned
|
||||||
|
assert asset_io, "Asset not existing. \
|
||||||
|
Check correct name: `{}`".format(asset_name)
|
||||||
|
|
||||||
|
# create subsets query filter
|
||||||
|
filter_query = {"type": "subset", "parent": asset_io["_id"]}
|
||||||
|
|
||||||
|
# add reggex filter string into query filter
|
||||||
|
if regex_filter:
|
||||||
|
filter_query.update({"name": {"$regex": r"{}".format(regex_filter)}})
|
||||||
|
else:
|
||||||
|
filter_query.update({"name": {"$regex": r'.*'}})
|
||||||
|
|
||||||
|
# query all assets
|
||||||
|
subsets = [s for s in io.find(filter_query)]
|
||||||
|
|
||||||
|
assert subsets, "No subsets found. Check correct filter. Try this for start `r'.*'`: asset: `{}`".format(asset_name)
|
||||||
|
|
||||||
|
output_dict = {}
|
||||||
|
# Process subsets
|
||||||
|
for subset in subsets:
|
||||||
|
if "last" in str(version):
|
||||||
|
version_sel = io.find_one({"type": "version",
|
||||||
|
"parent": subset["_id"]},
|
||||||
|
sort=[("name", -1)])
|
||||||
|
else:
|
||||||
|
version_sel = io.find_one({"type": "version",
|
||||||
|
"parent": subset["_id"],
|
||||||
|
"name": int(version)})
|
||||||
|
|
||||||
|
find_dict = {"type": "representation",
|
||||||
|
"parent": version_sel["_id"]}
|
||||||
|
|
||||||
|
filter_repr = {"$or": [{"name": repr} for repr in representations]}
|
||||||
|
|
||||||
|
find_dict.update(filter_repr)
|
||||||
|
repres_out = [i for i in io.find(find_dict)]
|
||||||
|
|
||||||
|
if len(repres_out) > 0:
|
||||||
|
output_dict[subset["name"]] = {"version": version_sel,
|
||||||
|
"representaions": repres_out}
|
||||||
|
|
||||||
|
return output_dict
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue