-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_reader.py
More file actions
33 lines (26 loc) · 1.02 KB
/
config_reader.py
File metadata and controls
33 lines (26 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import json
import os
from django.conf import settings
def read_config_from_json(resource_type: str) -> dict:
"""
Read the metadata fields configuration from a json file for a specific resource type.
:param resource_type: The type of resource for which the configuration is being read.
:return: The JSON content of the configuration file for the specified resource type.
"""
fields_file = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
"custom_metadata",
"metadata_fields",
f"{resource_type}_fields.json",
)
if hasattr(settings, "CUSTOM_METADATA_CONFIG_DIR"):
fields_file = os.path.join(
settings.CUSTOM_METADATA_CONFIG_DIR,
f"{resource_type}_fields.json",
)
try:
with open(fields_file, "r") as f:
json_file_content = json.load(f)
return json_file_content
except FileNotFoundError:
raise FileNotFoundError(f"Could not find the config file for {resource_type} in {fields_file}.")