OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 '''This utility cleans up the html files as emitted by doxygen so | 6 '''This utility cleans up the html files as emitted by doxygen so |
7 that they are suitable for publication on a Google documentation site. | 7 that they are suitable for publication on a Google documentation site. |
8 ''' | 8 ''' |
9 | 9 |
| 10 import argparse |
10 import glob | 11 import glob |
11 import optparse | |
12 import os | 12 import os |
13 import re | 13 import re |
14 import shutil | 14 import shutil |
15 import sys | 15 import sys |
| 16 |
16 try: | 17 try: |
17 from BeautifulSoup import BeautifulSoup, Tag | 18 from BeautifulSoup import BeautifulSoup, Tag |
18 except (ImportError, NotImplementedError): | 19 except (ImportError, NotImplementedError): |
19 print ("This tool requires the BeautifulSoup package " | 20 print ("This tool requires the BeautifulSoup package " |
20 "(see http://www.crummy.com/software/BeautifulSoup/).\n" | 21 "(see http://www.crummy.com/software/BeautifulSoup/).\n" |
21 "Make sure that the file BeautifulSoup.py is either in this directory " | 22 "Make sure that the file BeautifulSoup.py is either in this directory " |
22 "or is available in your PYTHON_PATH") | 23 "or is available in your PYTHON_PATH") |
23 raise | 24 raise |
24 | 25 |
25 | 26 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 return re.sub(r'(_\d_\d)(?=[": <])', '', html) | 141 return re.sub(r'(_\d_\d)(?=[": <])', '', html) |
141 | 142 |
142 def FixAll(self): | 143 def FixAll(self): |
143 self.FixTableHeadings() | 144 self.FixTableHeadings() |
144 self.RemoveTopHeadings() | 145 self.RemoveTopHeadings() |
145 html = str(self.soup) | 146 html = str(self.soup) |
146 html = self.RemoveVersionNumbers(html) | 147 html = self.RemoveVersionNumbers(html) |
147 return html | 148 return html |
148 | 149 |
149 | 150 |
150 def main(argv): | 151 def main(args): |
151 """Main entry for the doxy_cleanup utility | 152 """Main entry for the doxy_cleanup utility |
152 | 153 |
153 doxy_cleanup cleans up the html files generated by doxygen. | 154 doxy_cleanup cleans up the html files generated by doxygen. |
154 """ | 155 """ |
155 | 156 |
156 parser = optparse.OptionParser(usage='Usage: %prog [options] directory') | 157 parser = argparse.ArgumentParser(description=__doc__) |
157 parser.add_option('-v', '--verbose', help='verbose output.', | 158 parser.add_argument('-v', '--verbose', help='verbose output.', |
158 action='store_true') | 159 action='store_true') |
159 options, files = parser.parse_args(argv) | 160 parser.add_argument('directory') |
160 | 161 |
161 if len(files) != 1: | 162 options = parser.parse_args(args) |
162 parser.error('Expected one directory') | |
163 | 163 |
164 if options.verbose: | 164 if options.verbose: |
165 Trace.verbose = True | 165 Trace.verbose = True |
166 | 166 |
167 root_dir = files[0] | 167 root_dir = options.directory |
168 html_dir = os.path.join(root_dir, 'html') | 168 html_dir = os.path.join(root_dir, 'html') |
169 | 169 |
170 # Doxygen puts all files in an 'html' directory. | 170 # Doxygen puts all files in an 'html' directory. |
171 # First, move all files from that directory to root_dir. | 171 # First, move all files from that directory to root_dir. |
172 for filename in glob.glob(os.path.join(html_dir, '*')): | 172 for filename in glob.glob(os.path.join(html_dir, '*')): |
173 Trace('Moving %s -> %s' % (filename, root_dir)) | 173 Trace('Moving %s -> %s' % (filename, root_dir)) |
174 shutil.move(filename, root_dir) | 174 shutil.move(filename, root_dir) |
175 | 175 |
176 # Now remove the 'html' directory. | 176 # Now remove the 'html' directory. |
177 Trace('Removing %s' % html_dir) | 177 Trace('Removing %s' % html_dir) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 209 |
210 return 0 | 210 return 0 |
211 | 211 |
212 if __name__ == '__main__': | 212 if __name__ == '__main__': |
213 try: | 213 try: |
214 rtn = main(sys.argv[1:]) | 214 rtn = main(sys.argv[1:]) |
215 except KeyboardInterrupt: | 215 except KeyboardInterrupt: |
216 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__)) | 216 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__)) |
217 rtn = 1 | 217 rtn = 1 |
218 sys.exit(rtn) | 218 sys.exit(rtn) |
OLD | NEW |