mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
83 lines
2.4 KiB
Python
83 lines
2.4 KiB
Python
import os
|
|
import json
|
|
|
|
from .constants import CUST_ATTR_GROUP
|
|
|
|
|
|
def default_custom_attributes_definition():
|
|
json_file_path = os.path.join(
|
|
os.path.dirname(os.path.abspath(__file__)),
|
|
"custom_attributes.json"
|
|
)
|
|
with open(json_file_path, "r") as json_stream:
|
|
data = json.load(json_stream)
|
|
return data
|
|
|
|
|
|
def app_definitions_from_app_manager(app_manager):
|
|
_app_definitions = []
|
|
for app_name, app in app_manager.applications.items():
|
|
if app.enabled and app.is_host:
|
|
_app_definitions.append(
|
|
(app_name, app.full_label)
|
|
)
|
|
|
|
# Sort items by label
|
|
app_definitions = []
|
|
for key, label in sorted(_app_definitions, key=lambda item: item[1]):
|
|
app_definitions.append({key: label})
|
|
|
|
if not app_definitions:
|
|
app_definitions.append({"empty": "< Empty >"})
|
|
return app_definitions
|
|
|
|
|
|
def tool_definitions_from_app_manager(app_manager):
|
|
_tools_data = []
|
|
for tool_name, tool in app_manager.tools.items():
|
|
_tools_data.append(
|
|
(tool_name, tool.label)
|
|
)
|
|
|
|
# Sort items by label
|
|
tools_data = []
|
|
for key, label in sorted(_tools_data, key=lambda item: item[1]):
|
|
tools_data.append({key: label})
|
|
|
|
# Make sure there is at least one item
|
|
if not tools_data:
|
|
tools_data.append({"empty": "< Empty >"})
|
|
return tools_data
|
|
|
|
|
|
def get_openpype_attr(session, split_hierarchical=True, query_keys=None):
|
|
custom_attributes = []
|
|
hier_custom_attributes = []
|
|
if not query_keys:
|
|
query_keys = [
|
|
"id",
|
|
"entity_type",
|
|
"object_type_id",
|
|
"is_hierarchical",
|
|
"default"
|
|
]
|
|
# TODO remove deprecated "pype" group from query
|
|
cust_attrs_query = (
|
|
"select {}"
|
|
" from CustomAttributeConfiguration"
|
|
# Kept `pype` for Backwards Compatiblity
|
|
" where group.name in (\"pype\", \"{}\")"
|
|
).format(", ".join(query_keys), CUST_ATTR_GROUP)
|
|
all_avalon_attr = session.query(cust_attrs_query).all()
|
|
for cust_attr in all_avalon_attr:
|
|
if split_hierarchical and cust_attr["is_hierarchical"]:
|
|
hier_custom_attributes.append(cust_attr)
|
|
continue
|
|
|
|
custom_attributes.append(cust_attr)
|
|
|
|
if split_hierarchical:
|
|
# return tuple
|
|
return custom_attributes, hier_custom_attributes
|
|
|
|
return custom_attributes
|