comparison makeitso/makeitso.py @ 39:a2cdce0108e1

get directory substitution sorta working; start stubbing mixed case
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 01 Jan 2011 23:00:59 -0800
parents 9739212a63c3
children 6b4c8f23192f
comparison
equal deleted inserted replaced
38:9739212a63c3 39:a2cdce0108e1
243 variables.update(dict([(i, '') for i in missed])) 243 variables.update(dict([(i, '') for i in missed]))
244 244
245 return missing 245 return missing
246 246
247 def _substitute(self, **variables): 247 def _substitute(self, **variables):
248 # TODO: do this with recursion instead of os.walk so that
249 # per-directory control may be asserted
248 250
249 # make output directory if necessary 251 # make output directory if necessary
250 output = self.output 252 output = self.output
251 if output and not os.path.exists(output): 253 if output and not os.path.exists(output):
252 os.makedirs(output) 254 os.makedirs(output)
253 255
254 for dirname, dirnames, filenames in os.walk(self.name): 256 for dirname, dirnames, filenames in os.walk(self.name):
255 257
256 # interpolate directory names 258 # interpolate directory names
257 for d in dirnames: 259 for d in dirnames:
258 path = os.path.join(dirname, d) 260 path = os.path.join(dirname, d)
259 interpolated = ContentTemplate(path).substitute(**variables) 261 interpolated = ContentTemplate(path).substitute(**variables)
260 if os.path.exists(interpolated): 262 target = os.path.join(self.output, interpolated.split(self.name, 1)[-1].strip(os.path.sep))
263
264 if os.path.exists(target):
261 # ensure its a directory 265 # ensure its a directory
262 pass 266 # TODO: check this first before interpolation is in progress
267 assert os.path.isdir(target), "Can't substitute a directory on top of the file"
263 else: 268 else:
264 os.makedirs(interpolated) 269 os.makedirs(target)
270
271 # interpolate files
272 for filename in filenames:
273 path = os.path.join(dirname, filename)
274 interpolated = ContentTemplate(path).substitute(**variables)
275 target = os.path.join(self.output, interpolated.split(self.name, 1)[-1].strip(os.path.sep))
265 276
277 if os.path.exists(target):
278 # ensure its a directory
279 # TODO: check this first before interpolation is in progress
280 assert os.path.isfile(target), "Can't substitute a file on top of a directory"
281 template = URITemplate(path, output=target, interactive=False)
282 template.substitute(**variables)
283
266 284
267 class PolyTemplate(ContentTemplate): 285 class PolyTemplate(ContentTemplate):
268 """ 286 """
269 template for several files/directories 287 template for several files/directories
270 """ 288 """