annotate document_it.py @ 18:f7dc318832dc

misc improvements
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 02 Aug 2011 19:14:32 -0700
parents 0a1aecef2c52
children 493683e17eae
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 """
9
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
4 update MDN documentation from markdown
4
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/
9
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
15
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
16 --dest sets the destination, e.g.
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
17
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
18 --dest http://developer.mozilla.org/
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
19 --dest https://developer-stage9.mozilla.org/jhammel
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
20 --dest path/to directory
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
21
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
22 By default, a new temporary directory will be created
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23 """
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24
5
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
25 import optparse
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 import os
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27 import sys
9
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
28 import tempfile
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29 import urllib2
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
30
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31 # necessary imports
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
32 try:
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33 import markdown
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
34 except ImportError:
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
35 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
36
5
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
37 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
38
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
39 def find_readme(directory):
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
40 """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
41 # XXX currently unused
5
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
42 README=['README.md', 'README.txt', 'README']
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
43 for name in README:
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
44 path = os.path.join(directory, name)
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
45 if os.path.exists(path):
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
46 return path
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
47
18
f7dc318832dc misc improvements
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
48 def all_files(directory):
f7dc318832dc misc improvements
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
49 filenames = []
f7dc318832dc misc improvements
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
50 for dirpath, dirnames, files in os.walk(directory):
f7dc318832dc misc improvements
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
51 filenames.extend([os.path.join(dirpath, f) for f in files])
f7dc318832dc misc improvements
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
52 return sorted(filenames)
f7dc318832dc misc improvements
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
53
14
145a11393a73 better handling of urls
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
54 def parse_manifest(filename, baseurl, directory=None):
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
55 """
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
56 reads a documentation manifest; returns a list of two-tuples:
6
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
57 [(filename, destination)]
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
58 """
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
59
6
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
60 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
61
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
62 if directory is None:
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
63 directory = os.path.dirname(os.path.abspath(filename))
5
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
64 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
65 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
66 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
67 items = []
14
145a11393a73 better handling of urls
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
68 baseurl = baseurl.rstrip('/')
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
69 for line in lines:
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
70 try:
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
71 f, url = line.split()
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
72 # 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
73 except ValueError:
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
74 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
75
14
145a11393a73 better handling of urls
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
76 if '://' not in url:
145a11393a73 better handling of urls
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
77 url = '%s/%s' % (baseurl, url.lstrip('/'))
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
78 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
79 if os.path.isdir(filename):
18
f7dc318832dc misc improvements
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
80 files = all_files(filename)
f7dc318832dc misc improvements
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
81 for i in files:
f7dc318832dc misc improvements
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
82 relpath = os.path.relpath(i, filename)
f7dc318832dc misc improvements
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
83 items.append((i, '%s/%s' % (url.rstrip('/'), relpath.lstrip('/'))))
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
84 else:
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
85 items.append((filename, url))
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
86 return items
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
87
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
88 def main(args=sys.argv[1:]):
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
89
9
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
90 # default output directory
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
91 default_dir = tempfile.mktemp()
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
92
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
93 # parse command line options
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
94 usage = '%prog [options] manifest <manifest> <...>'
5
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
95
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
96 # description formatter
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
97 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
98 def format_description(self, description):
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
99 if description:
13
1efb669ab1c8 better description formatting
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
100 return description.strip() + '\n'
5
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
101 else:
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
102 return ''
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
103
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
104 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter())
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
105 parser.add_option('-d', '--directory', dest='directory',
6
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
106 help='render the documentation from this directory')
15
d9026d114655 deal with eccentricities of local directories
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
107 parser.add_option('-o', '--dest', dest='dest',
9
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
108 default=default_dir,
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
109 help='base directory or URL of destination [DEFAULT: %default]')
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
110 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
111 help='user name')
6
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
112 parser.add_option('--list', dest='list', action='store_true', default=False,
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
113 help="list files")
9
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
114 parser.add_option('--validate', dest='validate', # TODO unused
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
115 action='store_true', default=False,
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
116 help="validate the rendering but don't output")
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
117 options, manifests = parser.parse_args(args)
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
118
6
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
119 # 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
120 if not args:
5
3464eda1af80 better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents: 4
diff changeset
121 parser.print_help()
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
122 parser.exit()
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
123
7
6bf82220a04c more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
124 # get base url
11
df6c2e71b87e actually render
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
125 assert options.dest
7
6bf82220a04c more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
126 if '://' in options.dest:
6bf82220a04c more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
127 baseurl = options.dest
6bf82220a04c more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
128 else:
15
d9026d114655 deal with eccentricities of local directories
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
129 baseurl = 'file://' + os.path.abspath(options.dest)
7
6bf82220a04c more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
130
6
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
131 # read the manifests
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
132 files = []
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
133 for manifest in manifests:
14
145a11393a73 better handling of urls
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
134 for item in parse_manifest(manifest, baseurl, options.directory):
6
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
135 if item not in files:
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
136 files.append(item)
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
137 if options.list:
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
138 for item in files:
14
145a11393a73 better handling of urls
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
139 print '%s -> %s' % item
17
0a1aecef2c52 youre done after listing files
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
140 return
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
141
9
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
142 if not files:
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
143 return # you're done
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
144
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
145 # render and upload READMEs
11
df6c2e71b87e actually render
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
146 if baseurl.startswith('file://'):
df6c2e71b87e actually render
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
147 options.dest = baseurl[len('file://'):] # deals with --dest file:///foo from command line
8
f7fa35f972f4 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
148
11
df6c2e71b87e actually render
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
149 # ensure a directory
df6c2e71b87e actually render
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
150 if os.path.exists(options.dest):
df6c2e71b87e actually render
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
151 assert os.path.isdir(options.dest), "'%s' - not a directory" % options.dest
8
f7fa35f972f4 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
152
f7fa35f972f4 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
153 # TODO render to directory
9
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
154 for src, dest in files:
15
d9026d114655 deal with eccentricities of local directories
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
155
d9026d114655 deal with eccentricities of local directories
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
156 if dest.startswith('file://'):
d9026d114655 deal with eccentricities of local directories
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
157 dest = dest[len('file://'):]
11
df6c2e71b87e actually render
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
158
df6c2e71b87e actually render
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
159 # create a directory if needed
df6c2e71b87e actually render
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
160 dirname = os.path.dirname(dest)
16
d6528dd74592 only create the directory if we need to
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
161 if os.path.exists(dirname):
18
f7dc318832dc misc improvements
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
162 assert os.path.isdir(dirname), "%s exists and is not a directory" % dirname
16
d6528dd74592 only create the directory if we need to
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
163 else:
d6528dd74592 only create the directory if we need to
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
164 os.makedirs(dirname)
11
df6c2e71b87e actually render
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
165
df6c2e71b87e actually render
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
166 # render
df6c2e71b87e actually render
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
167 f = file(dest, 'w')
df6c2e71b87e actually render
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
168 buffer = markdown.Markdown().convert(file(src).read())
df6c2e71b87e actually render
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
169 f.write(buffer)
df6c2e71b87e actually render
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
170 f.close()
6
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
171 else:
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
172 # TODO check credentials
12
54e27f046cd2 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
173 for src, dest in files:
54e27f046cd2 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
174 pass
6
5a4c1339b2f9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
175 raise NotImplementedError
4
550f4b240e20 make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
176
11
df6c2e71b87e actually render
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
177
10
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
178 if options.dest == default_dir:
11
df6c2e71b87e actually render
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
179 print "Files rendered to\n%s" % default_dir
9
62bd66061329 add a helpful help message
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
180
0
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
181 if __name__ == '__main__':
665b2ae2ecc6 stub project for DocumentIt
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
182 main()