scripts: add script to count pushes to repositories
authorGregory Szorc <gps@mozilla.com>
Mon, 18 May 2015 09:39:45 -0700
changeset 360799 df623616c0857ee1556bcb86b7495a5f5e928715
parent 360798 58298b34d99184cccdc916f0eeade9545e00c0ce
child 360800 934bfd06a2b849c71af9ffcf2ad27ddc49e3cf02
push id16998
push userrwood@mozilla.com
push dateMon, 02 May 2016 19:42:03 +0000
scripts: add script to count pushes to repositories Laura wanted this data. The script is hacky but gets the job done.
scripts/count-repo-pushes
new file mode 100755
--- /dev/null
+++ b/scripts/count-repo-pushes
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# This script scans repository paths (specified via stdin) and prints
+# stats on pushes to those repos by consulting the pushlog database.
+
+import datetime
+import os
+import sqlite3
+import sys
+
+repos_by_day = {}
+totals_by_day = {}
+
+
+for path in sys.stdin:
+    path = path.strip()
+    dbpath = os.path.join(path, '.hg', 'pushlog2.db')
+    if not os.path.exists(dbpath):
+        continue
+
+    db = sqlite3.connect(dbpath)
+    try:
+        res = db.execute('SELECT date from pushlog ORDER BY date ASC')
+        for t in res:
+            date = datetime.date.fromtimestamp(t[0])
+
+            repos_by_day.setdefault(path, {}).setdefault(date, 0)
+            repos_by_day[path][date] += 1
+            totals_by_day.setdefault(date, 0)
+            totals_by_day[date] += 1
+    finally:
+        db.close()
+
+for date, count in sorted(totals_by_day.items()):
+    print('%s\t%d' % (date, count))