Mercurial > mozilla > hg > DocumentIt
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 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/env python |
2 | |
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 | 15 """ |
16 | |
5
3464eda1af80
better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
17 import optparse |
0 | 18 import os |
19 import sys | |
20 import urllib2 | |
21 | |
22 # necessary imports | |
23 try: | |
24 import markdown | |
25 except ImportError: | |
26 raise ImportError("markdown is not installed, run (e.g.):\neasy_install Markdown") | |
27 | |
1 | 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 | 31 |
32 def find_readme(directory): | |
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 | 36 for name in README: |
37 path = os.path.join(directory, name) | |
38 if os.path.exists(path): | |
39 return path | |
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 | 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 | 47 assert os.path.exists(filename) and os.path.isfile(filename), "%s not found" % filename |
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 | 69 def main(args=sys.argv[1:]): |
70 | |
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 | 83 parser.add_option('-d', '--directory', dest='directory', |
6 | 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 | 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 | 90 parser.add_option('--list', dest='list', action='store_true', default=False, |
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 | 93 |
6 | 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 | 98 |
7 | 99 # get base url |
100 if '://' in options.dest: | |
101 baseurl = options.dest | |
102 else: | |
103 baseurl = 'file://' + options.dest | |
104 | |
6 | 105 # read the manifests |
106 files = [] | |
107 for manifest in manifests: | |
108 for item in parse_manifest(manifest): | |
109 if item not in files: | |
110 files.append(item) | |
111 if options.list: | |
112 for item in files: | |
7 | 113 print '%s -> %s/%s' % (item[0], baseurl.rstrip('/'), item[1].lstrip('/')) |
6 | 114 |
0 | 115 |
116 # render and upload READMEs | |
6 | 117 if options.directory: |
118 pass | |
119 else: | |
120 # TODO check credentials | |
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 | 123 if __name__ == '__main__': |
124 main() |