You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.4 KiB

  1. #!/usr/bin/python
  2. # The MIT License (MIT)
  3. # Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. # The above copyright notice and this permission notice shall be included in
  11. # all copies or substantial portions of the Software.
  12. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. # THE SOFTWARE.
  19. import sys
  20. import subprocess
  21. import argparse
  22. def git_tags():
  23. args = ["git", "tag", '-l']
  24. tags = subprocess.check_output(args)
  25. tags = tags.split()
  26. tags.reverse()
  27. return tags
  28. def git_log(fromtag,totag):
  29. args = ['git','log','--no-merges','--oneline',fromtag+'...'+totag]
  30. return subprocess.check_output(args).strip().split('\n')
  31. def git_author_and_time(tag):
  32. args = ['git','log','-1','--format=-- %an <%ae> %cD',tag]
  33. return subprocess.check_output(args).strip()
  34. def git_version():
  35. args = ['git','describe','--always','--tags','--dirty']
  36. return subprocess.check_output(args).strip()
  37. def find_distrib_codename(f):
  38. for line in f:
  39. (key,value) = line.partition('=')[::2]
  40. if key == 'DISTRIB_CODENAME':
  41. return value.strip()
  42. def guess_distribution():
  43. try:
  44. with open('/etc/upstream-release/lsb-release') as f:
  45. return find_distrib_codename(f)
  46. except:
  47. try:
  48. with open('/etc/lsb-release') as f:
  49. return find_distrib_codename(f)
  50. except:
  51. return 'unknown'
  52. parser = argparse.ArgumentParser(description='Generated debian/changelog from git log')
  53. parser.add_argument('--name',type=str,help='Name of package',required=True)
  54. parser.add_argument('--version',type=str,help='Place in git history to include upto',default='::guess::')
  55. parser.add_argument('--distro',type=str,help='Distribution name',default='::guess::')
  56. parser.add_argument('--urgency',type=str,help='Urgency',default='medium')
  57. args = parser.parse_args()
  58. if args.distro == '::guess::':
  59. args.distro = guess_distribution()
  60. if args.version == '::guess::':
  61. args.version = git_version()
  62. tags = git_tags()
  63. if args.version in tags:
  64. idx = tags.index(args.version)
  65. tags = tags[idx:]
  66. tags = zip(tags,tags)
  67. else:
  68. tags = zip(tags,tags)
  69. tags.insert(0,(args.version,'HEAD'))
  70. tag = tags[0]
  71. for prev in tags[1:]:
  72. print('%s (%s) %s; urgency=%s\n' % (args.name,tag[0],args.distro,args.urgency))
  73. lines = git_log(tag[1],prev[1])
  74. for line in lines:
  75. print " * " + line
  76. print
  77. authorandtime = git_author_and_time(tag[1])
  78. print(' %s\n' % authorandtime)
  79. tag = prev