-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration.py
44 lines (35 loc) · 1.12 KB
/
configuration.py
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
34
35
36
37
38
39
40
41
42
43
44
from json import load
from constants import ENCODING
COMPILE_FILE_KEY = "compile_file"
TEMP_DIRECTORY_KEY = "temp_directory"
PUBLIC_DIRECTORY_KEY = "public_directory"
RESOURCES_DIRECTORY_KEY = "resources_directory"
DEBUG_KEY = "debug"
default_configuration = {
COMPILE_FILE_KEY: "./compile_file.py",
TEMP_DIRECTORY_KEY: "./temp/",
PUBLIC_DIRECTORY_KEY: "./public/",
RESOURCES_DIRECTORY_KEY: "__resources__",
DEBUG_KEY: False
}
def get_configuration(key: str):
"""
Gets a configuration value by key.
:param key: The key to get the value for.
:return: The value.
"""
json = {}
configuration_locations = [".statifyconfig", "config/.statifyconfig"]
for location in configuration_locations:
try:
with open(location, 'r', encoding=ENCODING) as file:
json = load(file)
break
except FileNotFoundError:
pass
if key in json:
return json[key]
elif key in default_configuration:
return default_configuration[key]
else:
raise ValueError("Key wasn't found in the configuration dictionary.")