diff makeitso/makeitso.py @ 16:1818cc524cde

change API making substitute return the substituted quantity
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 15 Nov 2010 18:28:10 -0800
parents edabb0bfe107
children c879b93c3f15
line wrap: on
line diff
--- 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()