Mercurial > hg > MakeItSo
comparison makeitso/makeitso.py @ 267:7e3a32f2794a
py3 fixes
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Fri, 27 Apr 2018 14:07:46 -0700 |
parents | f10f5beb8ad1 |
children | 64979cfff465 |
comparison
equal
deleted
inserted
replaced
266:402b17ba3d19 | 267:7e3a32f2794a |
---|---|
148 missing = set([]) | 148 missing = set([]) |
149 while True: | 149 while True: |
150 try: | 150 try: |
151 tempita.Template.substitute(self, **vars) | 151 tempita.Template.substitute(self, **vars) |
152 return missing | 152 return missing |
153 except NameError, e: | 153 except NameError as e: |
154 missed = get_missing(e) | 154 missed = get_missing(e) |
155 missing.add(missed) | 155 missing.add(missed) |
156 vars[missed] = '' | 156 vars[missed] = '' |
157 return missing | 157 return missing |
158 | 158 |
180 | 180 |
181 def read_variables(self, variables): | 181 def read_variables(self, variables): |
182 """read variables from stdin""" | 182 """read variables from stdin""" |
183 retval = {} | 183 retval = {} |
184 for i in variables: | 184 for i in variables: |
185 print 'Enter %s: ' % i, | 185 print ('Enter %s: ' % i) |
186 retval[i] = raw_input() | 186 retval[i] = raw_input() |
187 return retval | 187 return retval |
188 | 188 |
189 | 189 |
190 class URITemplate(ContentTemplate): | 190 class URITemplate(ContentTemplate): |
450 for key in sorted(entry_points.keys()): | 450 for key in sorted(entry_points.keys()): |
451 template_class = entry_points[key] | 451 template_class = entry_points[key] |
452 description = getattr(template_class, 'description', '') | 452 description = getattr(template_class, 'description', '') |
453 description = description or getattr(template_class, '__doc__', '') | 453 description = description or getattr(template_class, '__doc__', '') |
454 description = description.strip() | 454 description = description.strip() |
455 print key + ': ' + description | 455 print (key + ': ' + description) |
456 return | 456 return |
457 | 457 |
458 # print the variables for the templates | 458 # print the variables for the templates |
459 if options.variables: | 459 if options.variables: |
460 | 460 |
467 template = PolyTemplate(templates=args) | 467 template = PolyTemplate(templates=args) |
468 variables = template.variables() | 468 variables = template.variables() |
469 | 469 |
470 # print them | 470 # print them |
471 for variable in sorted(variables): | 471 for variable in sorted(variables): |
472 print variable | 472 print (variable) |
473 return | 473 return |
474 | 474 |
475 # template variables | 475 # template variables |
476 variables = {} | 476 variables = {} |
477 _args = [] | 477 _args = [] |
496 | 496 |
497 # print TTW commandline for invocation | 497 # print TTW commandline for invocation |
498 if options.commandline: | 498 if options.commandline: |
499 if args: | 499 if args: |
500 for arg in args: | 500 for arg in args: |
501 print invocation(arg, **variables) | 501 print (invocation(arg, **variables)) |
502 else: | 502 else: |
503 print invocation('[URI]', **variables) | 503 print (invocation('[URI]', **variables)) |
504 return | 504 return |
505 | 505 |
506 | 506 |
507 # get the content | 507 # get the content |
508 if args: | 508 if args: |
509 template = PolyTemplate(templates=args, | 509 template = PolyTemplate(templates=args, |
510 variables=variables) | 510 variables=variables) |
511 template.substitute({}, output=options.output) | 511 template.substitute({}, output=options.output) |
512 else: | 512 else: |
513 template = ContentTemplate(sys.stdin.read(), variables=variables) | 513 template = ContentTemplate(sys.stdin.read(), variables=variables) |
514 print template.substitute() | 514 print (template.substitute()) |
515 | 515 |
516 # cleanup | 516 # cleanup |
517 cleanup() | 517 cleanup() |
518 | 518 |
519 if __name__ == '__main__': | 519 if __name__ == '__main__': |