comparison makeitso/template.py @ 159:cfd4f1e91090

wip
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 30 Jul 2013 15:20:38 -0700
parents b2152efec89a
children f10f5beb8ad1
comparison
equal deleted inserted replaced
158:ff1f41a18da9 159:cfd4f1e91090
14 Undefined = Undefined() # singleton 14 Undefined = Undefined() # singleton
15 15
16 16
17 class Variable(object): 17 class Variable(object):
18 """variable object for MakeItSo templates""" 18 """variable object for MakeItSo templates"""
19 19
20 def __init__(self, name, description=None, default=Undefined, 20 def __init__(self, name, description=None, default=Undefined,
21 cast=None): 21 cast=None):
22 self.name = name 22 self.name = name
23 self.default = default 23 self.default = default
24 self.description = description 24 self.description = description
114 self.vardict[i.name] = i 114 self.vardict[i.name] = i
115 115
116 # ensure all of these templates exist 116 # ensure all of these templates exist
117 self._templates = [] 117 self._templates = []
118 for template in self.templates: 118 for template in self.templates:
119 if not isinstance(template, basestring):
120 template = os.path.join(*template)
119 if template.startswith('http://') or template.startswith('https://'): 121 if template.startswith('http://') or template.startswith('https://'):
120 self._templates.append(template) 122 self._templates.append(template)
121 continue 123 continue
122 if os.path.isabs(template): 124 if os.path.isabs(template):
123 path = template 125 path = template
190 # do whatever you need to do afterwards 192 # do whatever you need to do afterwards
191 self.post(vars, output) 193 self.post(vars, output)
192 194
193 def post(self, variables, output): 195 def post(self, variables, output):
194 """do stuff after interpolation""" 196 """do stuff after interpolation"""
195 197
196 def read_variables(self, variables): 198 def read_variables(self, variables):
197 """read variables from stdin""" 199 """read variables from stdin"""
198 retval = {} 200 retval = {}
199 for i in variables: 201 for i in variables:
200 if i in self.vardict: 202 if i in self.vardict: