aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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