# HG changeset patch # User Jeff Hammel # Date 1322176225 28800 # Node ID 80193ae99aafad0a442fa19a6b9e050162c9dc41 # Parent 272e10163900f9dcd0367855cbae410b0e20afb2 fill out asterisk-style licenses diff -r 272e10163900 -r 80193ae99aaf licenser/licenses.py --- 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 diff -r 272e10163900 -r 80193ae99aaf tests/doctest.txt --- 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)