Mercurial > mozilla > hg > licenser
diff licenser/licenses.py @ 3:e700bd2ec289
finish basic structure
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 10 May 2010 12:17:38 -0700 |
parents | b8d620fa1116 |
children | e46374799119 |
line wrap: on
line diff
--- a/licenser/licenses.py Mon May 10 11:46:49 2010 -0700 +++ b/licenser/licenses.py Mon May 10 12:17:38 2010 -0700 @@ -13,6 +13,11 @@ self.template) assert os.path.exists(self.template) + def print_license(self): + f = file(self.template) + print f.read() + f.close() + def __call__(self, directory, **kw): variables = self.obtain_variables(**kw) self.interpolate(directory, variables) @@ -29,8 +34,30 @@ """do anything that needs to be done before interpolation""" def interpolate(self, directory, variables): - for file in self.files(directory): - pass + 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(): + print >> f, '# %s' % line.rstrip() + g.close() + + # print the rest of the file + for line in lines: + print >> f, line.rstrip() + f.close() def isempty(self, path): """ @@ -56,7 +83,7 @@ class MPL(License): """Mozilla Public License""" template = 'MPL' # could be implicit here - variables = [ 'author' ] + variables = [ 'author', 'email' ] def pre(self, variables): variables['year'] = datetime.now().year