mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
duplicated environment group keys are checked
This commit is contained in:
parent
219515ea0e
commit
8494fd55e6
1 changed files with 57 additions and 11 deletions
|
|
@ -47,6 +47,24 @@ DEFAULTS_DIR = os.path.join(os.path.dirname(__file__), "defaults")
|
||||||
_DEFAULT_SETTINGS = None
|
_DEFAULT_SETTINGS = None
|
||||||
|
|
||||||
|
|
||||||
|
class DuplicatedEnvGroups(Exception):
|
||||||
|
def __init__(self, duplicated):
|
||||||
|
self.origin_duplicated = duplicated
|
||||||
|
self.duplicated = {}
|
||||||
|
for key, items in duplicated.items():
|
||||||
|
self.duplicated[key] = []
|
||||||
|
for item in items:
|
||||||
|
self.duplicated[key].append("/".join(item["parents"]))
|
||||||
|
|
||||||
|
msg = "Duplicated environment group keys. {}".format(
|
||||||
|
", ".join([
|
||||||
|
"\"{}\"".format(env_key) for env_key in self.duplicated.keys()
|
||||||
|
])
|
||||||
|
)
|
||||||
|
|
||||||
|
super(DuplicatedEnvGroups, self).__init__(msg)
|
||||||
|
|
||||||
|
|
||||||
def reset_default_settings():
|
def reset_default_settings():
|
||||||
global _DEFAULT_SETTINGS
|
global _DEFAULT_SETTINGS
|
||||||
_DEFAULT_SETTINGS = None
|
_DEFAULT_SETTINGS = None
|
||||||
|
|
@ -113,30 +131,58 @@ def load_json(fpath):
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
def find_environments(data):
|
def find_environments(data, with_items=False, parents=None):
|
||||||
if not data or not isinstance(data, dict):
|
if not data or not isinstance(data, dict):
|
||||||
return
|
return {}
|
||||||
|
|
||||||
output = {}
|
output = {}
|
||||||
|
if parents is None:
|
||||||
|
parents = []
|
||||||
|
|
||||||
if M_ENVIRONMENT_KEY in data:
|
if M_ENVIRONMENT_KEY in data:
|
||||||
metadata = data.get(M_ENVIRONMENT_KEY)
|
metadata = data.get(M_ENVIRONMENT_KEY)
|
||||||
for env_group_key, env_keys in metadata.items():
|
for env_group_key, env_keys in metadata.items():
|
||||||
output[env_group_key] = {}
|
if env_group_key not in output:
|
||||||
for key in env_keys:
|
output[env_group_key] = []
|
||||||
output[env_group_key][key] = data[key]
|
|
||||||
|
|
||||||
for value in data.values():
|
_env_values = {}
|
||||||
result = find_environments(value)
|
for key in env_keys:
|
||||||
|
_env_values[key] = data[key]
|
||||||
|
|
||||||
|
item = {
|
||||||
|
"env": _env_values,
|
||||||
|
"parents": parents[:-1]
|
||||||
|
}
|
||||||
|
output[env_group_key].append(item)
|
||||||
|
|
||||||
|
for key, value in data.items():
|
||||||
|
_parents = copy.deepcopy(parents)
|
||||||
|
_parents.append(key)
|
||||||
|
result = find_environments(value, True, _parents)
|
||||||
if not result:
|
if not result:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for env_group_key, env_values in result.items():
|
for env_group_key, env_values in result.items():
|
||||||
if env_group_key not in output:
|
if env_group_key not in output:
|
||||||
output[env_group_key] = {}
|
output[env_group_key] = []
|
||||||
|
|
||||||
for env_key, env_value in env_values.items():
|
for env_values_item in env_values:
|
||||||
output[env_group_key][env_key] = env_value
|
output[env_group_key].append(env_values_item)
|
||||||
return output
|
|
||||||
|
if with_items:
|
||||||
|
return output
|
||||||
|
|
||||||
|
duplicated_env_groups = {}
|
||||||
|
final_output = {}
|
||||||
|
for key, value_in_list in output.items():
|
||||||
|
if len(value_in_list) > 1:
|
||||||
|
duplicated_env_groups[key] = value_in_list
|
||||||
|
else:
|
||||||
|
final_output[key] = value_in_list[0]["env"]
|
||||||
|
|
||||||
|
if duplicated_env_groups:
|
||||||
|
raise DuplicatedEnvGroups(duplicated_env_groups)
|
||||||
|
return final_output
|
||||||
|
|
||||||
|
|
||||||
def subkey_merge(_dict, value, keys):
|
def subkey_merge(_dict, value, keys):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue