Mercurial > hg > MakeItSo
comparison makeitso/template.py @ 63:b91133e3b02d
override get_variables for API template; could instead do this in the ctor, alternately
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Thu, 06 Jan 2011 17:58:34 -0800 |
| parents | 30100690ad3f |
| children | c20277dbf8fa |
comparison
equal
deleted
inserted
replaced
| 62:30100690ad3f | 63:b91133e3b02d |
|---|---|
| 70 """ | 70 """ |
| 71 - output : output file or directory | 71 - output : output file or directory |
| 72 - interactive : whether tointeractively get variables | 72 - interactive : whether tointeractively get variables |
| 73 - usedefaults : try to use the default values if not specified | 73 - usedefaults : try to use the default values if not specified |
| 74 """ | 74 """ |
| 75 | 75 |
| 76 # boilerplate | |
| 76 assert self.templates | 77 assert self.templates |
| 77 self.output = output | 78 self.output = output |
| 78 self.interactive = interactive | 79 self.interactive = interactive |
| 79 self.location = os.path.dirname(os.path.abspath(__file__)) | 80 self.location = os.path.dirname(os.path.abspath(__file__)) |
| 80 self.defaults = variables.copy() | 81 self.defaults = variables.copy() |
| 82 self.usedefaults = usedefaults | |
| 81 | 83 |
| 82 # make a dictionary of the variables for lookup convenience | 84 # make a dictionary of the variables for lookup convenience |
| 83 self.vardict = {} | 85 self.vardict = {} |
| 84 for i in self.vars: | 86 for i in self.vars: |
| 85 self.vardict[i.name] = i | 87 self.vardict[i.name] = i |
| 92 path = template | 94 path = template |
| 93 else: | 95 else: |
| 94 path = os.path.join(self.location, template) | 96 path = os.path.join(self.location, template) |
| 95 assert os.path.exists(template) | 97 assert os.path.exists(template) |
| 96 | 98 |
| 99 def get_variables(self, **variables): | |
| 100 # XXX could do this in the ctor | |
| 101 vars = ContentTemplate.get_variables(self, **variables) | |
| 102 if self.usedefaults: | |
| 103 for variable in self.vars: | |
| 104 if variable.name in vars: | |
| 105 continue | |
| 106 if variable.default is not Undefined: | |
| 107 vars[variable.name] = variable.default | |
| 108 return vars | |
| 109 | |
| 97 def missing(self, **variables): | 110 def missing(self, **variables): |
| 111 vars = self.get_variables(**variables) | |
| 98 missing = set([]) | 112 missing = set([]) |
| 99 if self.look: | 113 if self.look: |
| 100 pass | 114 pass |
| 101 else: | 115 else: |
| 102 for var in self.vars: | 116 for var in self.vars: |
| 103 if self.usedefaults: | 117 if self.usedefaults: |
| 104 pass | 118 import pdb; pdb.set_trace() |
| 105 else: | 119 else: |
| 106 pass | 120 pass |
| 107 | 121 |
| 108 def pre(self, **variables): | 122 def pre(self, **variables): |
| 109 """do stuff before interpolation""" | 123 """do stuff before interpolation""" |
