Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(561)

Side by Side Diff: native_client_sdk/src/doc/doxygen/doxy_cleanup.py

Issue 591683002: [NaCl SDK Docs] Fix many issues with the doc generator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 '''This utility cleans up the html files as emitted by doxygen so 7 '''This utility cleans up the html files as emitted by doxygen so
8 that they are suitable for publication on a Google documentation site. 8 that they are suitable for publication on a Google documentation site.
9 ''' 9 '''
10 10
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 table_index = table_parent.contents.index(table) 129 table_index = table_parent.contents.index(table)
130 table_parent.insert(table_index, tag) 130 table_parent.insert(table_index, tag)
131 131
132 def RemoveTopHeadings(self): 132 def RemoveTopHeadings(self):
133 '''Removes <div> sections with a header, tabs, or navpath class attribute''' 133 '''Removes <div> sections with a header, tabs, or navpath class attribute'''
134 header_tags = self.soup.findAll( 134 header_tags = self.soup.findAll(
135 name='div', 135 name='div',
136 attrs={'class' : re.compile('^(header|tabs[0-9]*|navpath)$')}) 136 attrs={'class' : re.compile('^(header|tabs[0-9]*|navpath)$')})
137 [tag.extract() for tag in header_tags] 137 [tag.extract() for tag in header_tags]
138 138
139 def RemoveSeparators(self):
140 '''Removes separator rows from tables
141
142 This seems to only exist in newer versions of doxygen (1.8).
143 '''
144 separator_tags = self.soup.findAll(
145 name='tr',
146 attrs={'class': re.compile(r'^separator:.*$')})
147 [tag.extract() for tag in separator_tags]
148
149 def FixFragments(self):
150 ''''''
Sam Clegg 2014/09/20 00:02:36 Is this also a doxygen version thing? Maybe menti
binji 2014/09/22 17:54:02 Done.
151 first = True
152 fragments = self.soup.findAll(name='div', attrs={'class': 'fragment'})
153 for fragment in fragments:
154 # Replace:
155 # <div class="fragment">
156 # <div class="line">...</div>
157 #
158 # With:
159 # <div class="fragment">
160 # ...
161 lines = fragment.findAll(name='div', attrs={'class': 'line'})
162 for line in lines:
163 line.replaceWithChildren()
164
165 # Wrap the contents of the fragment in a <pre>, but only if it isn't
166 # already there.
167 if not fragment.pre:
168 pre = Tag(self.soup, name='pre', attrs={'class': 'fragment'})
169 for el in reversed(fragment.contents):
170 pre.insert(0, el.extract())
171 fragment.append(pre)
172
139 def RemoveVersionNumbers(self, html): 173 def RemoveVersionNumbers(self, html):
140 '''Horrible hack to strip _#_# from struct names.''' 174 '''Horrible hack to strip _#_# from struct names.'''
141 return re.sub(r'(_\d_\d)(?=[": <])', '', html) 175 return re.sub(r'(_\d_\d)(?=[": <])', '', html)
142 176
143 def FixAll(self): 177 def FixAll(self):
144 self.FixTableHeadings() 178 self.FixTableHeadings()
145 self.RemoveTopHeadings() 179 self.RemoveTopHeadings()
180 self.RemoveSeparators()
181 self.FixFragments()
146 html = str(self.soup) 182 html = str(self.soup)
147 html = self.RemoveVersionNumbers(html) 183 html = self.RemoveVersionNumbers(html)
148 return html 184 return html
149 185
150 186
151 def main(argv): 187 def main(argv):
152 """Main entry for the doxy_cleanup utility 188 """Main entry for the doxy_cleanup utility
153 189
154 doxy_cleanup cleans up the html files generated by doxygen. 190 doxy_cleanup cleans up the html files generated by doxygen.
155 """ 191 """
(...skipping 26 matching lines...) Expand all
182 for wildcard in FILES_TO_REMOVE: 218 for wildcard in FILES_TO_REMOVE:
183 Trace('Removing "%s":' % wildcard) 219 Trace('Removing "%s":' % wildcard)
184 path = os.path.join(root_dir, wildcard) 220 path = os.path.join(root_dir, wildcard)
185 for filename in glob.glob(path): 221 for filename in glob.glob(path):
186 Trace(' Removing "%s"' % filename) 222 Trace(' Removing "%s"' % filename)
187 os.remove(filename) 223 os.remove(filename)
188 224
189 # Now, fix the HTML files we've kept. 225 # Now, fix the HTML files we've kept.
190 Trace('Fixing HTML files...') 226 Trace('Fixing HTML files...')
191 for root, _, files in os.walk(root_dir): 227 for root, _, files in os.walk(root_dir):
228 files.sort()
192 for filename in files: 229 for filename in files:
193 if not os.path.splitext(filename)[1] == '.html': 230 if not os.path.splitext(filename)[1] == '.html':
194 Trace('Skipping %s' % filename) 231 Trace('Skipping %s' % filename)
195 continue 232 continue
196 233
197 filename = os.path.join(root, filename) 234 filename = os.path.join(root, filename)
198 Trace('Processing "%s"...' % filename) 235 Trace('Processing "%s"...' % filename)
199 try: 236 try:
200 with open(filename) as f: 237 with open(filename) as f:
201 html = f.read() 238 html = f.read()
202 239
203 fixer = HTMLFixer(html) 240 fixer = HTMLFixer(html)
204 output = fixer.FixAll() 241 output = fixer.FixAll()
205 with open(filename, 'w') as f: 242 with open(filename, 'w') as f:
206 f.write(output) 243 f.write(output)
207 except: 244 except:
208 sys.stderr.write("Error while processing %s\n" % filename) 245 sys.stderr.write("Error while processing %s\n" % filename)
209 raise 246 raise
210 247
211 return 0 248 return 0
212 249
213 if __name__ == '__main__': 250 if __name__ == '__main__':
214 try: 251 try:
215 rtn = main(sys.argv[1:]) 252 rtn = main(sys.argv[1:])
216 except KeyboardInterrupt: 253 except KeyboardInterrupt:
217 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__)) 254 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__))
218 rtn = 1 255 rtn = 1
219 sys.exit(rtn) 256 sys.exit(rtn)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698