11#!/usr/bin/env python3
22# generate_complist()
3- # Compares the entries in the component list (components.adoc) with the
3+ # Compares the entries in the component list (components.adoc) with the
44# available man pages and adds tables for missing components.
55# generate_links()
66# Generates a copy of components.adoc with added links to the man pages for the components.
1010import sys
1111
1212man1_path = '../docs/man/man1'
13- man1_files = {f . replace ( '.1' , '' ) for f in os .listdir (man1_path ) if os .path .isfile (os .path .join (man1_path , f ))}
13+ man1_files = {f for f in os .listdir (man1_path ) if os .path .isfile (os .path .join (man1_path , f ))}
1414man9_path = '../docs/man/man9'
15- man9_files = {f .replace ('.9' , '' ) for f in os .listdir (man9_path ) if os .path .isfile (os .path .join (man9_path , f ))}
16- man = {'1' :man1_files , '9' :man9_files }
17- doc1 = set ()
18- doc9 = set ()
19- components = {'1' :doc1 , '9' :doc9 }
20- section_switch = '[[sec:realtime-components]]'
15+ man9_files = {f for f in os .listdir (man9_path ) if os .path .isfile (os .path .join (man9_path , f ))}
16+ man_files = man1_files .union (man9_files )
17+ complist_doc = set ()
18+ miss_in_man = set ()
2119# complist_path = '../docs/src/hal/components.adoc'
2220
2321def generate_complist (complist_path ):
2422 file1 = open (complist_path , 'r' )
25- manpage = '1'
2623 for line in file1 :
27- if section_switch in line :
28- manpage = '9'
29-
3024 if line [0 ] == '|' and line [1 ] != '=' :
3125 splitted = line .split ('|' )
3226 if splitted [1 ].strip () != '' :
3327 if 'link:' in splitted [1 ]:
34- comp = re .search ('\[.*\]' , splitted [1 ]).group ()
28+ link = re .search ('(?<=link:).*(?=\\ [)' , splitted [1 ]).group ()
29+ comp_man = re .search ("[a-zA-Z0-9-_\\ .]+(?=\\ .html)" , link ).group ()
30+ if os .path .isfile (os .path .join ('../docs/html/hal' ,link )):
31+ complist_doc .add (comp_man )
32+ else :
33+ print ('gen_complist: Broken link:' , link , file = sys .stderr )
34+ miss_in_man .add (comp_man .split ("." )[0 ])
3535 else :
36- comp = splitted [1 ]
37- components [manpage ].add (comp .strip ('[] ' ))
38-
36+ print ("gen_complist: Component" , splitted [1 ], "without link" )
37+ miss_in_man .add (splitted [1 ])
3938 file1 .close ()
40- miss1 = man1_files .difference (doc1 )
41- obs1 = doc1 .difference (man1_files )
42- miss9 = man9_files .difference (doc9 )
43- obs9 = doc9 .difference (man9_files )
44- gen1_filename = '../docs/src/hal/components_gen1.adoc'
45- file2 = open (gen1_filename , 'w' )
46- if len (miss1 ) > 0 :
47- file2 .write ('=== Not categorized (auto generated)\n ' )
39+ miss_in_list = man_files .difference (complist_doc )
40+
41+ gen_filename = '../docs/src/hal/components_gen.adoc'
42+ file2 = open (gen_filename , 'w' )
43+ if len (miss_in_list ) > 0 :
44+ file2 .write ('=== Not categorized (auto generated from man pages)\n ' )
4845 file2 .write ('[{tab_options}]\n |=======================\n ' )
49- for i in sorted (miss1 ):
46+ for i in sorted (miss_in_list ):
5047 file2 .write ('| ' + i + ' |||\n ' )
5148 file2 .write ('|=======================\n ' )
52- if len (obs1 ) > 0 :
53- file2 .write ('\n === Without man page (auto generated)\n ' )
49+ if len (miss_in_man ) > 0 :
50+ file2 .write ('\n === Without man page or broken link (auto generated from component list )\n ' )
5451 file2 .write ('[{tab_options}]\n |=======================\n ' )
55- for i in sorted (obs1 ):
52+ for i in sorted (miss_in_man ):
5653 file2 .write ('| ' + i + ' |||\n ' )
5754 file2 .write ('|=======================\n ' )
5855 file2 .close ()
59- gen9_filename = '../docs/src/hal/components_gen9.adoc'
60- file3 = open (gen9_filename , 'w' )
61- if len (miss9 ) > 0 :
62- file3 .write ('=== Not categorized (auto generated)\n ' )
63- file3 .write ('[{tab_options}]\n |=======================\n ' )
64- for i in sorted (miss9 ):
65- file3 .write ('| ' + i + ' |||\n ' )
66- file3 .write ('|=======================\n ' )
67- if len (obs9 ) > 0 :
68- file3 .write ('\n === Without man page (auto generated)\n ' )
69- file3 .write ('[{tab_options}]\n |=======================\n ' )
70- for i in sorted (obs9 ):
71- file3 .write ('| ' + i + ' |||\n ' )
72- file3 .write ('|=======================\n ' )
73- file3 .close ()
74-
75- generate_links (gen1_filename , '1' , False , True )
76- generate_links (gen9_filename , '9' , False , True )
7756
78- print ( 'gen_complist: Added {} uncategorized and {} obsolete entries to hal component list (man1)' . format ( len ( miss1 ), len ( obs1 )) )
79- print ('gen_complist: Added {} uncategorized and {} obsolete entries to hal component list (man9) ' .format (len (miss9 ), len (obs9 )))
57+ generate_links ( gen_filename , False , True )
58+ print ('gen_complist: Added {} uncategorized and {} obsolete entries to hal component list' .format (len (miss_in_list ), len (miss_in_man )))
8059
8160
82- def generate_links (filename , manpage = '1' , create_backup = True , add_descr = False ):
61+ def generate_links (filename , create_backup = True , add_descr = False ):
8362 file = open (filename , 'r' )
8463 file_links = []
8564 links_added = 0
8665 for line in file :
87- if section_switch in line :
88- manpage = '9'
89-
9066 if line [0 ] == '|' and line [1 ] != '=' :
9167 splitted = line .split ('|' )
9268
@@ -95,22 +71,22 @@ def generate_links(filename, manpage='1', create_backup=True, add_descr=False):
9571 if not os .path .isfile (os .path .join ('../docs/html/hal' ,link )):
9672 print ('gen_complist_link: Broken link:' , link )
9773 else :
98- comp = splitted [1 ].strip (' ' )
99- if comp in man [manpage ]:
100- line = line .replace (comp , 'link:../man/man' + manpage + '/' + comp + '.' + manpage + '.html[' + comp + ']' , 1 )
74+ comp_man = splitted [1 ].strip (' ' )
75+ if comp_man in man_files :
76+ comp , man = comp_man .split ("." )
77+ line = line .replace (comp_man , 'link:../man/man' + man + '/' + comp_man + '.html[' + comp + ']' , 1 )
10178 links_added += 1
10279 if add_descr :
10380 splitted = line .split ('|' )
104- splitted [2 ] = extract_descr ('../docs/man/man' + manpage + '/' + comp + '.' + manpage )\
81+ splitted [2 ] = extract_descr ('../docs/man/man' + man + '/' + comp_man )\
10582 .replace (comp + ' ' , ' ' ,1 ).strip ('\n -' )
10683 line = '|' .join (splitted )
10784 file_links .append (line )
108-
10985 file .close ()
11086
11187 if links_added :
11288 if create_backup :
113- os .rename (filename , filename + '~' )
89+ os .rename (filename , filename + '~' )
11490 file = open (filename , 'w' )
11591 for line in file_links :
11692 file .write (line )
@@ -122,7 +98,7 @@ def extract_descr(filename):
12298 file = open (filename , 'r' )
12399 descr = ''
124100 in_descr = False
125-
101+
126102 for line in file :
127103 if '.SH NAME' in line or '.SH "NAME' in line :
128104 in_descr = True
0 commit comments