aboutsummaryrefslogtreecommitdiffstats
path: root/dist-tools
diff options
context:
space:
mode:
authorMatthias Andree <matthias.andree@gmx.de>2020-02-14 21:13:28 +0100
committerMatthias Andree <matthias.andree@gmx.de>2020-02-14 21:13:28 +0100
commit1429032b56ddc7fb33f32f3f0267410440c7bf05 (patch)
treee322409709284220afcc32a241fd7fbd6792bec0 /dist-tools
parentc81797aa74696519feb7c849b5c1d5f418f00cad (diff)
downloadfetchmail-1429032b56ddc7fb33f32f3f0267410440c7bf05.tar.gz
fetchmail-1429032b56ddc7fb33f32f3f0267410440c7bf05.tar.bz2
fetchmail-1429032b56ddc7fb33f32f3f0267410440c7bf05.zip
dist-tools/getstats.py - make this Python 3...
it used to be more like a shell wrapper previously.
Diffstat (limited to 'dist-tools')
-rwxr-xr-xdist-tools/getstats.py33
1 files changed, 19 insertions, 14 deletions
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' <configure.ac")
-print "fetchmail-" + vers + " (released " + date + ", " + string.strip(ln) + " LoC):"
+ except:
+ print("Cannot extract version from configure.ac!", file=sys.stderr)
+ raise
# end of getstats.py