Skip to content

Commit a328a91

Browse files
committed
docs: add links to component list + generate links by script
1 parent 5d091b7 commit a328a91

3 files changed

Lines changed: 225 additions & 174 deletions

File tree

docs/src/Submakefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ copy_asciidoc_files:
360360

361361
gen_complist:
362362
python3 $(DOC_SRCDIR)/gen_complist.py
363+
touch $(DOC_SRCDIR)/hal/components.adoc
364+
365+
.PHONY gen_complist_links:
366+
python3 $(DOC_SRCDIR)/gen_complist.py links
363367

364368
checkref: checkref_en checkref_de checkref_es checkref_fr checkref_hu checkref_nb checkref_vi checkref_zh_CN
365369

docs/src/gen_complist.py

Lines changed: 97 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,114 @@
11
#!/usr/bin/env python3
2-
# This file compares the entries in the component list (components.adoc) with the
3-
# available man pages and adds a tables for missing components.
2+
# generate_complist()
3+
# Compares the entries in the component list (components.adoc) with the
4+
# available man pages and adds tables for missing components.
5+
# generate_links()
6+
# Generates a copy of components.adoc with added links to the man pages for the components.
47

58
from os import listdir
69
from os.path import isfile, join
10+
import re
11+
import sys
712

813
man1_path = '../docs/html/man/man1'
914
man1_files = {f.replace('.1.html', '') for f in listdir(man1_path) if isfile(join(man1_path, f))}
1015
man9_path = '../docs/html/man/man9'
1116
man9_files = {f.replace('.9.html', '') for f in listdir(man9_path) if isfile(join(man9_path, f))}
12-
13-
file1 = open('../docs/src/hal/components.adoc', 'r')
14-
section_switch = '[[sec:realtime-components]]'
17+
man = [man1_files,man9_files]
1518
doc1 = set()
1619
doc9 = set()
1720
components = [doc1,doc9]
18-
comp_index = 0
19-
for line in file1:
20-
if section_switch in line:
21-
comp_index = 1
22-
23-
if line[0] == '|' and line[1] != '=':
24-
line = line.split('|')
25-
if line[1].strip() != '':
26-
components[comp_index].add(line[1].strip())
27-
#print(line[1].strip(), "-->", comp_index)
21+
section_switch = '[[sec:realtime-components]]'
22+
complist_path = '../docs/src/hal/components.adoc'
23+
24+
def generate_complist():
25+
file1 = open(complist_path, 'r')
26+
comp_index = 0
27+
for line in file1:
28+
if section_switch in line:
29+
comp_index = 1
30+
31+
if line[0] == '|' and line[1] != '=':
32+
splitted = line.split('|')
33+
if splitted[1].strip() != '':
34+
if 'link:' in splitted[1]:
35+
comp = re.search('\[.*\]', splitted[1]).group()
36+
else:
37+
comp = splitted[1]
38+
components[comp_index].add(comp.strip('[] '))
39+
40+
file1.close()
41+
miss1 = man1_files.difference(doc1)
42+
obs1 = doc1.difference(man1_files)
43+
miss9 = man9_files.difference(doc9)
44+
obs9 = doc9.difference(man9_files)
45+
46+
file2 = open('../docs/src/hal/components_gen1.adoc', 'w')
47+
if len(miss1) > 0:
48+
file2.write('=== Not categorized (auto generated)\n')
49+
file2.write('[{tab_options}]\n|=======================\n')
50+
for i in sorted(miss1):
51+
file2.write('| ' + i + ' |||\n')
52+
file2.write('|=======================\n')
53+
if len(obs1) > 0:
54+
file2.write('\n=== Obsolete (auto generated)\n')
55+
file2.write('[{tab_options}]\n|=======================\n')
56+
for i in sorted(obs1):
57+
file2.write('| ' + i + ' |||\n')
58+
file2.write('|=======================\n')
59+
file2.close()
60+
61+
file3 = open('../docs/src/hal/components_gen9.adoc', 'w')
62+
if len(miss9) > 0:
63+
file3.write('=== Not categorized (auto generated)\n')
64+
file3.write('[{tab_options}]\n|=======================\n')
65+
for i in sorted(miss9):
66+
file3.write('| ' + i + ' |||\n')
67+
file3.write('|=======================\n')
68+
if len(obs9) > 0:
69+
file3.write('\n=== Obsolete (auto generated)\n')
70+
file3.write('[{tab_options}]\n|=======================\n')
71+
for i in sorted(obs9):
72+
file3.write('| ' + i + ' |||\n')
73+
file3.write('|=======================\n')
74+
file3.close()
75+
76+
print('gen_complist: Added {} uncategorized and {} obsolete entries to hal component list (man1)'.format(len(miss1), len(obs1)))
77+
print('gen_complist: Added {} uncategorized and {} obsolete entries to hal component list (man9)'.format(len(miss9), len(obs9)))
78+
79+
80+
def generate_links():
81+
file1 = open(complist_path, 'r')
82+
file1_links = open('../docs/src/hal/components_links.adoc', 'w')
83+
comp_index = 0
84+
manpage = '1'
85+
for line in file1:
86+
if section_switch in line:
87+
comp_index = 1
88+
manpage = '9'
89+
90+
if line[0] == '|' and line[1] != '=':
91+
splitted = line.split('|')
92+
93+
if 'link:' in splitted[1]:
94+
link = re.search('(?<=link:).*(?=\[)', splitted[1]).group()
95+
if not isfile(join('../docs/html/hal',link)):
96+
print('broken link:', link)
97+
else:
98+
comp = splitted[1].strip(' ')
99+
if comp in man[comp_index]:
100+
line = line.replace(comp, 'link:../man/man'+manpage+'/'+comp+'.'+manpage+'.html['+comp+']', 1)
28101

29-
file1.close()
102+
file1_links.write(line)
30103

31-
miss1 = man1_files.difference(doc1)
32-
obs1 = doc1.difference(man1_files)
33-
miss9 = man9_files.difference(doc9)
34-
obs9 = doc9.difference(man9_files)
104+
file1.close()
105+
file1_links.close()
35106

36-
file2 = open('../docs/src/hal/components_gen1.adoc', 'w')
37-
if len(miss1) > 0:
38-
file2.write('=== Not categorized (auto generated)\n')
39-
file2.write('[{tab_options}]\n|=======================\n')
40-
for i in sorted(miss1):
41-
file2.write('| ' + i + ' |||\n')
42-
file2.write('|=======================\n')
43-
if len(obs1) > 0:
44-
file2.write('\n=== Obsolete (auto generated)\n')
45-
file2.write('[{tab_options}]\n|=======================\n')
46-
for i in sorted(obs1):
47-
file2.write('| ' + i + ' |||\n')
48-
file2.write('|=======================\n')
49-
file2.close()
107+
if __name__ == "__main__":
50108

51-
file3 = open('../docs/src/hal/components_gen9.adoc', 'w')
52-
if len(miss9) > 0:
53-
file3.write('=== Not categorized (auto generated)\n')
54-
file3.write('[{tab_options}]\n|=======================\n')
55-
for i in sorted(miss9):
56-
file3.write('| ' + i + ' |||\n')
57-
file3.write('|=======================\n')
58-
if len(obs9) > 0:
59-
file3.write('\n=== Obsolete (auto generated)\n')
60-
file3.write('[{tab_options}]\n|=======================\n')
61-
for i in sorted(obs9):
62-
file3.write('| ' + i + ' |||\n')
63-
file3.write('|=======================\n')
64-
file3.close()
109+
if len(sys.argv) > 1:
110+
if sys.argv[1] == 'links':
111+
generate_links()
65112

66-
print('gen_complist: Added {} uncategorized and {} obsolete entries to hal component list (man1)'.format(len(miss1), len(obs1)))
67-
print('gen_complist: Added {} uncategorized and {} obsolete entries to hal component list (man9)'.format(len(miss9), len(obs9)))
113+
else:
114+
generate_complist()

0 commit comments

Comments
 (0)