mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
slates can receive data though command line like burnins and it is possible to save slates metadata to json
This commit is contained in:
parent
a5d313492f
commit
3e216dc3b3
2 changed files with 55 additions and 14 deletions
|
|
@ -1,10 +1,17 @@
|
|||
import json
|
||||
from slate_base import api
|
||||
|
||||
|
||||
def main(in_args=None):
|
||||
# TODO proper argument handling
|
||||
api.example()
|
||||
data_arg = in_args[-1]
|
||||
in_data = json.loads(data_arg)
|
||||
api.create_slates(
|
||||
in_data["fill_data"],
|
||||
in_data.get("slate_name"),
|
||||
in_data.get("slate_data"),
|
||||
in_data.get("data_output_json")
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main(sys.argv)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import os
|
||||
import json
|
||||
import logging
|
||||
try:
|
||||
from queue import Queue
|
||||
|
|
@ -21,21 +23,36 @@ log = logging.getLogger(__name__)
|
|||
RequiredSlateKeys = ["width", "height", "destination_path"]
|
||||
|
||||
|
||||
def create_slates(fill_data, slate_name, slate_presets=None):
|
||||
if slate_presets is None:
|
||||
presets = get_presets()
|
||||
# TODO proper documentation
|
||||
def create_slates(
|
||||
fill_data, slate_name=None, slate_data=None, data_output_json=None
|
||||
):
|
||||
"""Implmentation for command line executing.
|
||||
|
||||
Data for slates are by defaule taken from presets. That requires to enter,
|
||||
`slate_name`. If `slate_data` are entered then they are used.
|
||||
|
||||
`data_output` should be path to json file where data will be collected.
|
||||
"""
|
||||
if slate_data is None and slate_name is None:
|
||||
raise TypeError(
|
||||
"`create_slates` expects to enter data for slates or name"
|
||||
" of slate preset."
|
||||
)
|
||||
|
||||
elif slate_data is None:
|
||||
slate_presets = (
|
||||
presets
|
||||
get_presets()
|
||||
.get("tools", {})
|
||||
.get("slates")
|
||||
) or {}
|
||||
slate_data = slate_presets.get(slate_name)
|
||||
|
||||
if not slate_data:
|
||||
log.error(
|
||||
"Name \"{}\" was not found in slate presets.".format(slate_name)
|
||||
)
|
||||
return False
|
||||
slate_data = slate_presets.get(slate_name)
|
||||
if slate_data is None:
|
||||
raise ValueError(
|
||||
"Preset name \"{}\" was not found in slate presets.".format(
|
||||
slate_name
|
||||
)
|
||||
)
|
||||
|
||||
missing_keys = []
|
||||
for key in RequiredSlateKeys:
|
||||
|
|
@ -116,3 +133,20 @@ def create_slates(fill_data, slate_name, slate_presets=None):
|
|||
|
||||
main.draw()
|
||||
log.debug("Slate creation finished")
|
||||
|
||||
if not data_output_json:
|
||||
return
|
||||
|
||||
if not data_output_json.endswith(".json"):
|
||||
raise ValueError("Output path must be .json file.")
|
||||
|
||||
data_output_json_dir = os.path.dirname(data_output_json)
|
||||
if not os.path.exists(data_output_json_dir):
|
||||
log.info("Creating folder \"{}\"".format(data_output_json_dir))
|
||||
os.makedirs(data_output_json_dir)
|
||||
|
||||
output_data = main.collect_data()
|
||||
with open(data_output_json, "w") as json_file:
|
||||
json_file.write(json.dumps(output_data, indent=4))
|
||||
|
||||
log.info("Metadata collected in \"{}\".".format(data_output_json))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue