Mercurial > mozilla > hg > licenser
changeset 21:80193ae99aaf
fill out asterisk-style licenses
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 24 Nov 2011 15:10:25 -0800 |
parents | 272e10163900 |
children | 9db63b0119de |
files | licenser/licenses.py tests/doctest.txt |
diffstat | 2 files changed, 25 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/licenser/licenses.py Thu Nov 24 15:01:16 2011 -0800 +++ b/licenser/licenses.py Thu Nov 24 15:10:25 2011 -0800 @@ -71,8 +71,29 @@ def __call__(self, license): + if self.isempty(): + return # you're done + lines = self.lines() + # open the file for writing - raise NotImplementedError + f = file(self.filename, 'w') + + # print the license + license_lines = license.splitlines(): + for index, line in license_lines: + prefix = ' *' + suffix = '' + if index == len(license_lines) - 1: + suffix = ' */' + if not index: + prefix = '/*' + print >> f, '%s %s%s' % (prefix, line, suffix) + + # print the rest of the file + for line in lines: + f.write(line) + f.close() + class HashCommentsFile(CommentedFile): @@ -95,14 +116,14 @@ print >> f # print the license - f.write(license) + for line in license.splitlines(): + print >> f, '# %s' % line # print the rest of the file for line in lines: f.write(line) f.close() - def isempty(self, path): """ determines if a file is empty; that is, contains only comments
--- a/tests/doctest.txt Thu Nov 24 15:01:16 2011 -0800 +++ b/tests/doctest.txt Thu Nov 24 15:10:25 2011 -0800 @@ -15,4 +15,5 @@ >>> license = licenses.MPL() >>> variables = {'author': 'Jeff Hammel', 'email': 'k0s@k0s.org'} + >>> variables = license.obtain_variables(**variables) >>> license.interpolate(directory, variables)