Mercurial > mozilla > hg > DocumentIt
annotate document_it.py @ 26:ce7cbf3e08e1 default tip
fix bug with local files, index.html, and manifest order
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 04 Aug 2011 18:43:12 -0700 |
parents | 0ce6b501f62d |
children |
rev | line source |
---|---|
0 | 1 #!/usr/bin/env python |
2 | |
3 """ | |
9 | 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 |
26
ce7cbf3e08e1
fix bug with local files, index.html, and manifest order
Jeff Hammel <jhammel@mozilla.com>
parents:
25
diff
changeset
|
6 for the MDN API see: |
4
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 | 15 |
25 | 16 --dest sets the destination. If a net location is specified, authentication |
17 is required. By default, a new temporary directory will be created | |
0 | 18 """ |
19 | |
5
3464eda1af80
better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
20 import optparse |
0 | 21 import os |
22 import sys | |
9 | 23 import tempfile |
0 | 24 import urllib2 |
25 | |
22
67e4becc7d49
first steps for cleaning up this awful mess
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
26 # import markdown |
0 | 27 try: |
28 import markdown | |
29 except ImportError: | |
30 raise ImportError("markdown is not installed, run (e.g.):\neasy_install Markdown") | |
31 | |
23
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
32 destinations = {'stage': 'https://developer-stage9.mozilla.org/@api/deki/pages/=%(page)s/contents?edittime=now', |
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
33 'MDN': 'https://developer.mozilla.org/@api/deki/pages/=%(page)s/contents?edittime=now'} |
22
67e4becc7d49
first steps for cleaning up this awful mess
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
34 |
0 | 35 |
36 def find_readme(directory): | |
37 """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
|
38 # XXX currently unused |
5
3464eda1af80
better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
39 README=['README.md', 'README.txt', 'README'] |
0 | 40 for name in README: |
41 path = os.path.join(directory, name) | |
42 if os.path.exists(path): | |
43 return path | |
44 | |
18 | 45 def all_files(directory): |
22
67e4becc7d49
first steps for cleaning up this awful mess
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
46 """get all files in a directory tree""" |
18 | 47 filenames = [] |
48 for dirpath, dirnames, files in os.walk(directory): | |
49 filenames.extend([os.path.join(dirpath, f) for f in files]) | |
50 return sorted(filenames) | |
51 | |
22
67e4becc7d49
first steps for cleaning up this awful mess
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
52 def parse_manifest(filename, directory=None): |
4
550f4b240e20
make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
53 """ |
550f4b240e20
make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
54 reads a documentation manifest; returns a list of two-tuples: |
6 | 55 [(filename, destination)] |
4
550f4b240e20
make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
56 """ |
550f4b240e20
make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
57 |
6 | 58 assert os.path.exists(filename) and os.path.isfile(filename), "%s not found" % filename |
59 | |
4
550f4b240e20
make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
60 if directory is None: |
550f4b240e20
make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
61 directory = os.path.dirname(os.path.abspath(filename)) |
5
3464eda1af80
better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
62 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
|
63 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
|
64 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
|
65 items = [] |
550f4b240e20
make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
66 for line in lines: |
550f4b240e20
make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
67 try: |
22
67e4becc7d49
first steps for cleaning up this awful mess
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
68 f, page = line.split() |
4
550f4b240e20
make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
69 # 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
|
70 except ValueError: |
550f4b240e20
make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
71 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
|
72 |
550f4b240e20
make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
73 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
|
74 if os.path.isdir(filename): |
22
67e4becc7d49
first steps for cleaning up this awful mess
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
75 raise NotImplementedError |
18 | 76 files = all_files(filename) |
77 for i in files: | |
78 relpath = os.path.relpath(i, filename) | |
22
67e4becc7d49
first steps for cleaning up this awful mess
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
79 items.append((i, relpath)) |
4
550f4b240e20
make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
80 else: |
22
67e4becc7d49
first steps for cleaning up this awful mess
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
81 items.append((filename, page)) |
4
550f4b240e20
make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
82 return items |
550f4b240e20
make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
83 |
23
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
84 def item_url(item, dest): |
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
85 if '://' in dest: |
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
86 if '%(page)s' in dest: |
24
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
87 return dest % {'page': item.replace('/', r'%25%32%66')} |
23
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
88 else: |
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
89 return '%s/%s' % (dest.lstrip('/'), item.rstrip('/')) |
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
90 else: |
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
91 return 'file://%s' % (os.path.join(dest, item)) |
24
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
92 |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
93 |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
94 def render(filename): |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
95 """render a file in markdown""" |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
96 return markdown.Markdown().convert(file(filename).read()) |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
97 |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
98 def post(content, url, user, password): |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
99 """post to the specified URL""" |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
100 # XXX cheat and use curl for now |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
101 try: |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
102 from subprocess import check_call as call |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
103 except: |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
104 from subprocess import call |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
105 content = content.replace('\r', '').replace('\n', '\r\n') # just to make sure |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
106 fd, filename = tempfile.mkstemp() |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
107 os.write(fd, content) |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
108 os.close(fd) |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
109 command = ["curl", "-u", "%s:%s" % (user, password), |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
110 "--data-binary", "@%s" % filename, |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
111 "-i", url] |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
112 call(command) |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
113 os.remove(filename) |
23
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
114 |
0 | 115 def main(args=sys.argv[1:]): |
116 | |
9 | 117 # default output directory |
118 default_dir = tempfile.mktemp() | |
119 | |
0 | 120 # parse command line options |
4
550f4b240e20
make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
121 usage = '%prog [options] manifest <manifest> <...>' |
5
3464eda1af80
better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
122 |
3464eda1af80
better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
123 # description formatter |
3464eda1af80
better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
124 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): |
3464eda1af80
better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
125 def format_description(self, description): |
3464eda1af80
better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
126 if description: |
13
1efb669ab1c8
better description formatting
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
127 return description.strip() + '\n' |
5
3464eda1af80
better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
128 else: |
3464eda1af80
better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
129 return '' |
3464eda1af80
better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
130 |
3464eda1af80
better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
131 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter()) |
0 | 132 parser.add_option('-d', '--directory', dest='directory', |
6 | 133 help='render the documentation from this directory') |
15
d9026d114655
deal with eccentricities of local directories
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
134 parser.add_option('-o', '--dest', dest='dest', |
9 | 135 default=default_dir, |
136 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
|
137 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
|
138 help='user name') |
20 | 139 parser.add_option('-p', '--password', dest='password', |
140 help='user password') | |
6 | 141 parser.add_option('--list', dest='list', action='store_true', default=False, |
142 help="list files") | |
24
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
143 parser.add_option('-l', '--list-destinations', dest='list_destinations', |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
144 action='store_true', default=False, |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
145 help='list preconfigured destinations') |
9 | 146 parser.add_option('--validate', dest='validate', # TODO unused |
147 action='store_true', default=False, | |
148 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
|
149 options, manifests = parser.parse_args(args) |
0 | 150 |
6 | 151 # 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
|
152 if not args: |
5
3464eda1af80
better formatting for command line
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
153 parser.print_help() |
4
550f4b240e20
make almost look like what we want to do
Jeff Hammel <jhammel@mozilla.com>
parents:
2
diff
changeset
|
154 parser.exit() |
0 | 155 |
24
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
156 # print preconfigured destinations if asked |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
157 if options.list_destinations: |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
158 for key in sorted(destinations.keys()): |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
159 print '%s: %s' % (key, destinations[key]) |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
160 return # you're done |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
161 |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
162 # get destination |
11 | 163 assert options.dest |
24
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
164 if options.dest in destinations: |
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
165 options.dest = destinations[options.dest] |
23
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
166 if options.dest.startswith('file://'): |
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
167 options.dest = options.dest[len('file://'):] |
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
168 if '://' not in options.dest: |
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
169 options.dest = os.path.abspath(options.dest) |
7 | 170 |
6 | 171 # read the manifests |
172 files = [] | |
173 for manifest in manifests: | |
22
67e4becc7d49
first steps for cleaning up this awful mess
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
174 for item in parse_manifest(manifest, options.directory): |
6 | 175 if item not in files: |
176 files.append(item) | |
23
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
177 files = [(i, item_url(j, options.dest)) for i, j in files] |
6 | 178 if options.list: |
179 for item in files: | |
14 | 180 print '%s -> %s' % item |
17
0a1aecef2c52
youre done after listing files
Jeff Hammel <jhammel@mozilla.com>
parents:
16
diff
changeset
|
181 return |
0 | 182 |
9 | 183 if not files: |
184 return # you're done | |
185 | |
0 | 186 # render and upload READMEs |
23
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
187 if '://' in options.dest: |
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
188 |
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
189 # check credentials |
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
190 assert options.user and options.password, "Please supply your --user and --password" |
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
191 |
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
192 # upload the files |
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
193 for src, dest in files: |
24
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
194 post(render(src), dest, options.user, options.password) |
23
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
195 |
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
196 else: |
8 | 197 |
11 | 198 # ensure a directory |
199 if os.path.exists(options.dest): | |
200 assert os.path.isdir(options.dest), "'%s' - not a directory" % options.dest | |
8 | 201 |
23
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
202 # render to directory |
9 | 203 for src, dest in files: |
15
d9026d114655
deal with eccentricities of local directories
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
204 |
d9026d114655
deal with eccentricities of local directories
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
205 if dest.startswith('file://'): |
d9026d114655
deal with eccentricities of local directories
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
206 dest = dest[len('file://'):] |
11 | 207 |
208 # create a directory if needed | |
209 dirname = os.path.dirname(dest) | |
16
d6528dd74592
only create the directory if we need to
Jeff Hammel <jhammel@mozilla.com>
parents:
15
diff
changeset
|
210 if os.path.exists(dirname): |
19
493683e17eae
now renders correctly to filesystem for preview
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
211 if not os.path.isdir(dirname): |
493683e17eae
now renders correctly to filesystem for preview
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
212 # deal with filesystem directories vs PATH_INFO |
493683e17eae
now renders correctly to filesystem for preview
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
213 f = file(dirname) |
493683e17eae
now renders correctly to filesystem for preview
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
214 buffer = f.read() |
493683e17eae
now renders correctly to filesystem for preview
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
215 f.close() |
493683e17eae
now renders correctly to filesystem for preview
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
216 os.remove(dirname) |
493683e17eae
now renders correctly to filesystem for preview
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
217 os.makedirs(dirname) |
493683e17eae
now renders correctly to filesystem for preview
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
218 f = file(os.path.join(dirname, 'index.html'), 'w') |
493683e17eae
now renders correctly to filesystem for preview
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
219 f.write(buffer) |
493683e17eae
now renders correctly to filesystem for preview
Jeff Hammel <jhammel@mozilla.com>
parents:
18
diff
changeset
|
220 f.close() |
16
d6528dd74592
only create the directory if we need to
Jeff Hammel <jhammel@mozilla.com>
parents:
15
diff
changeset
|
221 else: |
d6528dd74592
only create the directory if we need to
Jeff Hammel <jhammel@mozilla.com>
parents:
15
diff
changeset
|
222 os.makedirs(dirname) |
11 | 223 |
26
ce7cbf3e08e1
fix bug with local files, index.html, and manifest order
Jeff Hammel <jhammel@mozilla.com>
parents:
25
diff
changeset
|
224 # render to index.html if the directory already exists |
ce7cbf3e08e1
fix bug with local files, index.html, and manifest order
Jeff Hammel <jhammel@mozilla.com>
parents:
25
diff
changeset
|
225 if os.path.isdir(dest): |
ce7cbf3e08e1
fix bug with local files, index.html, and manifest order
Jeff Hammel <jhammel@mozilla.com>
parents:
25
diff
changeset
|
226 dest = os.path.join(dest, 'index.html') |
ce7cbf3e08e1
fix bug with local files, index.html, and manifest order
Jeff Hammel <jhammel@mozilla.com>
parents:
25
diff
changeset
|
227 |
11 | 228 # render |
229 f = file(dest, 'w') | |
24
045544951756
this actually works, by god
Jeff Hammel <jhammel@mozilla.com>
parents:
23
diff
changeset
|
230 f.write(render(src)) |
11 | 231 f.close() |
20 | 232 |
23
e6ed732e8ce6
now works with files anyway
Jeff Hammel <jhammel@mozilla.com>
parents:
22
diff
changeset
|
233 # print out destination directory if using the temporary default |
10 | 234 if options.dest == default_dir: |
11 | 235 print "Files rendered to\n%s" % default_dir |
9 | 236 |
0 | 237 if __name__ == '__main__': |
238 main() |