annotate document_it.py @ 5:3464eda1af80

better formatting for command line
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 01 Aug 2011 21:54:31 -0700
parents 550f4b240e20
children 5a4c1339b2f9
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 """
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
4 update MDN documentation
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
5
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
6 see:
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
7 http://developer.mindtouch.com/en/ref/MindTouch_API/POST%3Apages%2F%2F%7Bpageid%7D%2F%2Fcontents
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
8
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
9 The manifest format is in the form:
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
10
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
11 mozrunner/README.txt https://developer.mozilla.org/en/Mozrunner
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
12 jsbridge/README.txt https://developer.mozilla.org/en/JSbridge
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
13 mozmill/README.txt https://developer.mozilla.org/en/Mozmill
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
14 mozmill/docs/ https://developer.mozilla.org/en/Mozmill/
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 """
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16
5
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
17 import optparse
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 import os
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 import sys
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 import urllib2
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 # necessary imports
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23 try:
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24 import markdown
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25 except ImportError:
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 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
27
1
53c7f9c7dfb6 note staging server
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
28 #DEST='http://developer.mozilla.org/'
5
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
29 DEST='https://developer-stage9.mozilla.org/jhammel'
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
30 DIR=os.path.dirname(os.path.abspath(__file__)) # XXX currently unused
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
32 def find_readme(directory):
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33 """find a README file in a directory"""
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
34 # XXX currently unused
5
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
35 README=['README.md', 'README.txt', 'README']
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
36 for name in README:
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
37 path = os.path.join(directory, name)
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
38 if os.path.exists(path):
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
39 return path
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
40
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
41 def parse_manifest(filename, directory=None):
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
42 """
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
43 reads a documentation manifest; returns a list of two-tuples:
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
44 [
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
45 """
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
46
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
47 assert os.path.exists(filename) and os.path.isfile(filename)
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
48 if directory is None:
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
49 directory = os.path.dirname(os.path.abspath(filename))
5
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
50 lines = [line.strip() for line in file(filename).readlines()]
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
51 lines = [line for line in lines
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
52 if line and not line.startswith('#')]
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
53 items = []
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
54 for line in lines:
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
55 try:
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
56 f, url = line.split()
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
57 # TODO: include options as third segment (e.g. format=ReST)
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
58 except ValueError:
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
59 raise ValueError("illegal manifest line: '%s'" % line)
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
60
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
61 filename = os.path.join(directory, f)
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
62 if os.path.isdir(filename):
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
63 pass # TODO
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
64 else:
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
65 items.append((filename, url))
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
66 return items
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
67
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
68 def main(args=sys.argv[1:]):
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
69
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
70 # parse command line options
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
71 usage = '%prog [options] manifest <manifest> <...>'
5
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
72
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
73 # description formatter
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
74 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
75 def format_description(self, description):
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
76 if description:
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
77 return description + '\n'
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
78 else:
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
79 return ''
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
80
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
81 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter())
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
82 parser.add_option('-d', '--directory', dest='directory',
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
83 help='render the documentation to this directory')
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
84 parser.add_option('--dest', dest='dest',
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
85 default=DEST,
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
86 help='base URL of destination')
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
87 parser.add_option('-u', '--user', dest='user',
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
88 help='user name')
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
89 parser.add_option('--list', dest='list', action='store_true',
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
90 help="list packages")
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
91 options, manifests = parser.parse_args(args)
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
92
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
93 if not args:
5
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
94 parser.print_help()
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
95 parser.exit()
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
96
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
97 # run setup_development.py in this directory
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
98 # to ensure documentation is up to date
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
99 # TODO; as yet unneeded
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
100
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
101 # render and upload READMEs
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
102 # TODO
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
103
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
104
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
105
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
106 if __name__ == '__main__':
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
107 main()