# HG changeset patch # User Jeff Hammel # Date 1289874490 28800 # Node ID 1818cc524cdeded2438ce1eb1a1b9dbf073076e0 # Parent edabb0bfe107ac052bf28c6708e2edcbfd011e73 change API making substitute return the substituted quantity diff -r edabb0bfe107 -r 1818cc524cde makeitso/makeitso.py --- a/makeitso/makeitso.py Mon Nov 15 18:26:21 2010 -0800 +++ b/makeitso/makeitso.py Mon Nov 15 18:28:10 2010 -0800 @@ -11,7 +11,6 @@ from optparse import OptionParser - try: import tempita except ImportError: @@ -76,7 +75,8 @@ retval[i] = raw_input() return retval -def substitute(content, fp=sys.stdout, variables=None): +def substitute(content, variables=None): + """interactive (for now) substitution""" # remove makeitso shebang if it has one if shebang_re.match(content): @@ -88,7 +88,7 @@ if missing: # TODO: add a switch for interactive or not variables.update(read_variables(missing)) - print >> fp, template.substitute(**variables) + return template.substitute(**variables) def invocation(url, **variables): """returns a string appropriate for TTW invocation""" @@ -161,10 +161,10 @@ for arg in args: f, headers = urllib.urlretrieve(arg) content = file(f).read() - substitute(content, variables=variables) + print substitute(content, variables=variables) else: content = sys.stdin.read() - substitute(content, variables=variables) + print substitute(content, variables=variables) if __name__ == '__main__': main()