Mercurial > hg > MakeItSo
diff 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 |
line wrap: on
line diff
--- a/makeitso/makeitso.py Sat Jan 01 22:34:29 2011 -0800 +++ b/makeitso/makeitso.py Sat Jan 01 23:00:59 2011 -0800 @@ -245,6 +245,8 @@ return missing def _substitute(self, **variables): + # TODO: do this with recursion instead of os.walk so that + # per-directory control may be asserted # make output directory if necessary output = self.output @@ -255,14 +257,30 @@ # interpolate directory names for d in dirnames: - path = os.path.join(dirname, d) - interpolated = ContentTemplate(path).substitute(**variables) - if os.path.exists(interpolated): + path = os.path.join(dirname, d) + interpolated = ContentTemplate(path).substitute(**variables) + target = os.path.join(self.output, interpolated.split(self.name, 1)[-1].strip(os.path.sep)) + + if os.path.exists(target): # ensure its a directory - pass + # TODO: check this first before interpolation is in progress + assert os.path.isdir(target), "Can't substitute a directory on top of the file" else: - os.makedirs(interpolated) + os.makedirs(target) + + # interpolate files + for filename in filenames: + path = os.path.join(dirname, filename) + interpolated = ContentTemplate(path).substitute(**variables) + target = os.path.join(self.output, interpolated.split(self.name, 1)[-1].strip(os.path.sep)) + if os.path.exists(target): + # ensure its a directory + # TODO: check this first before interpolation is in progress + assert os.path.isfile(target), "Can't substitute a file on top of a directory" + template = URITemplate(path, output=target, interactive=False) + template.substitute(**variables) + class PolyTemplate(ContentTemplate): """