mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 21:32:15 +01:00
moved load_jsons_from_dir
# Conflicts: # pype/settings/lib.py
This commit is contained in:
parent
d5b55f60b0
commit
8d23f491d2
1 changed files with 39 additions and 39 deletions
|
|
@ -92,7 +92,45 @@ def load_json_file(fpath):
|
|||
return {}
|
||||
|
||||
|
||||
def find_environments(data, with_items=False, parents=None):
|
||||
def load_jsons_from_dir(path, *args, **kwargs):
|
||||
output = {}
|
||||
|
||||
path = os.path.normpath(path)
|
||||
if not os.path.exists(path):
|
||||
# TODO warning
|
||||
return output
|
||||
|
||||
sub_keys = list(kwargs.pop("subkeys", args))
|
||||
for sub_key in tuple(sub_keys):
|
||||
_path = os.path.join(path, sub_key)
|
||||
if not os.path.exists(_path):
|
||||
break
|
||||
|
||||
path = _path
|
||||
sub_keys.pop(0)
|
||||
|
||||
base_len = len(path) + 1
|
||||
for base, _directories, filenames in os.walk(path):
|
||||
base_items_str = base[base_len:]
|
||||
if not base_items_str:
|
||||
base_items = []
|
||||
else:
|
||||
base_items = base_items_str.split(os.path.sep)
|
||||
|
||||
for filename in filenames:
|
||||
basename, ext = os.path.splitext(filename)
|
||||
if ext == ".json":
|
||||
full_path = os.path.join(base, filename)
|
||||
value = load_json_file(full_path)
|
||||
dict_keys = base_items + [basename]
|
||||
output = subkey_merge(output, value, dict_keys)
|
||||
|
||||
for sub_key in sub_keys:
|
||||
output = output[sub_key]
|
||||
return output
|
||||
|
||||
|
||||
def find_environments(data):
|
||||
if not data or not isinstance(data, dict):
|
||||
return {}
|
||||
|
||||
|
|
@ -159,44 +197,6 @@ def subkey_merge(_dict, value, keys):
|
|||
return _dict
|
||||
|
||||
|
||||
def load_jsons_from_dir(path, *args, **kwargs):
|
||||
output = {}
|
||||
|
||||
path = os.path.normpath(path)
|
||||
if not os.path.exists(path):
|
||||
# TODO warning
|
||||
return output
|
||||
|
||||
sub_keys = list(kwargs.pop("subkeys", args))
|
||||
for sub_key in tuple(sub_keys):
|
||||
_path = os.path.join(path, sub_key)
|
||||
if not os.path.exists(_path):
|
||||
break
|
||||
|
||||
path = _path
|
||||
sub_keys.pop(0)
|
||||
|
||||
base_len = len(path) + 1
|
||||
for base, _directories, filenames in os.walk(path):
|
||||
base_items_str = base[base_len:]
|
||||
if not base_items_str:
|
||||
base_items = []
|
||||
else:
|
||||
base_items = base_items_str.split(os.path.sep)
|
||||
|
||||
for filename in filenames:
|
||||
basename, ext = os.path.splitext(filename)
|
||||
if ext == ".json":
|
||||
full_path = os.path.join(base, filename)
|
||||
value = load_json(full_path)
|
||||
dict_keys = base_items + [basename]
|
||||
output = subkey_merge(output, value, dict_keys)
|
||||
|
||||
for sub_key in sub_keys:
|
||||
output = output[sub_key]
|
||||
return output
|
||||
|
||||
|
||||
def studio_system_settings():
|
||||
if os.path.exists(SYSTEM_SETTINGS_PATH):
|
||||
return load_json_file(SYSTEM_SETTINGS_PATH)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue