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