Launchpad digest script
authorBill Erickson <berick@esilibrary.com>
Fri, 1 Jun 2012 17:25:39 +0000 (13:25 -0400)
committerBill Erickson <berick@esilibrary.com>
Fri, 1 Jun 2012 17:25:39 +0000 (13:25 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
launchpad/lp_digest.py [new file with mode: 0755]

diff --git a/launchpad/lp_digest.py b/launchpad/lp_digest.py
new file mode 100755 (executable)
index 0000000..b8bfc03
--- /dev/null
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+from launchpadlib.launchpad import Launchpad
+from datetime import datetime, timedelta
+
+# XXX change to suit
+cachedir = '/home/berick/.lpcache'
+
+# report on last 7 days
+end_date = datetime.utcnow()
+start_date = end_date - timedelta(days=7)
+
+launchpad = Launchpad.login_anonymously('testing', service_root="production")
+project = launchpad.projects["evergreen"]
+
+tasks = project.searchTasks(
+    modified_since = start_date.strftime('%F'),
+    order_by = ['milestone', 'title']
+)
+
+new_bugs = []
+committed_bugs = []
+
+for task in tasks:
+    bug = task.bug # avoid re-fetch
+
+    if task.date_fix_committed:
+        if task.date_fix_committed.replace(tzinfo=None) > start_date:
+            committed_bugs.append({'task' : task, 'bug' : bug})
+
+    if bug.date_created.replace(tzinfo=None) > start_date:
+        new_bugs.append({'task' : task, 'bug' : bug})
+
+last_milestone = None
+def print_task(task_chunk):
+    global last_milestone
+    task = task_chunk['task']
+    bug = task_chunk['bug']
+
+    milestone = '<unset>'
+    if task.milestone:
+        milestone = str(task.milestone).split('/')[-1:][0]
+
+    if last_milestone is None or last_milestone != milestone:
+        last_milestone = milestone
+        print 'Milestone: %s' % milestone
+        print '---------\n'
+
+    owner = bug.owner_link.split('~')[-1:][0]
+
+    print '%s' % task.title.replace(' in Evergreen', '')
+    print '\timportance: %s; status: %s; comments: %d\n' % (
+        task.importance, task.status, bug.message_count - 1)
+
+# ----------------------------------------------------------------
+# Print
+# ----------------------------------------------------------------
+
+print "Launchpad Evergreen Digest From %s to %s" % (start_date.strftime('%F'), end_date.strftime('%F'))
+print "Tasks Committed: %d" % len(committed_bugs)
+print "New Bugs: %d" % len(new_bugs)
+print ''
+
+print '------------------------------------------'
+print 'Committed Tasks:'
+print '------------------------------------------'
+print ''
+for task_chunk in committed_bugs: print_task(task_chunk)
+
+last_milestone = None
+
+print '------------------------------------------'
+print 'New Bugs:'
+print '------------------------------------------'
+print ''
+for task_chunk in new_bugs: print_task(task_chunk)
+
+
+