Mercurial > hg > MakeItSo
comparison makeitso/template.py @ 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 |
comparison
equal
deleted
inserted
replaced
| 99:d9c6e26a42ff | 100:b54898f7d8a9 |
|---|---|
| 44 return self._set | 44 return self._set |
| 45 | 45 |
| 46 def read(self, fd=sys.stdout): | 46 def read(self, fd=sys.stdout): |
| 47 """prompt and read the variable from stdin""" | 47 """prompt and read the variable from stdin""" |
| 48 fd.write(self.display()) | 48 fd.write(self.display()) |
| 49 self.set(raw_input()) | 49 return self.set(raw_input()) |
| 50 | 50 |
| 51 def display(self): | 51 def display(self): |
| 52 description = self.description or self.name | 52 description = self.description or self.name |
| 53 if self.default: | 53 if self.default: |
| 54 return 'Enter %s [DEFAULT: %s]: ' % (description, repr(self.default)) | 54 return 'Enter %s [DEFAULT: %s]: ' % (description, repr(self.default)) |
| 144 for var in self.vars: | 144 for var in self.vars: |
| 145 if var.name in vars: | 145 if var.name in vars: |
| 146 if var.default is Undefined: | 146 if var.default is Undefined: |
| 147 missing.add(var.name) | 147 missing.add(var.name) |
| 148 continue | 148 continue |
| 149 if self.usedefaults and not var.isset(): | 149 if (not self.usedefaults) and (not var.isset()): |
| 150 missing.add(var.name) | 150 missing.add(var.name) |
| 151 else: | 151 else: |
| 152 missing.add(var.name) | 152 missing.add(var.name) |
| 153 | 153 |
| 154 if self.look: | 154 if self.look: |
| 161 return missing | 161 return missing |
| 162 | 162 |
| 163 def pre(self, variables): | 163 def pre(self, variables): |
| 164 """do stuff before interpolation""" | 164 """do stuff before interpolation""" |
| 165 | 165 |
| 166 def substitute(self, variables, output): | 166 def substitute(self, variables, output=None): |
| 167 """do the substitution""" | 167 """do the substitution""" |
| 168 | 168 |
| 169 vars = self.get_variables(**variables) | 169 vars = self.get_variables(**variables) |
| 170 self.pre(vars) | 170 self.pre(vars) |
| 171 self.check_missing(vars) | 171 self.check_missing(vars) |
