mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 13:52:15 +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
|
||||
|
||||
|
||||
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():
|
||||
global _DEFAULT_SETTINGS
|
||||
_DEFAULT_SETTINGS = None
|
||||
|
|
@ -113,30 +131,58 @@ def load_json(fpath):
|
|||
return {}
|
||||
|
||||
|
||||
def find_environments(data):
|
||||
def find_environments(data, with_items=False, parents=None):
|
||||
if not data or not isinstance(data, dict):
|
||||
return
|
||||
return {}
|
||||
|
||||
output = {}
|
||||
if parents is None:
|
||||
parents = []
|
||||
|
||||
if M_ENVIRONMENT_KEY in data:
|
||||
metadata = data.get(M_ENVIRONMENT_KEY)
|
||||
for env_group_key, env_keys in metadata.items():
|
||||
output[env_group_key] = {}
|
||||
for key in env_keys:
|
||||
output[env_group_key][key] = data[key]
|
||||
if env_group_key not in output:
|
||||
output[env_group_key] = []
|
||||
|
||||
for value in data.values():
|
||||
result = find_environments(value)
|
||||
_env_values = {}
|
||||
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:
|
||||
continue
|
||||
|
||||
for env_group_key, env_values in result.items():
|
||||
if env_group_key not in output:
|
||||
output[env_group_key] = {}
|
||||
output[env_group_key] = []
|
||||
|
||||
for env_key, env_value in env_values.items():
|
||||
output[env_group_key][env_key] = env_value
|
||||
return output
|
||||
for env_values_item in env_values:
|
||||
output[env_group_key].append(env_values_item)
|
||||
|
||||
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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue