comparison contrib/check-code.py @ 10720:fbcccf9ec58f

check-code: add a return value to checkfile function The checkfile function returns True if the file is correct, False otherwise.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Wed, 17 Mar 2010 10:51:26 +0100
parents 3be9ae49b628
children c4fb2103e734
comparison
equal deleted inserted replaced
10719:3be9ae49b628 10720:fbcccf9ec58f
164 :f: filepath 164 :f: filepath
165 :logfunc: function used to report error 165 :logfunc: function used to report error
166 logfunc(filename, linenumber, linecontent, errormessage) 166 logfunc(filename, linenumber, linecontent, errormessage)
167 :maxerr: number of error to display before arborting. 167 :maxerr: number of error to display before arborting.
168 Set to None (default) to report all errors 168 Set to None (default) to report all errors
169
170 return True if no error is found, False otherwise.
169 """ 171 """
172 result = True
170 for name, match, filters, pats in checks: 173 for name, match, filters, pats in checks:
171 fc = 0 174 fc = 0
172 if not re.match(match, f): 175 if not re.match(match, f):
173 continue 176 continue
174 pre = post = open(f).read() 177 pre = post = open(f).read()
183 continue 186 continue
184 for p, msg in pats: 187 for p, msg in pats:
185 if re.search(p, l[1]): 188 if re.search(p, l[1]):
186 logfunc(f, n+1, l[0], msg) 189 logfunc(f, n+1, l[0], msg)
187 fc += 1 190 fc += 1
191 result = False
188 if maxerr is not None and fc >= maxerr: 192 if maxerr is not None and fc >= maxerr:
189 print " (too many errors, giving up)" 193 print " (too many errors, giving up)"
190 break 194 break
191 break 195 break
196 return result
192 197
193 198
194 if __name__ == "__main__": 199 if __name__ == "__main__":
195 if len(sys.argv) == 1: 200 if len(sys.argv) == 1:
196 check = glob.glob("*") 201 check = glob.glob("*")