mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 05:14:40 +01:00
allow values other than paths
This commit is contained in:
parent
7197134954
commit
d8715d59d0
5 changed files with 106 additions and 49 deletions
|
|
@ -768,45 +768,49 @@ def update_houdini_vars_context():
|
|||
if houdini_vars_settings["enabled"]:
|
||||
houdini_vars = houdini_vars_settings["houdini_vars"]
|
||||
|
||||
# Remap AYON settings structure to OpenPype settings structure
|
||||
# It allows me to use the same logic for both AYON and OpenPype
|
||||
if isinstance(houdini_vars, list):
|
||||
items = {}
|
||||
for item in houdini_vars:
|
||||
items.update({item["var"]: item["path"]})
|
||||
# No vars specified - nothing to do
|
||||
if not houdini_vars:
|
||||
return
|
||||
|
||||
houdini_vars = items
|
||||
# Get Template data
|
||||
template_data = get_current_context_template_data()
|
||||
|
||||
# Set Houdini Vars
|
||||
for item in houdini_vars:
|
||||
|
||||
# For consistency reasons we always force all vars to be uppercase
|
||||
item["var"] = item["var"].upper()
|
||||
|
||||
for var, path in houdini_vars.items():
|
||||
# get and resolve job path template
|
||||
path = StringTemplate.format_template(
|
||||
path,
|
||||
get_current_context_template_data()
|
||||
item_value = StringTemplate.format_template(
|
||||
item["value"],
|
||||
template_data
|
||||
)
|
||||
path = path.replace("\\", "/")
|
||||
|
||||
if var == "JOB" and path == "":
|
||||
if item["is_path"]:
|
||||
item_value = item_value.replace("\\", "/")
|
||||
try:
|
||||
os.makedirs(item_value)
|
||||
except OSError as e:
|
||||
if e.errno != errno.EEXIST:
|
||||
print(
|
||||
" - Failed to create ${} dir. Maybe due to "
|
||||
"insufficient permissions.".format(item["var"])
|
||||
)
|
||||
|
||||
if item["var"] == "JOB" and item_value == "":
|
||||
# sync $JOB to $HIP if $JOB is empty
|
||||
path = os.environ["HIP"]
|
||||
item_value = os.environ["HIP"]
|
||||
|
||||
current_path = hou.hscript("echo -n `${}`".format(var))[0]
|
||||
current_value = hou.hscript("echo -n `${}`".format(item["var"]))[0]
|
||||
|
||||
# sync both environment variables.
|
||||
# because houdini doesn't do that by default
|
||||
# on opening new files
|
||||
os.environ[var] = current_path
|
||||
os.environ[item["var"]] = current_value
|
||||
|
||||
if current_path != path:
|
||||
hou.hscript("set {}={}".format(var, path))
|
||||
os.environ[var] = path
|
||||
if current_value != item_value:
|
||||
hou.hscript("set {}={}".format(item["var"], item_value))
|
||||
os.environ[item["var"]] = item_value
|
||||
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except OSError as e:
|
||||
if e.errno != errno.EEXIST:
|
||||
print(
|
||||
" - Failed to create {} dir. Maybe due to "
|
||||
"insufficient permissions.".format(var)
|
||||
)
|
||||
|
||||
print(" - Updated ${} to {}".format(var, path))
|
||||
print(" - Updated ${} to {}".format(item["var"], item_value))
|
||||
|
|
|
|||
|
|
@ -667,17 +667,30 @@ def get_current_context_template_data():
|
|||
"""Template data for template fill from current context
|
||||
|
||||
Returns:
|
||||
Dict[str, str] of the following tokens and their values
|
||||
- app
|
||||
- user
|
||||
- asset
|
||||
- parent
|
||||
- hierarchy
|
||||
- folder[name]
|
||||
- root[work, ...]
|
||||
- studio[code, name]
|
||||
- project[code, name]
|
||||
- task[type, name, short]
|
||||
Dict[str, Any] of the following tokens and their values
|
||||
Supported Tokens:
|
||||
- Regular Tokens
|
||||
- app
|
||||
- user
|
||||
- asset
|
||||
- parent
|
||||
- hierarchy
|
||||
- folder[name]
|
||||
- root[work, ...]
|
||||
- studio[code, name]
|
||||
- project[code, name]
|
||||
- task[type, name, short]
|
||||
|
||||
- Context Specific Tokens
|
||||
- assetData[frameStart]
|
||||
- assetData[frameEnd]
|
||||
- assetData[handleStart]
|
||||
- assetData[handleEnd]
|
||||
- assetData[frameStartHandle]
|
||||
- assetData[frameEndHandle]
|
||||
- assetData[resolutionHeight]
|
||||
- assetData[resolutionWidth]
|
||||
|
||||
"""
|
||||
|
||||
# pre-prepare get_template_data args
|
||||
|
|
@ -692,10 +705,28 @@ def get_current_context_template_data():
|
|||
task_name = current_context["task_name"]
|
||||
host_name = get_current_host_name()
|
||||
|
||||
# get template data
|
||||
# get regular template data
|
||||
template_data = get_template_data(
|
||||
project_doc, asset_doc, task_name, host_name
|
||||
)
|
||||
|
||||
template_data["root"] = anatomy.roots
|
||||
|
||||
# get context specific vars
|
||||
asset_data = asset_doc["data"].copy()
|
||||
|
||||
# compute `frameStartHandle` and `frameEndHandle`
|
||||
if "frameStart" in asset_data and "handleStart" in asset_data:
|
||||
asset_data["frameStartHandle"] = (
|
||||
asset_data["frameStart"] - asset_data["handleStart"]
|
||||
)
|
||||
|
||||
if "frameEnd" in asset_data and "handleEnd" in asset_data:
|
||||
asset_data["frameEndHandle"] = (
|
||||
asset_data["frameEnd"] + asset_data["handleEnd"]
|
||||
)
|
||||
|
||||
# add assetData
|
||||
template_data["assetData"] = asset_data
|
||||
|
||||
return template_data
|
||||
|
|
|
|||
|
|
@ -2,9 +2,13 @@
|
|||
"general": {
|
||||
"update_houdini_var_context": {
|
||||
"enabled": true,
|
||||
"houdini_vars":{
|
||||
"JOB": "{root[work]}/{project[name]}/{hierarchy}/{asset}/work/{task[name]}"
|
||||
}
|
||||
"houdini_vars":[
|
||||
{
|
||||
"var": "JOB",
|
||||
"value": "{root[work]}/{project[name]}/{hierarchy}/{asset}/work/{task[name]}",
|
||||
"is_path": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"imageio": {
|
||||
|
|
|
|||
|
|
@ -18,13 +18,29 @@
|
|||
"label": "Enabled"
|
||||
},
|
||||
{
|
||||
"type": "dict-modifiable",
|
||||
"type": "list",
|
||||
"key": "houdini_vars",
|
||||
"label": "Houdini Vars",
|
||||
"collapsible": false,
|
||||
"object_type": {
|
||||
"type": "path",
|
||||
"multiplatform": false
|
||||
"type": "dict",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"key": "var",
|
||||
"label": "Var"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"key": "value",
|
||||
"label": "Value"
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"key": "is_path",
|
||||
"label": "isPath"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ from ayon_server.settings import BaseSettingsModel
|
|||
class HoudiniVarModel(BaseSettingsModel):
|
||||
_layout = "expanded"
|
||||
var: str = Field("", title="Var")
|
||||
path: str = Field(default_factory="", title="Path")
|
||||
value: str = Field("", title="Value")
|
||||
is_path: bool = Field(False, title="isPath")
|
||||
|
||||
|
||||
class UpdateHoudiniVarcontextModel(BaseSettingsModel):
|
||||
|
|
@ -30,7 +31,8 @@ DEFAULT_GENERAL_SETTINGS = {
|
|||
"houdini_vars": [
|
||||
{
|
||||
"var": "JOB",
|
||||
"path": "{root[work]}/{project[name]}/{hierarchy}/{asset}/work/{task[name]}" # noqa
|
||||
"value": "{root[work]}/{project[name]}/{hierarchy}/{asset}/work/{task[name]}", # noqa
|
||||
"is_path": True
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue