mergerfs/tools/git2debcl

113 lines
3.5 KiB
Plaintext
Raw Normal View History

2020-01-23 00:56:40 +08:00
#!/usr/bin/env python
# Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import sys
import subprocess
2015-08-07 01:11:17 +08:00
import argparse
2020-01-23 00:56:40 +08:00
def call(args):
return subprocess.Popen(args,stdout=subprocess.PIPE).communicate()[0].decode()
2015-08-07 01:11:17 +08:00
def git_tags():
args = ["git", "tag", '-l']
2020-01-23 00:56:40 +08:00
tags = call(args)
2016-02-26 06:52:47 +08:00
tags = [[int(X) for X in tag.split(".")] for tag in tags.split()]
tags.sort()
2015-08-07 01:11:17 +08:00
tags.reverse()
2016-02-26 06:52:47 +08:00
tags = [".".join([str(X) for X in tag]) for tag in tags]
2015-08-07 01:11:17 +08:00
return tags
2015-08-07 01:11:17 +08:00
def git_log(fromtag,totag):
args = ['git','log','--no-merges','--oneline',fromtag+'...'+totag]
2020-01-23 00:56:40 +08:00
return call(args).strip().split('\n')
2015-08-07 01:11:17 +08:00
def git_author_and_time(tag):
args = ['git','log','-1','--format=-- %an <%ae> %cD',tag]
2020-01-23 00:56:40 +08:00
return call(args).strip()
2015-08-07 01:11:17 +08:00
def git_version():
args = ['git','describe','--always','--tags','--dirty']
2020-01-23 00:56:40 +08:00
return call(args).strip()
2015-08-07 01:11:17 +08:00
def guess_distro():
try:
args = ['lsb_release','-i','-s']
2020-01-23 00:56:40 +08:00
return call(args).strip().lower()
except:
return 'unknown'
2015-08-07 01:11:17 +08:00
def guess_codename():
2015-08-07 01:11:17 +08:00
try:
args = ['lsb_release','-c','-s']
2020-01-23 00:56:40 +08:00
return call(args).strip().lower()
2015-08-07 01:11:17 +08:00
except:
return 'unknown'
def main():
parser = argparse.ArgumentParser(description='Generated debian/changelog from git log')
parser.add_argument('--name',type=str,help='Name of package',required=True)
parser.add_argument('--version',type=str,help='Place in git history to include upto',default='::guess::')
parser.add_argument('--distro',type=str,help='Distribution name',default='::guess::')
parser.add_argument('--codename',type=str,help='Distribution codename',default='::guess::')
parser.add_argument('--urgency',type=str,help='Urgency',default='medium')
args = parser.parse_args()
if args.distro == '::guess::':
args.distro = guess_distro()
if args.codename == '::guess::':
args.codename = guess_codename()
versuffix = "~"+args.distro+"-"+args.codename
if args.version == '::guess::':
args.version = git_version()
tags = git_tags()
if args.version in tags:
idx = tags.index(args.version)
tags = tags[idx:]
2020-01-23 00:56:40 +08:00
tags = list(zip(tags,tags))
else:
2020-01-23 00:56:40 +08:00
tags = list(zip(tags,tags))
tags.insert(0,(args.version,'HEAD'))
2020-01-23 00:56:40 +08:00
for i in range(0,len(tags)):
tags[i] = (tags[i][0] + versuffix,tags[i][1])
tag = tags[0]
for prev in tags[1:]:
lines = git_log(tag[1],prev[1])
if lines == ['']:
tag = prev
continue
2020-01-23 05:48:46 +08:00
print('{0} ({1}) {2}; urgency={3}\n'.format(args.name,tag[0],args.codename,args.urgency))
for line in lines:
2020-01-23 00:56:40 +08:00
print(" * " + line)
authorandtime = git_author_and_time(tag[1])
2020-01-23 05:48:46 +08:00
print(' {0}\n'.format(authorandtime))
tag = prev
if __name__ == "__main__":
main()