annotate document_it.py @ 0:665b2ae2ecc6

stub project for DocumentIt
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 01 Aug 2011 12:00:51 -0700
parents
children 53c7f9c7dfb6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 update documentation for Mozmill
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 """
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 import os
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 import sys
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 import urllib2
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 from optparse import OptionParser
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 # necessary imports
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 try:
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14 import markdown
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 except ImportError:
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 raise ImportError("markdown is not installed, run (e.g.):\neasy_install Markdown")
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 DEST='http://developer.mozilla.org/'
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 DIR=os.path.dirname(os.path.abspath(__file__))
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 README=['README.md', 'README.txt', 'README']
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 def find_readme(directory):
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23 """find a README file in a directory"""
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24 for name in README:
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25 path = os.path.join(directory, name)
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 if os.path.exists(path):
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27 return path
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
28
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29 def main(args=sys.argv[1:]):
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
30
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31 # parse command line options
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
32 usage = '%prog [options]'
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33 parser = OptionParser(usage=usage, description=__doc__)
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
34 parser.add_option('-d', '--directory', dest='directory',
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
35 help='render the documentation to this directory')
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
36 parser.add_option('-p', '--package', dest='packages',
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
37 action='append',
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
38 help='package to operate on')
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
39 parser.add_option('--list', dest='list', action='store_true',
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
40 help="list packages")
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
41 options, args = parser.parse_args(args)
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
42
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
43 # find packages
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
44 packages = options.__dict__.pop('packages')
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
45 if not packages:
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
46 packages = [i for i in os.listdir(DIR)
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
47 if os.path.isdir(os.path.join(DIR, i))
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
48 and find_readme(os.path.join(DIR, i))]
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
49 if options.list:
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
50 for i in packages:
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
51 print i
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
52
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
53 # run setup_development.py in this directory
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
54 # to ensure documentation is up to date
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
55 # TODO; as yet unneeded
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
56
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
57 # render and upload READMEs
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
58 # TODO
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
59
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
60 if __name__ == '__main__':
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
61 main()