Skip to content

Commit ad7ecbd

Browse files
committed
scripts: handle helpers being different between v2 and v2.1
1 parent b0ef14d commit ad7ecbd

File tree

2 files changed

+63
-54
lines changed

2 files changed

+63
-54
lines changed

scripts/helpers_doc_generate.py

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -27,55 +27,61 @@
2727

2828
TEMPLATE_FILE = Path(__file__).resolve().parent / "helpers_doc_template.md.j2"
2929

30-
TREE = {
31-
"sources": {
32-
"title": "Sources",
33-
"notes": "This is coupled to the 'sources' resource in the manifest.toml",
34-
"subsections": ["sources"],
35-
"helpers": {},
36-
},
37-
"tech": {
38-
"title": "App technologies",
39-
"notes": "These allow to install specific version of the technology required to run some apps",
40-
"subsections": ["nodejs", "ruby", "go", "composer"],
41-
"helpers": {},
42-
},
43-
"db": {
44-
"title": "Databases",
45-
"notes": "This is coupled to the 'database' resource in the manifest.toml - at least for mysql/postgresql. Mongodb/redis may have better integration in the future.",
46-
"subsections": ["mysql", "postgresql", "mongodb", "redis"],
47-
"helpers": {},
48-
},
49-
"conf": {
50-
"title": "Configurations / templating",
51-
"subsections": [
52-
"templating",
53-
"nginx",
54-
"php",
55-
"systemd",
56-
"fail2ban",
57-
"logrotate",
58-
],
59-
"helpers": {},
60-
},
61-
"misc": {
62-
"title": "Misc tools",
63-
"subsections": [
64-
"utils",
65-
"setting",
66-
"string",
67-
"backup",
68-
"logging",
69-
"multimedia",
70-
],
71-
"helpers": {},
72-
},
73-
"meh": {
74-
"title": "Deprecated or handled by the core / app resources since v2",
75-
"subsections": ["permission", "apt", "systemuser"],
76-
"helpers": {},
77-
},
78-
}
30+
31+
def get_helpers_tree(helpers_version: str) -> dict[str, dict]:
32+
tree = {
33+
"sources": {
34+
"title": "Sources",
35+
"notes": "This is coupled to the 'sources' resource in the manifest.toml",
36+
"subsections": ["sources"],
37+
"helpers": {},
38+
},
39+
"tech": {
40+
"title": "App technologies",
41+
"notes": "These allow to install specific version of the technology required to run some apps",
42+
"subsections": ["nodejs", "ruby", "go", "composer"],
43+
"helpers": {},
44+
},
45+
"db": {
46+
"title": "Databases",
47+
"notes": "This is coupled to the 'database' resource in the manifest.toml - at least for mysql/postgresql. Mongodb/redis may have better integration in the future.",
48+
"subsections": ["mysql", "postgresql", "mongodb", "redis"],
49+
"helpers": {},
50+
},
51+
"conf": {
52+
"title": "Configurations / templating",
53+
"subsections": [
54+
"templating",
55+
"nginx",
56+
"php",
57+
"systemd",
58+
"fail2ban",
59+
"logrotate",
60+
],
61+
"helpers": {},
62+
},
63+
"misc": {
64+
"title": "Misc tools",
65+
"subsections": [
66+
"utils",
67+
"setting",
68+
"string",
69+
"backup",
70+
"logging",
71+
"multimedia",
72+
],
73+
"helpers": {},
74+
},
75+
"meh": {
76+
"title": "Deprecated or handled by the core / app resources since v2",
77+
"subsections": ["permission", "apt", "systemuser"],
78+
"helpers": {},
79+
},
80+
}
81+
if helpers_version == "2.1":
82+
tree["misc"]["subsections"][0] = "_utils" # type: ignore
83+
84+
return tree
7985

8086

8187
def get_current_commit(docdir: Path) -> str:
@@ -269,11 +275,14 @@ def main() -> None:
269275
output = args.output if args.output else Path(f"helpers.v{args.version}.md")
270276
helpers_dir = args.input / "helpers" / f"helpers.v{args.version}.d"
271277

272-
for section in TREE.values():
278+
tree = get_helpers_tree(args.version)
279+
for section in tree.values():
273280
for subsection in section["subsections"]:
274-
print(f"Parsing {subsection} ...")
281+
print(f"Parsing {subsection}...")
275282
helper_file = helpers_dir / subsection
276-
assert helper_file.is_file(), f"Uhoh, {helper_file} doesn't exists?"
283+
if not helper_file.is_file():
284+
print(f"Uhoh, {helper_file} doesn't exists? Maybe for another helper version.")
285+
continue
277286
p = Parser(helper_file)
278287
p.parse_blocks()
279288
for b in p.blocks:
@@ -282,7 +291,7 @@ def main() -> None:
282291
section["helpers"][subsection] = p.blocks # type: ignore
283292

284293
template_data = {
285-
"tree": TREE,
294+
"tree": tree,
286295
"helpers_version": args.version,
287296
"date": datetime.datetime.now().strftime("%d/%m/%Y"),
288297
"version": get_changelog_version(args.input),

scripts/helpers_doc_template.md.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Doc auto-generated by [this script](https://github.com/YunoHost/doc/blob/{{doc_c
1717
{%- endif -%}
1818
{%- for subsection, helpers in section["helpers"].items() %}
1919

20-
### {{ subsection.upper() }}
20+
### {{ subsection.replace('_', '').upper() }}
2121
{%- for h in helpers %}
2222

2323
#### {{ h.name }}

0 commit comments

Comments
 (0)