Mercurial > mozilla > hg > DocumentIt
comparison document_it.py @ 11:df6c2e71b87e
actually render
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 01 Aug 2011 23:25:46 -0700 |
parents | 853214384bd0 |
children | 54e27f046cd2 |
comparison
equal
deleted
inserted
replaced
10:853214384bd0 | 11:df6c2e71b87e |
---|---|
108 if not args: | 108 if not args: |
109 parser.print_help() | 109 parser.print_help() |
110 parser.exit() | 110 parser.exit() |
111 | 111 |
112 # get base url | 112 # get base url |
113 assert options.dest | |
113 if '://' in options.dest: | 114 if '://' in options.dest: |
114 baseurl = options.dest | 115 baseurl = options.dest |
115 else: | 116 else: |
116 baseurl = 'file://' + options.dest | 117 baseurl = 'file://' + options.dest |
117 | 118 |
118 # read the manifests | 119 # read the manifests |
119 files = [] | 120 files = [] |
120 for manifest in manifests: | 121 for manifest in manifests: |
121 for item in parse_manifest(manifest): | 122 for item in parse_manifest(manifest, options.directory): |
122 if item not in files: | 123 if item not in files: |
123 files.append(item) | 124 files.append(item) |
124 if options.list: | 125 if options.list: |
125 for item in files: | 126 for item in files: |
126 print '%s -> %s/%s' % (item[0], baseurl.rstrip('/'), item[1].lstrip('/')) | 127 print '%s -> %s/%s' % (item[0], baseurl.rstrip('/'), item[1].lstrip('/')) |
127 | 128 |
128 if not files: | 129 if not files: |
129 return # you're done | 130 return # you're done |
130 | 131 |
131 # render and upload READMEs | 132 # render and upload READMEs |
132 if options.directory: | 133 if baseurl.startswith('file://'): |
134 options.dest = baseurl[len('file://'):] # deals with --dest file:///foo from command line | |
133 | 135 |
134 # create a directory if needed | 136 # ensure a directory |
135 if os.path.exists(options.directory): | 137 if os.path.exists(options.dest): |
136 assert os.path.isdir(options.directory), "'%s' - not a directory" % options.directory | 138 assert os.path.isdir(options.dest), "'%s' - not a directory" % options.dest |
137 else: | |
138 os.makedirs(options.directory) | |
139 | 139 |
140 # TODO render to directory | 140 # TODO render to directory |
141 for src, dest in files: | 141 for src, dest in files: |
142 dest = os.path.join(options.dest, dest) | 142 dest = os.path.join(options.dest, dest) |
143 | |
144 # create a directory if needed | |
145 dirname = os.path.dirname(dest) | |
146 os.makedirs(dirname) | |
147 | |
148 # render | |
149 f = file(dest, 'w') | |
150 buffer = markdown.Markdown().convert(file(src).read()) | |
151 f.write(buffer) | |
152 f.close() | |
143 else: | 153 else: |
144 # TODO check credentials | 154 # TODO check credentials |
145 raise NotImplementedError | 155 raise NotImplementedError |
146 | 156 |
157 | |
147 if options.dest == default_dir: | 158 if options.dest == default_dir: |
148 print "Files rendered to %s" % default_dir | 159 print "Files rendered to\n%s" % default_dir |
149 | 160 |
150 if __name__ == '__main__': | 161 if __name__ == '__main__': |
151 main() | 162 main() |