lintChanges.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. contents = " ".join(contents.split())
  23. if isBug and not re.search(r'(\d+)', contents):
  24. warn("bugfix does not mention a number")
  25. elif isBug and not re.search(r'Fixes bug (\d+)', contents):
  26. warn("bugfix does not say 'Fixes bug XXX'")
  27. if re.search(r'[bB]ug (\d+)', contents) and not re.search(r'Bugfix on ', contents):
  28. warn("bugfix does not say 'bugfix on X.Y.Z'")
  29. if __name__=='__main__':
  30. for fname in sys.argv[1:]:
  31. if fname.endswith("~"):
  32. continue
  33. lintfile(fname)