OLD | NEW |
---|---|
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 |
11 import glob | 11 import glob |
12 import optparse | 12 import argparse |
binji
2014/11/13 23:57:02
sort
Sam Clegg
2014/11/30 17:55:12
Done.
| |
13 import os | 13 import os |
14 import re | 14 import re |
15 import shutil | 15 import shutil |
16 import sys | 16 import sys |
17 try: | 17 try: |
18 from BeautifulSoup import BeautifulSoup, Tag | 18 from BeautifulSoup import BeautifulSoup, Tag |
19 except (ImportError, NotImplementedError): | 19 except (ImportError, NotImplementedError): |
20 print ("This tool requires the BeautifulSoup package " | 20 print ("This tool requires the BeautifulSoup package " |
21 "(see http://www.crummy.com/software/BeautifulSoup/).\n" | 21 "(see http://www.crummy.com/software/BeautifulSoup/).\n" |
22 "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 " |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 return re.sub(r'(_\d_\d)(?=[": <])', '', html) | 141 return re.sub(r'(_\d_\d)(?=[": <])', '', html) |
142 | 142 |
143 def FixAll(self): | 143 def FixAll(self): |
144 self.FixTableHeadings() | 144 self.FixTableHeadings() |
145 self.RemoveTopHeadings() | 145 self.RemoveTopHeadings() |
146 html = str(self.soup) | 146 html = str(self.soup) |
147 html = self.RemoveVersionNumbers(html) | 147 html = self.RemoveVersionNumbers(html) |
148 return html | 148 return html |
149 | 149 |
150 | 150 |
151 def main(argv): | 151 def main(argv): |
binji
2014/11/13 23:57:02
rename to args
| |
152 """Main entry for the doxy_cleanup utility | 152 """Main entry for the doxy_cleanup utility |
153 | 153 |
154 doxy_cleanup cleans up the html files generated by doxygen. | 154 doxy_cleanup cleans up the html files generated by doxygen. |
155 """ | 155 """ |
156 | 156 |
157 parser = optparse.OptionParser(usage='Usage: %prog [options] directory') | 157 parser = argparse.ArgumentParser(usage='Usage: %prog [options] directory') |
binji
2014/11/13 23:57:02
remove usage?
Sam Clegg
2014/11/30 17:55:12
Done.
| |
158 parser.add_option('-v', '--verbose', help='verbose output.', | 158 parser.add_argument('-v', '--verbose', help='verbose output.', |
159 action='store_true') | 159 action='store_true') |
160 options, files = parser.parse_args(argv) | 160 parser.add_argument('directory') |
161 | 161 |
162 if len(files) != 1: | 162 options = parser.parse_args(argv) |
163 parser.error('Expected one directory') | |
164 | 163 |
165 if options.verbose: | 164 if options.verbose: |
166 Trace.verbose = True | 165 Trace.verbose = True |
167 | 166 |
168 root_dir = files[0] | 167 root_dir = options.directory |
169 html_dir = os.path.join(root_dir, 'html') | 168 html_dir = os.path.join(root_dir, 'html') |
170 | 169 |
171 # Doxygen puts all files in an 'html' directory. | 170 # Doxygen puts all files in an 'html' directory. |
172 # First, move all files from that directory to root_dir. | 171 # First, move all files from that directory to root_dir. |
173 for filename in glob.glob(os.path.join(html_dir, '*')): | 172 for filename in glob.glob(os.path.join(html_dir, '*')): |
174 Trace('Moving %s -> %s' % (filename, root_dir)) | 173 Trace('Moving %s -> %s' % (filename, root_dir)) |
175 shutil.move(filename, root_dir) | 174 shutil.move(filename, root_dir) |
176 | 175 |
177 # Now remove the 'html' directory. | 176 # Now remove the 'html' directory. |
178 Trace('Removing %s' % html_dir) | 177 Trace('Removing %s' % html_dir) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 | 209 |
211 return 0 | 210 return 0 |
212 | 211 |
213 if __name__ == '__main__': | 212 if __name__ == '__main__': |
214 try: | 213 try: |
215 rtn = main(sys.argv[1:]) | 214 rtn = main(sys.argv[1:]) |
216 except KeyboardInterrupt: | 215 except KeyboardInterrupt: |
217 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__)) | 216 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__)) |
218 rtn = 1 | 217 rtn = 1 |
219 sys.exit(rtn) | 218 sys.exit(rtn) |
OLD | NEW |