sortChanges.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/python
  2. # Copyright (c) 2014-2015, The Tor Project, Inc.
  3. # See LICENSE for licensing information
  4. """This script sorts a bunch of changes files listed on its command
  5. line into roughly the order in which they should appear in the
  6. changelog.
  7. TODO: collation support.
  8. """
  9. import re
  10. import sys
  11. def fetch(fn):
  12. with open(fn) as f:
  13. s = f.read()
  14. s = "%s\n" % s.rstrip()
  15. return s
  16. def score(s,fname=None):
  17. m = re.match(r'^ +o (.*)', s)
  18. if not m:
  19. print >>sys.stderr, "Can't score %r from %s"%(s,fname)
  20. lw = m.group(1).lower()
  21. if lw.startswith("major feature"):
  22. score = 0
  23. elif lw.startswith("major bug"):
  24. score = 1
  25. elif lw.startswith("major"):
  26. score = 2
  27. elif lw.startswith("minor feature"):
  28. score = 10
  29. elif lw.startswith("minor bug"):
  30. score = 11
  31. elif lw.startswith("minor"):
  32. score = 12
  33. else:
  34. score = 100
  35. return (score, lw, s)
  36. changes = [ score(fetch(fn),fn) for fn in sys.argv[1:] if not fn.endswith('~') ]
  37. changes.sort()
  38. for _, _, s in changes:
  39. print s