changeset 100:b54898f7d8a9

now API template variables seem to work
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 11 Jan 2011 12:04:25 -0800
parents d9c6e26a42ff
children 80a57bf2b7f4
files examples/doctest.txt makeitso/template.py
diffstat 2 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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)