lintChanges.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/python
  2. from __future__ import print_function
  3. from __future__ import with_statement
  4. import sys
  5. import re
  6. import os
  7. KNOWN_GROUPS = set([
  8. "Minor bugfix",
  9. "Minor bugfixes",
  10. "Major bugfix",
  11. "Major bugfixes",
  12. "Minor feature",
  13. "Minor features",
  14. "Major feature",
  15. "Major features",
  16. "New system requirements",
  17. "Testing",
  18. "Documentation",
  19. "Code simplification and refactoring",
  20. "Removed features"])
  21. def lintfile(fname):
  22. have_warned = []
  23. def warn(s):
  24. if not have_warned:
  25. have_warned.append(1)
  26. print("{}:".format(fname))
  27. print("\t{}".format(s))
  28. m = re.search(r'(\d{3,})', os.path.basename(fname))
  29. if m:
  30. bugnum = m.group(1)
  31. else:
  32. bugnum = None
  33. with open(fname) as f:
  34. contents = f.read()
  35. if bugnum and bugnum not in contents:
  36. warn("bug number {} does not appear".format(bugnum))
  37. m = re.match(r'^[ ]{2}o ([^\(:]*)([^:]*):', contents)
  38. if not m:
  39. warn("header not in format expected")
  40. elif m.group(1).strip() not in KNOWN_GROUPS:
  41. warn("Weird header: %r" % m.group(1))
  42. elif (("bugfix" in m.group(1) or "feature" in m.group(1)) and
  43. ("Removed" not in m.group(1)) and
  44. '(' not in m.group(2)):
  45. warn("Missing subcategory on %s" % m.group(1))
  46. if m:
  47. isBug = ("bug" in m.group(1).lower() or "fix" in m.group(1).lower())
  48. else:
  49. isBug = False
  50. contents = " ".join(contents.split())
  51. if re.search(r'\#\d{2,}', contents):
  52. warn("don't use a # before ticket numbers")
  53. if isBug and not re.search(r'(\d+)', contents):
  54. warn("bugfix does not mention a number")
  55. elif isBug and not re.search(r'Fixes ([a-z ]*)bug (\d+)', contents):
  56. warn("bugfix does not say 'Fixes bug XXX'")
  57. if re.search(r'[bB]ug (\d+)', contents):
  58. if not re.search(r'[Bb]ugfix on ', contents):
  59. warn("bugfix does not say 'bugfix on X.Y.Z'")
  60. elif not re.search('[fF]ixes ([a-z ]*)bug (\d+); bugfix on ',
  61. contents):
  62. warn("bugfix incant is not semicoloned")
  63. elif re.search('tor-([0-9]+)', contents):
  64. warn("do not prefix versions with 'tor-'")
  65. if __name__ == '__main__':
  66. for fname in sys.argv[1:]:
  67. if fname.endswith("~"):
  68. continue
  69. lintfile(fname)