OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
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 | |
4 # found in the LICENSE file. | |
5 | |
6 import optparse | |
7 import os | |
8 import pydoc | |
9 import shutil | |
10 import sys | |
11 | |
12 | |
13 def main(): | |
14 parser = optparse.OptionParser() | |
15 parser.add_option('-w', '--write', dest='dir', metavar='FILE', | |
16 default=os.path.join(os.getcwd(), 'pyauto_docs'), | |
17 help=('Directory path to write all of the documentation. ' | |
18 'Defaults to "pyauto_docs" in current directory.')) | |
19 parser.add_option('-p', '--pyautolib', dest='pyautolib', metavar='FILE', | |
20 default=os.getcwd(), | |
21 help='Location of pyautolib directory') | |
22 (options, args) = parser.parse_args() | |
23 | |
24 if not os.path.isdir(options.dir): | |
25 os.makedirs(options.dir) | |
26 | |
27 # Add these paths so pydoc can find everything | |
28 sys.path.append(os.path.join(options.pyautolib, | |
29 '../../../third_party/')) | |
30 sys.path.append(options.pyautolib) | |
31 | |
32 # Get a snapshot of the current directory where pydoc will export the files | |
33 previous_contents = set(os.listdir(os.getcwd())) | |
34 pydoc.writedocs(options.pyautolib) | |
35 current_contents = set(os.listdir(os.getcwd())) | |
36 | |
37 if options.dir == os.getcwd(): | |
38 print 'Export complete, files are located in %s' % options.dir | |
39 return 1 | |
40 | |
41 new_files = current_contents.difference(previous_contents) | |
42 for file_name in new_files: | |
43 basename, extension = os.path.splitext(file_name) | |
44 if extension == '.html': | |
45 # Build the complete path | |
46 full_path = os.path.join(os.getcwd(), file_name) | |
47 existing_file_path = os.path.join(options.dir, file_name) | |
48 if os.path.isfile(existing_file_path): | |
49 os.remove(existing_file_path) | |
50 shutil.move(full_path, options.dir) | |
51 | |
52 print 'Export complete, files are located in %s' % options.dir | |
53 return 0 | |
54 | |
55 | |
56 if __name__ == '__main__': | |
57 sys.exit(main()) | |
OLD | NEW |