comparison licenser/licenses.py @ 19:73e815e13914

fix a few things
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 24 Nov 2011 14:55:29 -0800
parents c04a53145f19
children 272e10163900
comparison
equal deleted inserted replaced
18:c04a53145f19 19:73e815e13914
47 extensions = set() 47 extensions = set()
48 48
49 @classmethod 49 @classmethod
50 def match(cls, filename): 50 def match(cls, filename):
51 basename, extension = os.path.splitext(os.path.basename(filename)) 51 basename, extension = os.path.splitext(os.path.basename(filename))
52 if extension in extensions: 52 if extension in cls.extensions:
53 return cls(filename) 53 return cls(filename)
54 54
55 def __init__(self, filename): 55 def __init__(self, filename):
56 self.filename = filename 56 self.filename = filename
57 57
71 def __call__(self, license): 71 def __call__(self, license):
72 72
73 # open the file for writing 73 # open the file for writing
74 raise NotImplementedError 74 raise NotImplementedError
75 75
76 class HashCommentsFile(object): 76 class HashCommentsFile(CommentedFile):
77 77
78 extensions = set(['py', 'sh']) 78 extensions = set(['py', 'sh'])
79 79
80 def __call__(self, license): 80 def __call__(self, license):
81 """interpolate the file""" 81 """interpolate the file"""
135 def print_license(self): 135 def print_license(self):
136 print self.license() 136 print self.license()
137 137
138 def token(self): 138 def token(self):
139 """a token indicative of the license, by default the first line""" 139 """a token indicative of the license, by default the first line"""
140 return self.license.splitlines()[0].strip() 140 return self.license().splitlines()[0].strip()
141 141
142 def has_license(self, filename): 142 def has_license(self, filename):
143 """does the file already have a license?""" 143 """does the file already have a license?"""
144 token = self.token() 144 token = self.token()
145 for line in file(filename).readlines(): 145 for line in file(filename).readlines():
170 return match 170 return match
171 171
172 def interpolate_file(self, _file, variables): 172 def interpolate_file(self, _file, variables):
173 173
174 # if the file is licensed, no need to proceed 174 # if the file is licensed, no need to proceed
175 if self.has_license(filename): 175 if self.has_license(_file):
176 return # you're done 176 return # you're done
177 177
178 # get the filetype 178 # get the filetype
179 filetype = self.filetype(_file) 179 filetype = self.filetype(_file)
180 if not filetype: 180 if not filetype:
191 def interpolate(self, directory, variables): 191 def interpolate(self, directory, variables):
192 for _file in self.files(directory): 192 for _file in self.files(directory):
193 self.interpolate_file(_file, variables) 193 self.interpolate_file(_file, variables)
194 194
195 def files(self, directory): 195 def files(self, directory):
196 files = set() 196 files = []
197 for dirpath, _, filenames in os.walk(directory): 197 for dirpath, _, filenames in os.walk(directory):
198 for f in filenames: 198 for f in filenames:
199 path = os.path.join(dirpath, f) 199 files.append(os.path.join(dirpath, f))
200 return files 200 return files
201 201
202 202
203 class MPL(License): 203 class MPL(License):
204 """Mozilla Public License""" 204 """Mozilla Public License"""