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.
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',
21 help='Location of pyautolib directory')
22 (options, args) = parser.parse_args()
24 if not os.path.isdir(options.dir):
25 os.makedirs(options.dir)
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)
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()))
37 if options.dir == os.getcwd():
38 print 'Export complete, files are located in %s' % options.dir
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)
52 print 'Export complete, files are located in %s' % options.dir
56 if __name__ == '__main__':