diff makeitso/template.py @ 99:d9c6e26a42ff

fix up interactivity of API template a bit. still doesnt quite work
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 11 Jan 2011 11:53:02 -0800
parents 26b9c3bba04e
children b54898f7d8a9
line wrap: on
line diff
--- a/makeitso/template.py	Tue Jan 11 11:35:38 2011 -0800
+++ b/makeitso/template.py	Tue Jan 11 11:53:02 2011 -0800
@@ -37,6 +37,11 @@
         else:
             self.value = value
         self._set = True
+        return self.value
+
+    def isset(self):
+        """whether the variable has been set or not"""
+        return self._set
 
     def read(self, fd=sys.stdout):
         """prompt and read the variable from stdin"""
@@ -46,9 +51,9 @@
     def display(self):
         description = self.description or self.name
         if self.default:
-            return 'Enter %s [DEFAULT: %s]:' % (description, repr(self.default))
+            return 'Enter %s [DEFAULT: %s]: ' % (description, repr(self.default))
         else:
-            return 'Enter %s:' % description
+            return 'Enter %s: ' % description
 
     def __repr__(self):
         return "Variable(name='%s')" % self.name
@@ -137,13 +142,22 @@
 
         # get known needed variables
         for var in self.vars:
-            if var.name not in vars:
-                missing.add(var)
+            if var.name in vars:
+                if var.default is Undefined:
+                    missing.add(var.name)
+                    continue
+                if self.usedefaults and not var.isset():
+                    missing.add(var.name)
+            else:
+                missing.add(var.name)
 
         if self.look:
             # scan templates for other variables
-            raise NotImplementedError
-                
+            template = PolyTemplate(self._templates,
+                                    interactive=self.interactive,
+                                    variables=vars)
+            missing.update(template.missing())
+
         return missing
 
     def pre(self, variables):
@@ -173,7 +187,8 @@
         retval = {}
         for i in variables:
             if i in self.vardict:
-                self.vardict[i].read()
+                value = self.vardict[i].read()
+                retval[i] = value
             else:
                 retval.update(ContentTemplate.read_variables(self, (i,)))
         return retval