changeset 11:a8ad01735f71

more stubbing
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 22 Nov 2011 17:41:21 -0800
parents 952eb98f6f6e
children 697b6f892e12
files licenser/licenses.py
diffstat 1 files changed, 31 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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
+