Mercurial > mozilla > hg > DocumentIt
comparison document_it.py @ 9:62bd66061329
add a helpful help message
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 01 Aug 2011 23:13:53 -0700 |
parents | f7fa35f972f4 |
children | 853214384bd0 |
comparison
equal
deleted
inserted
replaced
8:f7fa35f972f4 | 9:62bd66061329 |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 """ | 3 """ |
4 update MDN documentation | 4 update MDN documentation from markdown |
5 | 5 |
6 see: | 6 see: |
7 http://developer.mindtouch.com/en/ref/MindTouch_API/POST%3Apages%2F%2F%7Bpageid%7D%2F%2Fcontents | 7 http://developer.mindtouch.com/en/ref/MindTouch_API/POST%3Apages%2F%2F%7Bpageid%7D%2F%2Fcontents |
8 | 8 |
9 The manifest format is in the form: | 9 The manifest format is in the form: |
10 | 10 |
11 mozrunner/README.txt https://developer.mozilla.org/en/Mozrunner | 11 mozrunner/README.txt https://developer.mozilla.org/en/Mozrunner |
12 jsbridge/README.txt https://developer.mozilla.org/en/JSbridge | 12 jsbridge/README.txt https://developer.mozilla.org/en/JSbridge |
13 mozmill/README.txt https://developer.mozilla.org/en/Mozmill | 13 mozmill/README.txt https://developer.mozilla.org/en/Mozmill |
14 mozmill/docs/ https://developer.mozilla.org/en/Mozmill/ | 14 mozmill/docs/ https://developer.mozilla.org/en/Mozmill/ |
15 | |
16 --dest sets the destination, e.g. | |
17 | |
18 --dest http://developer.mozilla.org/ | |
19 --dest https://developer-stage9.mozilla.org/jhammel | |
20 --dest path/to directory | |
21 | |
22 By default, a new temporary directory will be created | |
15 """ | 23 """ |
16 | 24 |
17 import optparse | 25 import optparse |
18 import os | 26 import os |
19 import sys | 27 import sys |
28 import tempfile | |
20 import urllib2 | 29 import urllib2 |
21 | 30 |
22 # necessary imports | 31 # necessary imports |
23 try: | 32 try: |
24 import markdown | 33 import markdown |
25 except ImportError: | 34 except ImportError: |
26 raise ImportError("markdown is not installed, run (e.g.):\neasy_install Markdown") | 35 raise ImportError("markdown is not installed, run (e.g.):\neasy_install Markdown") |
27 | 36 |
28 #DEST='http://developer.mozilla.org/' | |
29 DEST='https://developer-stage9.mozilla.org/jhammel' | |
30 DIR=os.path.dirname(os.path.abspath(__file__)) # XXX currently unused | 37 DIR=os.path.dirname(os.path.abspath(__file__)) # XXX currently unused |
31 | 38 |
32 def find_readme(directory): | 39 def find_readme(directory): |
33 """find a README file in a directory""" | 40 """find a README file in a directory""" |
34 # XXX currently unused | 41 # XXX currently unused |
66 items.append((filename, url)) | 73 items.append((filename, url)) |
67 return items | 74 return items |
68 | 75 |
69 def main(args=sys.argv[1:]): | 76 def main(args=sys.argv[1:]): |
70 | 77 |
78 # default output directory | |
79 default_dir = tempfile.mktemp() | |
80 | |
71 # parse command line options | 81 # parse command line options |
72 usage = '%prog [options] manifest <manifest> <...>' | 82 usage = '%prog [options] manifest <manifest> <...>' |
73 | 83 |
74 # description formatter | 84 # description formatter |
75 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): | 85 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): |
81 | 91 |
82 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter()) | 92 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter()) |
83 parser.add_option('-d', '--directory', dest='directory', | 93 parser.add_option('-d', '--directory', dest='directory', |
84 help='render the documentation from this directory') | 94 help='render the documentation from this directory') |
85 parser.add_option('--dest', dest='dest', | 95 parser.add_option('--dest', dest='dest', |
86 default=DEST, | 96 default=default_dir, |
87 help='base directory or URL of destination') | 97 help='base directory or URL of destination [DEFAULT: %default]') |
88 parser.add_option('-u', '--user', dest='user', | 98 parser.add_option('-u', '--user', dest='user', |
89 help='user name') | 99 help='user name') |
90 parser.add_option('--list', dest='list', action='store_true', default=False, | 100 parser.add_option('--list', dest='list', action='store_true', default=False, |
91 help="list files") | 101 help="list files") |
102 parser.add_option('--validate', dest='validate', # TODO unused | |
103 action='store_true', default=False, | |
104 help="validate the rendering but don't output") | |
92 options, manifests = parser.parse_args(args) | 105 options, manifests = parser.parse_args(args) |
93 | 106 |
94 # print help if no manifests given | 107 # print help if no manifests given |
95 if not args: | 108 if not args: |
96 parser.print_help() | 109 parser.print_help() |
110 files.append(item) | 123 files.append(item) |
111 if options.list: | 124 if options.list: |
112 for item in files: | 125 for item in files: |
113 print '%s -> %s/%s' % (item[0], baseurl.rstrip('/'), item[1].lstrip('/')) | 126 print '%s -> %s/%s' % (item[0], baseurl.rstrip('/'), item[1].lstrip('/')) |
114 | 127 |
128 if not files: | |
129 return # you're done | |
130 | |
115 # render and upload READMEs | 131 # render and upload READMEs |
116 if options.directory: | 132 if options.directory: |
117 | 133 |
118 # create a directory if needed | 134 # create a directory if needed |
119 if os.path.exists(options.directory): | 135 if os.path.exists(options.directory): |
120 assert os.path.isdir(options.directory), "'%s' - not a directory" % options.directory | 136 assert os.path.isdir(options.directory), "'%s' - not a directory" % options.directory |
121 else: | 137 else: |
122 os.makedirs(options.directory) | 138 os.makedirs(options.directory) |
123 | 139 |
124 # TODO render to directory | 140 # TODO render to directory |
125 | 141 for src, dest in files: |
142 dest = os.path.join(options.dest, dest) | |
143 | |
126 else: | 144 else: |
127 # TODO check credentials | 145 # TODO check credentials |
128 raise NotImplementedError | 146 raise NotImplementedError |
129 | 147 |
148 if options.dest = default_dir: | |
149 print "Files rendered to %s" % default_dir | |
150 | |
130 if __name__ == '__main__': | 151 if __name__ == '__main__': |
131 main() | 152 main() |