Mercurial > mozilla > hg > licenser
comparison 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 |
comparison
equal
deleted
inserted
replaced
2:b8d620fa1116 | 3:e700bd2ec289 |
---|---|
10 if not os.path.isabs(self.template): | 10 if not os.path.isabs(self.template): |
11 self.template = os.path.join(os.path.dirname(__file__), | 11 self.template = os.path.join(os.path.dirname(__file__), |
12 'licenses', | 12 'licenses', |
13 self.template) | 13 self.template) |
14 assert os.path.exists(self.template) | 14 assert os.path.exists(self.template) |
15 | |
16 def print_license(self): | |
17 f = file(self.template) | |
18 print f.read() | |
19 f.close() | |
15 | 20 |
16 def __call__(self, directory, **kw): | 21 def __call__(self, directory, **kw): |
17 variables = self.obtain_variables(**kw) | 22 variables = self.obtain_variables(**kw) |
18 self.interpolate(directory, variables) | 23 self.interpolate(directory, variables) |
19 | 24 |
27 | 32 |
28 def pre(self, variables): | 33 def pre(self, variables): |
29 """do anything that needs to be done before interpolation""" | 34 """do anything that needs to be done before interpolation""" |
30 | 35 |
31 def interpolate(self, directory, variables): | 36 def interpolate(self, directory, variables): |
32 for file in self.files(directory): | 37 for _file in self.files(directory): |
33 pass | 38 |
39 # get the file lines | |
40 f = file(_file) | |
41 lines = [ i.rstrip() for i in f.readlines() ] | |
42 f.close() | |
43 f = file(_file, 'w') | |
44 | |
45 # print shebang if it exists | |
46 if lines[0].startswith('#!'): | |
47 shebang = lines.pop(0) | |
48 print >> f, shebang | |
49 print >> f | |
50 | |
51 # print the license | |
52 g = file(self.template) | |
53 for line in g.readlines(): | |
54 print >> f, '# %s' % line.rstrip() | |
55 g.close() | |
56 | |
57 # print the rest of the file | |
58 for line in lines: | |
59 print >> f, line.rstrip() | |
60 f.close() | |
34 | 61 |
35 def isempty(self, path): | 62 def isempty(self, path): |
36 """ | 63 """ |
37 determines if a python file is empty; that is, contains only comments | 64 determines if a python file is empty; that is, contains only comments |
38 """ | 65 """ |
54 | 81 |
55 | 82 |
56 class MPL(License): | 83 class MPL(License): |
57 """Mozilla Public License""" | 84 """Mozilla Public License""" |
58 template = 'MPL' # could be implicit here | 85 template = 'MPL' # could be implicit here |
59 variables = [ 'author' ] | 86 variables = [ 'author', 'email' ] |
60 | 87 |
61 def pre(self, variables): | 88 def pre(self, variables): |
62 variables['year'] = datetime.now().year | 89 variables['year'] = datetime.now().year |