diff licenser/licenses.py @ 6:0a01ed263c06

add ability to interpolate a single file; should move to makeitso
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 13 Dec 2010 13:26:31 -0800
parents f7d485cedc80
children 952eb98f6f6e
line wrap: on
line diff
--- a/licenser/licenses.py	Mon May 10 12:28:59 2010 -0700
+++ b/licenser/licenses.py	Mon Dec 13 13:26:31 2010 -0800
@@ -70,33 +70,37 @@
   def pre(self, variables):
     """do anything that needs to be done before interpolation"""
 
+  def interpolate_file(self, _file, variables):
+
+    # get the file lines
+    f = file(_file)
+    lines = [ i.rstrip() for i in f.readlines() ]
+    f.close()
+    f = file(_file, 'w')
+
+    # print shebang if it exists
+    if lines[0].startswith('#!'):
+      shebang = lines.pop(0)
+      print >> f, shebang
+      print >> f
+
+    # print the license
+    g = file(self.template)
+    for line in g.readlines():
+      line = line.rstrip()
+      _template = Template(line)
+      print >> f, '# %s' % _template.substitute(**variables)
+    g.close()
+
+    # print the rest of the file
+    for line in lines:
+      print >> f, line.rstrip()
+    f.close()
+    
+
   def interpolate(self, directory, variables):
     for _file in self.files(directory):
-
-      # get the file lines
-      f = file(_file)
-      lines = [ i.rstrip() for i in f.readlines() ]
-      f.close()
-      f = file(_file, 'w')
-
-      # print shebang if it exists
-      if lines[0].startswith('#!'):
-        shebang = lines.pop(0)
-        print >> f, shebang
-        print >> f
-
-      # print the license
-      g = file(self.template)
-      for line in g.readlines():
-        line = line.rstrip()
-        _template = Template(line)
-        print >> f, '# %s' % _template.substitute(**variables)
-      g.close()
-
-      # print the rest of the file
-      for line in lines:
-        print >> f, line.rstrip()
-      f.close()
+      self.interpolate_file(_file, variables)
 
   def isempty(self, path):
     """