enhance git2debcl to work with older python releases

This commit is contained in:
Antonio SJ Musumeci 2015-10-13 00:20:47 -04:00
parent 6709791156
commit 5489952aa8

View File

@ -60,42 +60,75 @@ def guess_distribution():
with open('/etc/lsb-release') as f: with open('/etc/lsb-release') as f:
return find_distrib_codename(f) return find_distrib_codename(f)
except: except:
return 'unknown' try:
args = ['lsb_release','-c','-s']
return subprocess.check_output(args).strip()
except:
return 'unknown'
parser = argparse.ArgumentParser(description='Generated debian/changelog from git log') def patch_subprocess():
parser.add_argument('--name',type=str,help='Name of package',required=True) if "check_output" not in dir( subprocess ): # duck punch it in!
parser.add_argument('--version',type=str,help='Place in git history to include upto',default='::guess::') def check_output(*popenargs, **kwargs):
parser.add_argument('--distro',type=str,help='Distribution name',default='::guess::') r"""Run command with arguments and return its output as a byte string.
parser.add_argument('--urgency',type=str,help='Urgency',default='medium')
args = parser.parse_args() Backported from Python 2.7 as it's implemented as pure python on stdlib.
if args.distro == '::guess::': >>> check_output(['/usr/bin/python', '--version'])
args.distro = guess_distribution() Python 2.6.2
"""
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
output, unused_err = process.communicate()
retcode = process.poll()
if retcode:
cmd = kwargs.get("args")
if cmd is None:
cmd = popenargs[0]
error = subprocess.CalledProcessError(retcode, cmd)
error.output = output
raise error
return output
if args.version == '::guess::': subprocess.check_output = check_output
args.version = git_version()
tags = git_tags() def main():
patch_subprocess()
if args.version in tags: parser = argparse.ArgumentParser(description='Generated debian/changelog from git log')
idx = tags.index(args.version) parser.add_argument('--name',type=str,help='Name of package',required=True)
tags = tags[idx:] parser.add_argument('--version',type=str,help='Place in git history to include upto',default='::guess::')
tags = zip(tags,tags) parser.add_argument('--distro',type=str,help='Distribution name',default='::guess::')
else: parser.add_argument('--urgency',type=str,help='Urgency',default='medium')
tags = zip(tags,tags)
tags.insert(0,(args.version,'HEAD'))
tag = tags[0] args = parser.parse_args()
for prev in tags[1:]:
print('%s (%s) %s; urgency=%s\n' % (args.name,tag[0],args.distro,args.urgency))
lines = git_log(tag[1],prev[1]) if args.distro == '::guess::':
for line in lines: args.distro = guess_distribution()
print " * " + line
print
authorandtime = git_author_and_time(tag[1]) if args.version == '::guess::':
print(' %s\n' % authorandtime) args.version = git_version()
tag = prev tags = git_tags()
if args.version in tags:
idx = tags.index(args.version)
tags = tags[idx:]
tags = zip(tags,tags)
else:
tags = zip(tags,tags)
tags.insert(0,(args.version,'HEAD'))
tag = tags[0]
for prev in tags[1:]:
print('%s (%s) %s; urgency=%s\n' % (args.name,tag[0],args.distro,args.urgency))
lines = git_log(tag[1],prev[1])
for line in lines:
print " * " + line
authorandtime = git_author_and_time(tag[1])
print(' %s\n' % authorandtime)
tag = prev
if __name__ == "__main__":
main()