Browse Source

Merge pull request #699 from trapexit/git2debcl

make git2debcl work on Python 2 & 3
pull/700/head
trapexit 5 years ago
committed by GitHub
parent
commit
eb57425315
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 55
      tools/git2debcl

55
tools/git2debcl

@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> # Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
@ -18,9 +18,12 @@ import sys
import subprocess import subprocess
import argparse import argparse
def call(args):
return subprocess.Popen(args,stdout=subprocess.PIPE).communicate()[0].decode()
def git_tags(): def git_tags():
args = ["git", "tag", '-l'] args = ["git", "tag", '-l']
tags = subprocess.check_output(args)
tags = call(args)
tags = [[int(X) for X in tag.split(".")] for tag in tags.split()] tags = [[int(X) for X in tag.split(".")] for tag in tags.split()]
tags.sort() tags.sort()
tags.reverse() tags.reverse()
@ -29,20 +32,20 @@ def git_tags():
def git_log(fromtag,totag): def git_log(fromtag,totag):
args = ['git','log','--no-merges','--oneline',fromtag+'...'+totag] args = ['git','log','--no-merges','--oneline',fromtag+'...'+totag]
return subprocess.check_output(args).strip().split('\n')
return call(args).strip().split('\n')
def git_author_and_time(tag): def git_author_and_time(tag):
args = ['git','log','-1','--format=-- %an <%ae> %cD',tag] args = ['git','log','-1','--format=-- %an <%ae> %cD',tag]
return subprocess.check_output(args).strip()
return call(args).strip()
def git_version(): def git_version():
args = ['git','describe','--always','--tags','--dirty'] args = ['git','describe','--always','--tags','--dirty']
return subprocess.check_output(args).strip()
return call(args).strip()
def guess_distro(): def guess_distro():
try: try:
args = ['lsb_release','-i','-s'] args = ['lsb_release','-i','-s']
return subprocess.check_output(args).strip().lower()
return call(args).strip().lower()
except: except:
return 'unknown' return 'unknown'
@ -50,38 +53,12 @@ def guess_distro():
def guess_codename(): def guess_codename():
try: try:
args = ['lsb_release','-c','-s'] args = ['lsb_release','-c','-s']
return subprocess.check_output(args).strip().lower()
return call(args).strip().lower()
except: except:
return 'unknown' return 'unknown'
def patch_subprocess():
if "check_output" not in dir( subprocess ): # duck punch it in!
def check_output(*popenargs, **kwargs):
r"""Run command with arguments and return its output as a byte string.
Backported from Python 2.7 as it's implemented as pure python on stdlib.
>>> check_output(['/usr/bin/python', '--version'])
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
subprocess.check_output = check_output
def main(): def main():
patch_subprocess()
parser = argparse.ArgumentParser(description='Generated debian/changelog from git log') 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('--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('--version',type=str,help='Place in git history to include upto',default='::guess::')
@ -107,12 +84,12 @@ def main():
if args.version in tags: if args.version in tags:
idx = tags.index(args.version) idx = tags.index(args.version)
tags = tags[idx:] tags = tags[idx:]
tags = zip(tags,tags)
tags = list(zip(tags,tags))
else: else:
tags = zip(tags,tags)
tags = list(zip(tags,tags))
tags.insert(0,(args.version,'HEAD')) tags.insert(0,(args.version,'HEAD'))
for i in xrange(0,len(tags)):
for i in range(0,len(tags)):
tags[i] = (tags[i][0] + versuffix,tags[i][1]) tags[i] = (tags[i][0] + versuffix,tags[i][1])
tag = tags[0] tag = tags[0]
@ -122,13 +99,13 @@ def main():
tag = prev tag = prev
continue continue
print('%s (%s) %s; urgency=%s\n' % (args.name,tag[0],args.codename,args.urgency))
print('{} ({}) {}; urgency={}\n'.format(args.name,tag[0],args.codename,args.urgency))
for line in lines: for line in lines:
print " * " + line
print(" * " + line)
authorandtime = git_author_and_time(tag[1]) authorandtime = git_author_and_time(tag[1])
print(' %s\n' % authorandtime)
print(' {}\n'.format(authorandtime))
tag = prev tag = prev

Loading…
Cancel
Save