-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdocs_macros.py
72 lines (60 loc) · 2.2 KB
/
docs_macros.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import sys
from unittest.mock import Mock
_django_settings = None
def get_django_settings():
global _django_settings
if _django_settings is None:
sys.path.append("app/app")
# Mock out imports
sys.modules.update(
{
"django.utils.safestring": Mock(mark_safe=lambda s: s),
"environ": Mock(Env=lambda: Mock(bool=lambda *args, **kwargs: True)),
}
)
from crazyarms import settings
_django_settings = settings
return _django_settings
def get_constance_config_type(default, type_hint=None):
types_to_string = {
int: "Integer",
float: "Decimal",
bool: "Boolean (true or false)",
str: "String",
}
type_hints_to_string = {
"clearable_file": "File",
"email": "Email Address",
"nonzero_positive_int": "Integer (non-zero)",
"positive_float": "Decimal (non-negative)",
"positive_int": "Integer (non-negative)",
"required_char": "String (required)",
"station_name": "String (required, 40 characters max)",
"zoom_minutes": "Integer (number of minutes)",
}
settings = get_django_settings()
for choice_field in (
"asset_bitrate_choices",
"asset_encoding_choices",
"autodj_requests_choices",
):
choices = settings.CONSTANCE_ADDITIONAL_FIELDS[choice_field][1]["choices"]
type_hints_to_string[
choice_field
] = f'Choice of: {", ".join(choice for _, choice in choices)}'
if type_hint is None or type_hint not in type_hints_to_string:
return types_to_string[type(default)]
else:
return type_hints_to_string[type_hint]
def get_constance_config_default(name, default):
if name == 'ICECAST_ADMIN_EMAIL':
default = '[email protected]'
return repr(default)
def define_env(env):
env.variables["DJANGO_SETTINGS"] = get_django_settings()
with open("LICENSE", "r") as license:
env.variables["LICENSE"] = license.read()
with open(".default.env", "r") as default_env:
env.variables["DEFAULT_ENV"] = default_env.read()
env.macro(get_constance_config_type)
env.macro(get_constance_config_default)