From 1429032b56ddc7fb33f32f3f0267410440c7bf05 Mon Sep 17 00:00:00 2001 From: Matthias Andree Date: Fri, 14 Feb 2020 21:13:28 +0100 Subject: dist-tools/getstats.py - make this Python 3... it used to be more like a shell wrapper previously. --- dist-tools/getstats.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'dist-tools') diff --git a/dist-tools/getstats.py b/dist-tools/getstats.py index f48c153a..4586e361 100755 --- a/dist-tools/getstats.py +++ b/dist-tools/getstats.py @@ -1,23 +1,28 @@ #!/usr/bin/env python # # Collect statistics on current release. +# This needs a halfway recent Python 3. -import commands, os, string, ftplib +import sys +import subprocess +import tempfile +import re +from datetime import date # Get version and date -date = commands.getoutput("LC_TIME=C date +'%Y-%m-%d'") -pid = os.getpid() -os.mkdir("/tmp/getstats.%d" % pid) +with tempfile.TemporaryDirectory() as tmpdirname: + subprocess.check_call("git archive --format=tar HEAD | ( cd {} && tar -xf -)".format(tmpdirname), shell=True) + LOC = subprocess.getoutput("cat {}/*.[chly] 2>/dev/null | wc -l".format(tmpdirname)).strip() + try: + with open("configure.ac") as f: + AC_INIT = list(filter(lambda x: re.match('AC_INIT', x), + f.readlines()))[0] + VERS = re.search(r'AC_INIT\(\[.+\],\[(.+)\],\[.*\]', AC_INIT).group(1) + DATE = date.today().isoformat() + print("fetchmail-{} (released {}, {} LoC):".format(VERS, DATE, LOC)) -cmd = "git archive --format=tar HEAD | ( cd /tmp/getstats.%d && tar -xf -)" % pid - -if os.system(cmd): - print "git-archive FAILED" - os.exit(1) - -ln = commands.getoutput("cat /tmp/getstats.%d/*.[chly] 2>/dev/null | wc -l" % pid) -os.system("rm -rf /tmp/getstats.%d" % pid) -vers = commands.getoutput("sed -n -e '/AC_INIT/s/AC_INIT(\\[.\\+\\],\\[\\(.*\\)\\],.*)/\\1/p'