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

Unified Diff: native_client_sdk/src/doc/doxygen/doxy_cleanup.py

Issue 136033007: [NaCl SDK Docs] Simplify PPAPI documentation generation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: native_client_sdk/src/doc/doxygen/doxy_cleanup.py
diff --git a/ppapi/c/documentation/doxy_cleanup.py b/native_client_sdk/src/doc/doxygen/doxy_cleanup.py
similarity index 53%
copy from ppapi/c/documentation/doxy_cleanup.py
copy to native_client_sdk/src/doc/doxygen/doxy_cleanup.py
index 01b1ca07d4e72d00eae19d4f5a161123b346501d..9097cd2909f008b4a54c3e05bc5d0059195a8e83 100755
--- a/ppapi/c/documentation/doxy_cleanup.py
+++ b/native_client_sdk/src/doc/doxygen/doxy_cleanup.py
@@ -8,11 +8,11 @@
that they are suitable for publication on a Google documentation site.
'''
+import glob
import optparse
import os
import re
import shutil
-import string
import sys
try:
from BeautifulSoup import BeautifulSoup, Tag
@@ -24,6 +24,50 @@ except (ImportError, NotImplementedError):
raise
+def Trace(msg):
+ if Trace.verbose:
+ sys.stderr.write(str(msg) + '\n')
+
+Trace.verbose = False
+
+
+FILES_TO_REMOVE = [
+ '*.css',
+ '*.map',
+ '*.md5',
+ 'annotated.html',
+ 'bc_s.png',
+ 'classes.html',
+ 'closed.png',
+ 'doxygen.png',
+ 'files.html',
+ 'functions*.html',
+ 'globals_0x*.html',
+ 'globals_enum.html',
+ 'globals_eval.html',
+ 'globals_func.html',
+ 'globals.html',
+ 'globals_type.html',
+ 'globals_vars.html',
+ 'graph_legend.html',
+ 'graph_legend.png',
+ 'hierarchy.html',
+ 'index_8dox.html',
+ 'index.html',
+ 'modules.html',
+ 'namespacemembers_func.html',
+ 'namespacemembers.html',
+ 'namespaces.html',
+ 'nav_f.png',
+ 'nav_h.png',
+ 'open.png',
+ 'tab_a.png',
+ 'tab_b.png',
+ 'tab_h.png',
+ 'tab_s.png',
+]
+
+
class HTMLFixer(object):
'''This class cleans up the html strings as produced by Doxygen
'''
@@ -66,10 +110,10 @@ class HTMLFixer(object):
table_headers.reverse()
# Split up tables that have multiple table header (th) rows
for tag in table_headers:
- print "Header tag: %s is %s" % (tag.name, tag.string.strip())
+ Trace("Header tag: %s is %s" % (tag.name, tag.string.strip()))
# Is this a heading in the middle of a table?
if tag.findPreviousSibling('tr') and tag.parent.name == 'table':
- print "Splitting Table named %s" % tag.string.strip()
+ Trace("Splitting Table named %s" % tag.string.strip())
table = tag.parent
table_parent = table.parent
table_index = table_parent.contents.index(table)
@@ -100,43 +144,72 @@ class HTMLFixer(object):
return str(self.soup)
-def main():
- '''Main entry for the doxy_cleanup utility
-
- doxy_cleanup takes a list of html files and modifies them in place.'''
-
- parser = optparse.OptionParser(usage='Usage: %prog [options] files...')
-
- parser.add_option('-m', '--move', dest='move', action='store_true',
- default=False, help='move html files to "original_html"')
-
- options, files = parser.parse_args()
-
- if not files:
- parser.print_usage()
- return 1
-
- for filename in files:
- try:
- with open(filename, 'r') as file:
- html = file.read()
-
- print "Processing %s" % filename
- fixer = HTMLFixer(html)
- fixer.FixAll()
- with open(filename, 'w') as file:
- file.write(str(fixer))
- if options.move:
- new_directory = os.path.join(
- os.path.dirname(os.path.dirname(filename)), 'original_html')
- if not os.path.exists(new_directory):
- os.mkdir(new_directory)
- shutil.move(filename, new_directory)
- except:
- print "Error while processing %s" % filename
- raise
+def main(argv):
+ """Main entry for the doxy_cleanup utility
+
+ doxy_cleanup cleans up the html files generated by doxygen.
+ """
+
+ parser = optparse.OptionParser(usage='Usage: %prog [options] directory')
+ parser.add_option('-v', '--verbose', help='verbose output.',
+ action='store_true')
+ options, files = parser.parse_args(argv)
+
+ if len(files) != 1:
+ parser.error('Expected one directory')
+
+ if options.verbose:
+ Trace.verbose = True
+
+ root_dir = files[0]
+ html_dir = os.path.join(root_dir, 'html')
+
+ # Doxygen puts all files in an 'html' directory.
+ # First, move all files from that directory to root_dir.
+ for filename in glob.glob(os.path.join(html_dir, '*')):
+ Trace('Moving %s -> %s' % (filename, root_dir))
+ shutil.move(filename, root_dir)
+
+ # Now remove the 'html' directory.
+ Trace('Removing %s' % html_dir)
+ os.rmdir(html_dir)
+
+ # Then remove unneeded files.
+ for wildcard in FILES_TO_REMOVE:
+ Trace('Removing "%s":' % wildcard)
+ path = os.path.join(root_dir, wildcard)
+ for filename in glob.glob(path):
+ Trace(' Removing "%s"' % filename)
+ os.remove(filename)
+
+ # Now, fix the HTML files we've kept.
+ Trace('Fixing HTML files...')
+ for root, _, files in os.walk(root_dir):
+ for filename in files:
+ if not os.path.splitext(filename)[1] == '.html':
+ Trace('Skipping %s' % filename)
+ continue
+
+ filename = os.path.join(root, filename)
+ Trace('Processing "%s"...' % filename)
+ try:
+ with open(filename) as f:
+ html = f.read()
+
+ fixer = HTMLFixer(html)
+ fixer.FixAll()
+ with open(filename, 'w') as f:
+ f.write(str(fixer))
+ except:
+ sys.stderr.write("Error while processing %s\n" % filename)
+ raise
return 0
if __name__ == '__main__':
- sys.exit(main())
+ try:
+ rtn = main(sys.argv[1:])
+ except KeyboardInterrupt:
+ sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__))
+ rtn = 1
+ sys.exit(rtn)

Powered by Google App Engine
This is Rietveld 408576698