comparison makeitso/makeitso.py @ 28:dc18d6db4956

depend on trunk tempita; stubbing for next stage
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 22 Dec 2010 13:30:09 -0800
parents ac44c36da885
children 1549be7f0fcb
comparison
equal deleted inserted replaced
27:ac44c36da885 28:dc18d6db4956
131 retval = {} 131 retval = {}
132 for i in variables: 132 for i in variables:
133 print 'Enter %s: ' % i, 133 print 'Enter %s: ' % i,
134 retval[i] = raw_input() 134 retval[i] = raw_input()
135 return retval 135 return retval
136
137 ### functions for substitution
136 138
137 def substitute(content, variables=None): 139 def substitute(content, variables=None):
138 """interactive (for now) substitution""" 140 """interactive (for now) substitution"""
139 141
140 # remove makeitso shebang if it has one 142 # remove makeitso shebang if it has one
147 if missing: 149 if missing:
148 # TODO: add a switch for interactive or not 150 # TODO: add a switch for interactive or not
149 variables.update(read_variables(missing)) 151 variables.update(read_variables(missing))
150 return template.substitute(**variables) 152 return template.substitute(**variables)
151 153
154 def substitute_directory(directory, output=None, variables=None):
155 # TODO: interpolate directory names
156
157 ###
158
152 def invocation(url, **variables): 159 def invocation(url, **variables):
153 """returns a string appropriate for TTW invocation""" 160 """returns a string appropriate for TTW invocation"""
154 variables_string = ' '.join(['%s=%s' % (i,j) for i,j in variables.items()]) 161 variables_string = ' '.join(['%s=%s' % (i,j) for i,j in variables.items()])
155 return 'python <(curl %s) %s %s' % (location, url, variables_string) 162 return 'python <(curl %s) %s %s' % (location, url, variables_string)
156 163
157 def main(args=sys.argv[1:]): 164 def main(args=sys.argv[1:]):
158 165
159 # create option parser 166 # create option parser
160 usage = '%prog [options] template <template> <...>' 167 usage = '%prog [options] template <template> <...>'
161 parser = OptionParser(usage, description=__doc__) 168 parser = OptionParser(usage, description=__doc__)
169
170 # delimeters
171 # XXX needs tempita trunk
162 parser.add_option('-[', '--start-braces', dest='start_braces', 172 parser.add_option('-[', '--start-braces', dest='start_braces',
163 help='starting delimeter') 173 help='starting delimeter')
164 parser.add_option('-]', '--end-braces', dest='end_braces', 174 parser.add_option('-]', '--end-braces', dest='end_braces',
165 help='starting delimeter') 175 help='starting delimeter')
176
177 # options about where to put things
166 parser.add_option('--in-place', dest='in_place', 178 parser.add_option('--in-place', dest='in_place',
167 action='store_true', default=False, 179 action='store_true', default=False,
168 help='interpret files in place') # TODO: unused 180 help='interpret files in place') # TODO: unused
181 parser.add_option('-o', '--output', dest='output',
182 help='where to put the output (filename or directory)')
183
184 #
169 parser.add_option('--commandline', dest='commandline', 185 parser.add_option('--commandline', dest='commandline',
170 action='store_true', default=False, 186 action='store_true', default=False,
171 help="print the commandline to invoke this script TTW") 187 help="print the commandline to invoke this script TTW")
172 parser.add_option('--variables', dest='variables', 188 parser.add_option('--variables', dest='variables',
173 action='store_true', default=False, 189 action='store_true', default=False,