-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator_general.py
145 lines (123 loc) · 4.39 KB
/
generator_general.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
"""
Readme generator for ShotGrid frameworks/engines/apps
"""
from pathlib import Path
import yaml
import utils
def generate_general_readme(
filepath: Path, prepend: str = None, append: str = None
) -> str:
"""
Generate a readme file for a ShotGrid framework/engine/app
Args:
filepath: File path to info.yml
prepend: File path to Markdown file to prepend in Readme
append: File path to Markdown file to append in Readme
Returns:
Markdown readme
"""
with open(str(filepath), "r") as file:
info = yaml.safe_load(file)
readme = ""
readme += utils.get_header(info, filepath)
# Prepend readme file
if prepend is not None and prepend != "":
prepend_filepath = Path(prepend)
if prepend_filepath.is_file():
with open(prepend_filepath, "r") as prepend_file:
readme += prepend_file.read()
readme += "\n\n"
readme += "## Requirements\n\n"
readme += utils.get_general_requirements(info)
if (
"requires_shotgun_fields" in info
and info["requires_shotgun_fields"] is not None
):
readme += "### ShotGrid fields:\n\n"
for key, value in info["requires_shotgun_fields"].items():
readme += f"**{key}:**\n"
for field in value:
readme += f"- {field['system_name']} `{field['type']}`\n"
readme += "\n"
if "frameworks" in info and info["frameworks"] is not None:
readme += "**Frameworks:**\n\n"
readme += utils.make_table(
["Name", "Version", "Minimum version"],
list(
map(
lambda framework: [
framework["name"],
framework["version"],
framework.get("minimum_version", ""),
],
info["frameworks"],
)
),
)
readme += "\n\n"
config_names = {
"str": "Strings",
"int": "Integers",
"bool": "Booleans",
"dict": "Dictionaries",
"list": "Lists",
"config_path": "Config paths",
"template": "Templates",
"publish_type": "Publish types",
"hook": "Hooks",
"shotgun_entity_type": "ShotGrid entity types",
"shotgun_permission_group": "ShotGrid permission groups",
"shotgun_filter": "ShotGrid filters",
"tank_type": "Tank types",
}
if "configuration" in info and info["configuration"] is not None:
readme += "## Configuration\n\n"
config = {}
for key, value in info["configuration"].items():
config_item = {**value, "name": key}
if "default_value" not in config_item:
config_item["default_value"] = ""
if value["type"] not in config:
config[value["type"]] = [config_item]
else:
config[value["type"]] += [config_item]
for key, value in config.items():
name = key
if key in config_names:
name = config_names[key]
readme += f"### {name}\n\n"
cols = ["Name", "Description", "Default value"]
if key == "template":
cols.append("Fields")
rows = list(
map(
lambda item: [
f"`{item['name']}`",
item.get("description", ""),
item.get("default_value", ""),
item.get("fields", ""),
],
value,
)
)
else:
rows = list(
map(
lambda item: [
f"`{item['name']}`",
item.get("description", ""),
f'{item.get("default_value", "")}',
],
value,
)
)
readme += utils.make_table(cols, rows)
readme += "\n"
# Append readme file
if append is not None and append != "":
append_filepath = Path(append)
if append_filepath.is_file():
with open(append_filepath, "r") as append_file:
readme += "\n\n"
readme += append_file.read()
return readme