# HG changeset patch # User Jeff Hammel # Date 1322012481 28800 # Node ID a8ad01735f7131f5ba3dc6a06cfb7088d132d26d # Parent 952eb98f6f6ecc95aeeac1e5ade3a282d117c808 more stubbing diff -r 952eb98f6f6e -r a8ad01735f71 licenser/licenses.py --- a/licenser/licenses.py Tue Nov 22 16:59:34 2011 -0800 +++ b/licenser/licenses.py Tue Nov 22 17:41:21 2011 -0800 @@ -36,6 +36,7 @@ # ***** END LICENSE BLOCK ***** import os +import urllib2 from datetime import datetime from string import Template @@ -45,16 +46,17 @@ variables = [] # required variables def __init__(self): - if not os.path.isabs(self.template): + if self.template and not os.path.isabs(self.template): self.template = os.path.join(os.path.dirname(__file__), 'licenses', self.template) assert os.path.exists(self.template) + def license(self): + return file(self.template).read() + def print_license(self): - f = file(self.template) - print f.read() - f.close() + print self.license() def __call__(self, directory, **kw): variables = self.obtain_variables(**kw) @@ -86,8 +88,8 @@ print >> f # print the license - g = file(self.template) - for line in g.readlines(): + g = self.license() + for line in g.splitlines(): line = line.rstrip() _template = Template(line) print >> f, '# %s' % _template.substitute(**variables) @@ -98,7 +100,6 @@ print >> f, line.rstrip() f.close() - def interpolate(self, directory, variables): for _file in self.files(directory): self.interpolate_file(_file, variables) @@ -128,6 +129,29 @@ """Mozilla Public License""" template = 'MPL' # could be implicit here variables = [ 'author', 'email' ] + url = 'http://www.mozilla.org/MPL/boilerplate-1.1/mpl-tri-license-txt' + + def license(self): + # get the raw license + raw = urllib2.urlopen(self.url).read() + + # now make it something not crazy + lines = raw.splitlines() + contributor_index = None + for index, line in enumerate(lines): + if line.startswith('The Original Code is'): + lines[index] = 'The Original Code is mozilla.org code.' + if line.startswith('_'): + lines[index] = 'the Mozilla Foundation.' + if '2___' in line: + lines[index] = line.replace('2___', '${year}') + if line.startswith('Contributor'): + contributor_index = index + + assert contributor_index + lines[contibutor_index] = ' ${author} <${email}>' + return '\n'.join(lines) def pre(self, variables): variables['year'] = datetime.now().year +