# HG changeset patch # User Jeff Hammel # Date 1294775582 28800 # Node ID d9c6e26a42ff530c217f09147aa7c7c36945c840 # Parent 37f92ae8f999dcec2180083a40f06bde36760a14 fix up interactivity of API template a bit. still doesnt quite work diff -r 37f92ae8f999 -r d9c6e26a42ff makeitso/template.py --- 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