# HG changeset patch # User Jeff Hammel # Date 1294776265 28800 # Node ID b54898f7d8a9f86fb2707ddf13f73061d4ee767e # Parent d9c6e26a42ff530c217f09147aa7c7c36945c840 now API template variables seem to work diff -r d9c6e26a42ff -r b54898f7d8a9 examples/doctest.txt --- a/examples/doctest.txt Tue Jan 11 11:53:02 2011 -0800 +++ b/examples/doctest.txt Tue Jan 11 12:04:25 2011 -0800 @@ -97,11 +97,25 @@ ... vars = [Variable(name='name', default='bar')] >>> buffer = tempfile.mktemp() >>> apitemplate = MyTemplate(interactive=False) + >>> apitemplate.missing() + set([]) >>> apitemplate.substitute({}, buffer) >>> file(buffer).read().strip() 'Hello bar' >>> os.remove(buffer) +If you dont use the defaults, then you will get a missing variable:: + + >>> apitemplate.usedefaults = False + >>> apitemplate.missing() + set(['name']) + >>> try: + ... apitemplate.substitute({}) + ... except Exception, e: + ... pass + >>> isinstance(e, makeitso.MissingVariablesException) + True + Test CLI handler: >>> from makeitso.cli import MakeItSoCLI diff -r d9c6e26a42ff -r b54898f7d8a9 makeitso/template.py --- a/makeitso/template.py Tue Jan 11 11:53:02 2011 -0800 +++ b/makeitso/template.py Tue Jan 11 12:04:25 2011 -0800 @@ -46,7 +46,7 @@ def read(self, fd=sys.stdout): """prompt and read the variable from stdin""" fd.write(self.display()) - self.set(raw_input()) + return self.set(raw_input()) def display(self): description = self.description or self.name @@ -146,7 +146,7 @@ if var.default is Undefined: missing.add(var.name) continue - if self.usedefaults and not var.isset(): + if (not self.usedefaults) and (not var.isset()): missing.add(var.name) else: missing.add(var.name) @@ -163,7 +163,7 @@ def pre(self, variables): """do stuff before interpolation""" - def substitute(self, variables, output): + def substitute(self, variables, output=None): """do the substitution""" vars = self.get_variables(**variables)