lintChanges.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/python
  2. import sys
  3. import re
  4. def lintfile(fname):
  5. have_warned = []
  6. def warn(s):
  7. if not have_warned:
  8. have_warned.append(1)
  9. print fname,":"
  10. print "\t",s
  11. m = re.search(r'(\d{3,})', fname)
  12. if m:
  13. bugnum = m.group(1)
  14. else:
  15. bugnum = None
  16. with open(fname) as f:
  17. contents = f.read()
  18. if bugnum and bugnum not in contents:
  19. warn("bug number %s does not appear"%bugnum)
  20. lines = contents.split("\n")
  21. isBug = ("bug" in lines[0] or "fix" in lines[0])
  22. if not re.match(r'^ +o (.*)', contents):
  23. warn("header not in format expected")
  24. contents = " ".join(contents.split())
  25. if isBug and not re.search(r'(\d+)', contents):
  26. warn("bugfix does not mention a number")
  27. elif isBug and not re.search(r'Fixes ([a-z ]*)bug (\d+)', contents):
  28. warn("bugfix does not say 'Fixes bug XXX'")
  29. if re.search(r'[bB]ug (\d+)', contents):
  30. if not re.search(r'[Bb]ugfix on ', contents):
  31. warn("bugfix does not say 'bugfix on X.Y.Z'")
  32. elif not re.search('[fF]ixes ([a-z ]*)bug (\d+); bugfix on ', contents):
  33. warn("bugfix incant is not semicoloned")
  34. if __name__=='__main__':
  35. for fname in sys.argv[1:]:
  36. if fname.endswith("~"):
  37. continue
  38. lintfile(fname)