@@ -164,6 +164,7 @@ def xml_to_text(destination, xml, *, only_interface=None):
164164 file = io .StringIO ()
165165
166166 declarations = collections .defaultdict (list )
167+ interfaces = []
167168
168169 print (f'''node { destination } {{''' , file = file )
169170
@@ -173,10 +174,13 @@ def xml_to_text(destination, xml, *, only_interface=None):
173174 print_boring = print_boring ,
174175 only_interface = only_interface ,
175176 declarations = declarations )
177+ name = iface .get ('name' )
178+ if not name in BORING_INTERFACES :
179+ interfaces .append (name )
176180
177181 print (f'''}};''' , file = file )
178182
179- return file .getvalue (), declarations
183+ return file .getvalue (), declarations , interfaces
180184
181185def subst_output (document , programlisting ):
182186 try :
@@ -201,7 +205,7 @@ def subst_output(document, programlisting):
201205
202206 xml = etree .fromstring (out , parser = PARSER )
203207
204- new_text , declarations = xml_to_text (object_path , xml , only_interface = only_interface )
208+ new_text , declarations , interfaces = xml_to_text (object_path , xml , only_interface = only_interface )
205209
206210 programlisting .text = '\n ' .join (prefix_lines ) + '\n ' + new_text + footer
207211
@@ -211,9 +215,50 @@ def subst_output(document, programlisting):
211215
212216 # delete old comments
213217 for child in parent :
218+ if (child .tag == etree .Comment
219+ and 'Autogenerated' in child .text ):
220+ parent .remove (child )
214221 if (child .tag == etree .Comment
215222 and 'not documented' in child .text ):
216223 parent .remove (child )
224+ if (child .tag == "variablelist"
225+ and child .attrib .get ("generated" ,False ) == "True" ):
226+ parent .remove (child )
227+
228+ # insert pointer for systemd-directives generation
229+ the_tail = programlisting .tail #tail is erased by addnext, so save it here.
230+ prev_element = etree .Comment ("Autogenerated cross-references for systemd.directives, do not edit" )
231+ programlisting .addnext (prev_element )
232+ programlisting .tail = the_tail
233+
234+ for interface in interfaces :
235+ variablelist = etree .Element ("variablelist" )
236+ variablelist .attrib ['class' ] = 'dbus-interface'
237+ variablelist .attrib ['generated' ] = 'True'
238+ variablelist .attrib ['extra-ref' ] = interface
239+
240+ prev_element .addnext (variablelist )
241+ prev_element .tail = the_tail
242+ prev_element = variablelist
243+
244+ for decl_type ,decl_list in declarations .items ():
245+ for declaration in decl_list :
246+ variablelist = etree .Element ("variablelist" )
247+ variablelist .attrib ['class' ] = 'dbus-' + decl_type
248+ variablelist .attrib ['generated' ] = 'True'
249+ if decl_type == 'method' :
250+ variablelist .attrib ['extra-ref' ] = declaration + '()'
251+ else :
252+ variablelist .attrib ['extra-ref' ] = declaration
253+
254+ prev_element .addnext (variablelist )
255+ prev_element .tail = the_tail
256+ prev_element = variablelist
257+
258+ last_element = etree .Comment ("End of Autogenerated section" )
259+ prev_element .addnext (last_element )
260+ prev_element .tail = the_tail
261+ last_element .tail = the_tail
217262
218263 # insert comments for undocumented items
219264 for item in reversed (missing ):
0 commit comments