annotate document_it.py @ 7:6bf82220a04c

more stubbing
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 01 Aug 2011 22:51:12 -0700
parents 5a4c1339b2f9
children f7fa35f972f4
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:
6
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
44 [(filename, destination)]
4
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
6
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
47 assert os.path.exists(filename) and os.path.isfile(filename), "%s not found" % filename
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
48
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
49 if directory is None:
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
50 directory = os.path.dirname(os.path.abspath(filename))
5
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
51 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
52 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
53 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
54 items = []
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
55 for line in lines:
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
56 try:
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
57 f, url = line.split()
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
58 # 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
59 except ValueError:
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
60 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
61
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
62 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
63 if os.path.isdir(filename):
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
64 pass # TODO
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
65 else:
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
66 items.append((filename, url))
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
67 return items
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
68
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
69 def main(args=sys.argv[1:]):
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
70
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
71 # parse command line options
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
72 usage = '%prog [options] manifest <manifest> <...>'
5
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
73
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
74 # description formatter
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
75 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
76 def format_description(self, description):
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
77 if description:
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
78 return description + '\n'
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
79 else:
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
80 return ''
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
81
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
82 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter())
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
83 parser.add_option('-d', '--directory', dest='directory',
6
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
84 help='render the documentation from this directory')
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
85 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
86 default=DEST,
6
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
87 help='base directory or URL of destination')
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
88 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
89 help='user name')
6
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
90 parser.add_option('--list', dest='list', action='store_true', default=False,
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
91 help="list files")
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
92 options, manifests = parser.parse_args(args)
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
93
6
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
94 # print help if no manifests given
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
95 if not args:
5
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
96 parser.print_help()
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
97 parser.exit()
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
98
7
6bf82220a04c more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
99 # get base url
6bf82220a04c more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
100 if '://' in options.dest:
6bf82220a04c more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
101 baseurl = options.dest
6bf82220a04c more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
102 else:
6bf82220a04c more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
103 baseurl = 'file://' + options.dest
6bf82220a04c more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
104
6
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
105 # read the manifests
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
106 files = []
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
107 for manifest in manifests:
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
108 for item in parse_manifest(manifest):
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
109 if item not in files:
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
110 files.append(item)
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
111 if options.list:
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
112 for item in files:
7
6bf82220a04c more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
113 print '%s -> %s/%s' % (item[0], baseurl.rstrip('/'), item[1].lstrip('/'))
6
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
114
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
115
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
116 # render and upload READMEs
6
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
117 if options.directory:
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
118 pass
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
119 else:
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
120 # TODO check credentials
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
121 raise NotImplementedError
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
122
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
123 if __name__ == '__main__':
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
124 main()