Mercurial > mozilla > hg > DocumentIt
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 |
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: |
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 | 68 def main(args=sys.argv[1:]): |
69 | |
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 | 82 parser.add_option('-d', '--directory', dest='directory', |
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 | 89 parser.add_option('--list', dest='list', action='store_true', |
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 | 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 | 96 |
97 # run setup_development.py in this directory | |
98 # to ensure documentation is up to date | |
99 # TODO; as yet unneeded | |
100 | |
101 # render and upload READMEs | |
102 # TODO | |
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 | 106 if __name__ == '__main__': |
107 main() |