Mercurial > hg > MakeItSo
diff makeitso/template.py @ 63:b91133e3b02d
override get_variables for API template; could instead do this in the ctor, alternately
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 06 Jan 2011 17:58:34 -0800 |
parents | 30100690ad3f |
children | c20277dbf8fa |
line wrap: on
line diff
--- a/makeitso/template.py Thu Jan 06 17:49:40 2011 -0800 +++ b/makeitso/template.py Thu Jan 06 17:58:34 2011 -0800 @@ -72,12 +72,14 @@ - interactive : whether tointeractively get variables - usedefaults : try to use the default values if not specified """ - + + # boilerplate assert self.templates self.output = output self.interactive = interactive self.location = os.path.dirname(os.path.abspath(__file__)) self.defaults = variables.copy() + self.usedefaults = usedefaults # make a dictionary of the variables for lookup convenience self.vardict = {} @@ -94,14 +96,26 @@ path = os.path.join(self.location, template) assert os.path.exists(template) + def get_variables(self, **variables): + # XXX could do this in the ctor + vars = ContentTemplate.get_variables(self, **variables) + if self.usedefaults: + for variable in self.vars: + if variable.name in vars: + continue + if variable.default is not Undefined: + vars[variable.name] = variable.default + return vars + def missing(self, **variables): + vars = self.get_variables(**variables) missing = set([]) if self.look: pass else: for var in self.vars: if self.usedefaults: - pass + import pdb; pdb.set_trace() else: pass