comparison makeitso/makeitso.py @ 101:80a57bf2b7f4

fixed a few problems
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 11 Jan 2011 14:23:17 -0800
parents b6a46332cced
children a6aff990985b
comparison
equal deleted inserted replaced
100:b54898f7d8a9 101:80a57bf2b7f4
163 if missing: 163 if missing:
164 if self.interactive: 164 if self.interactive:
165 vars.update(self.read_variables(missing)) 165 vars.update(self.read_variables(missing))
166 else: 166 else:
167 raise MissingVariablesException(missing) 167 raise MissingVariablesException(missing)
168 168
169
170 def variables(self): 169 def variables(self):
171 """return the variables needed for a template""" 170 """return the variables needed for a template"""
172 return self.missing() 171 return self.missing()
173 172
174 def substitute(self, **variables): 173 def substitute(self, **variables):
206 ContentTemplate.__init__(self, content, name=uri, 205 ContentTemplate.__init__(self, content, name=uri,
207 interactive=interactive, 206 interactive=interactive,
208 variables=variables) 207 variables=variables)
209 208
210 def substitute(self, variables, output=None): 209 def substitute(self, variables, output=None):
210
211 # interpolate
211 content = ContentTemplate.substitute(self, **variables) 212 content = ContentTemplate.substitute(self, **variables)
212 213
213 # write output 214 # write output
214 output = output or sys.stdout 215 output = output or sys.stdout
215 if isinstance(output, basestring): 216 if isinstance(output, basestring):
290 for dirname, dirnames, filenames in os.walk(self.name): 291 for dirname, dirnames, filenames in os.walk(self.name):
291 292
292 # interpolate directory names 293 # interpolate directory names
293 for d in dirnames: 294 for d in dirnames:
294 path = os.path.join(dirname, d) 295 path = os.path.join(dirname, d)
295 interpolated = ContentTemplate(path).substitute(**variables) 296 interpolated = ContentTemplate(path).substitute(**vars)
296 target = os.path.join(output, interpolated.split(self.name, 1)[-1].strip(os.path.sep)) 297 target = os.path.join(output, interpolated.split(self.name, 1)[-1].strip(os.path.sep))
297 298
298 if os.path.exists(target): 299 if os.path.exists(target):
299 # ensure its a directory 300 # ensure its a directory
300 # TODO: check this first before interpolation is in progress 301 # TODO: check this first before interpolation is in progress
305 # interpolate files 306 # interpolate files
306 for filename in filenames: 307 for filename in filenames:
307 308
308 # interpolate filenames 309 # interpolate filenames
309 path = os.path.join(dirname, filename) 310 path = os.path.join(dirname, filename)
310 interpolated = ContentTemplate(path).substitute(**variables) 311 interpolated = ContentTemplate(path).substitute(**vars)
311 target = os.path.join(output, interpolated.split(self.name, 1)[-1].strip(os.path.sep)) 312 target = os.path.join(output, interpolated.split(self.name, 1)[-1].strip(os.path.sep))
312 313
313 # interpolate their contents 314 # interpolate their contents
314 if os.path.exists(target): 315 if os.path.exists(target):
315 # ensure its a directory 316 # ensure its a directory
316 assert os.path.isfile(target), "Can't substitute a file on top of a directory" 317 assert os.path.isfile(target), "Can't substitute a file on top of a directory"
317 template = URITemplate(path, interactive=False) 318 template = URITemplate(path, interactive=False)
318 template.substitute(variables, target) 319 template.substitute(vars, target)
319 320
320 321
321 class PolyTemplate(ContentTemplate): 322 class PolyTemplate(ContentTemplate):
322 """template for several files/directories""" 323 """template for several files/directories"""
323 324