Merge lp:~rockstar/laika/foolin into lp:laika

Proposed by Paul Hummer
Status: Merged
Approved by: Alex Chiang
Approved revision: 10
Merged at revision: 4
Proposed branch: lp:~rockstar/laika/foolin
Merge into: lp:laika
Diff against target: 315 lines (+152/-137)
1 file modified
laika.py (+152/-137)
To merge this branch: bzr merge lp:~rockstar/laika/foolin
Reviewer Review Type Date Requested Status
Alex Chiang Approve
Review via email: mp+30129@code.launchpad.net

Description of the change

This branch just refactors some of the functionality of laika into a Report class. It's just moving code around really. I haven't changed any of the functionality of laika itself. It's merely contained in a class instance now.

To post a comment you must log in.
Revision history for this message
Alex Chiang (achiang) wrote :

Commit #5 in your branch was a little large for my taste, but I did review it and verify that there was not really any functional change.

Thanks for the patches; they're awesome!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'laika.py'
--- laika.py 2010-05-24 22:24:25 +0000
+++ laika.py 2010-07-16 16:33:22 +0000
@@ -7,14 +7,18 @@
7# http://en.wikipedia.org/wiki/Laika7# http://en.wikipedia.org/wiki/Laika
8#8#
9# Copyright 2010 Alex Chiang <achiang@canonical.com>9# Copyright 2010 Alex Chiang <achiang@canonical.com>
10# 10#
11# This program is distributed under the terms of the11# This program is distributed under the terms of the
12# GNU General Public License version 2.12# GNU General Public License version 2.
1313
14import datetime
15import getopt
14import os16import os
15import re17import re
16import sys18import sys
17import datetime19
20from launchpadlib.launchpad import Launchpad
21
1822
19# Number of days prior to search for Launchpad activity23# Number of days prior to search for Launchpad activity
20window = 824window = 8
@@ -23,144 +27,155 @@
23now = datetime.datetime.utcnow()27now = datetime.datetime.utcnow()
24my_bugs = {}28my_bugs = {}
2529
26def print_header(header):30
27 print "==", header, "=="31class Report(object):
2832 '''An activity report for a specified Launchpad user.
29# Here be side-effects. Using this interface adds the bug to global bug list.33
30def print_bugid(task):34 In order of decreasing importance, search and display activity on
31 ago = ""35 bugs assigned to me, then on bugs that I actually commented upon,
32 my_bugs[task.bug.id] = 136 and finally bugs that I just opened, but did nothing further with.
33 delta = now - task.bug.date_last_updated.replace(tzinfo=None)37
34 if delta.days > 0:38 Avoids duplication of activity. So if the status was changed on
35 ago = "%d day%s" % (delta.days, "s" if delta.days > 1 else "")39 a bug assigned to you and you also commented on it, only report the
3640 status change.
37 hours = delta.seconds / 360041 '''
38 if hours > 0:42
39 ago += ", " if ago else ""43 def __init__(self, user):
40 ago += "%d hour%s" % (hours, "s" if hours > 1 else "")44 self.user = user
41 45
42 minutes = (delta.seconds - (hours * 3600)) / 6046 def print_header(self, header):
43 if minutes > 0:47 print "==", header, "=="
44 ago += ", " if ago else ""48
45 ago += "%d minute%s" % (minutes, "s" if minutes > 1 else "")49 def in_window(self, date):
4650 '''Timezones do not exist, all datetime objects have to be naive.
47 print task.title51
48 print "https://launchpad.net/bugs/" + str(task.bug.id)52 Time zone aware means broken.
49 print "last updated", ago, "ago"53 http://www.enricozini.org/2009/debian/using-python-datetime/
5054 '''
51# heh.55 win = datetime.timedelta(window)
52# Timezones do not exist, all datetime objects have to be naive.56 date = date.replace(tzinfo=None)
53# aware means broken.57 delta = now - date
54# http://www.enricozini.org/2009/debian/using-python-datetime/58 return delta <= win
55def in_window(date):59
56 win = datetime.timedelta(window)60 def print_bugid(self, task):
57 date = date.replace(tzinfo=None)61 '''Using this interface adds the bug to global bug list.'''
58 delta = now - date62 ago = ""
59 return delta <= win63 my_bugs[task.bug.id] = 1
6064 delta = now - task.bug.date_last_updated.replace(tzinfo=None)
61def my_assignments(me):65 if delta.days > 0:
62 statuses = ['closed', 'fix_released', 'fix_committed',66 ago = "%d day%s" % (delta.days, "s" if delta.days > 1 else "")
63 'in_progress', 'triaged', 'confirmed', 'created']67
6468 hours = delta.seconds / 3600
65 tasks = me.searchTasks(assignee=me)69 if hours > 0:
66 print_header("Assigned Bugs")70 ago += ", " if ago else ""
6771 ago += "%d hour%s" % (hours, "s" if hours > 1 else "")
68 for t in tasks:72
69 if my_bugs.has_key(t.bug.id):73 minutes = (delta.seconds - (hours * 3600)) / 60
70 continue74 if minutes > 0:
71 updates = []75 ago += ", " if ago else ""
72 for s in statuses:76 ago += "%d minute%s" % (minutes, "s" if minutes > 1 else "")
73 attr = 'date_' + s77
74 date = getattr(t, attr)78 print task.title
75 if not date:79 print "https://launchpad.net/bugs/" + str(task.bug.id)
76 continue80 print "last updated", ago, "ago"
77 if in_window(date):81
78 updates.append("\t" + s + ": " + re.sub("\s.*$", "", str(date)))82 def print_assignments(self):
7983 statuses = ['closed', 'fix_released', 'fix_committed',
80 if updates:84 'in_progress', 'triaged', 'confirmed', 'created']
81 print_bugid(t)85
82 for u in updates:86 tasks = self.user.searchTasks(assignee=self.user)
83 print u87 self.print_header("Assigned Bugs")
84 print88
85 print89 for t in tasks:
8690 if my_bugs.has_key(t.bug.id):
87def my_comments(me):91 continue
88 tasks = me.searchTasks(bug_commenter=me)92 updates = []
89 print_header("Commented Bugs")93 for s in statuses:
90 for t in tasks:94 attr = 'date_' + s
91 if my_bugs.has_key(t.bug.id):95 date = getattr(t, attr)
92 continue96 if not date:
93 for m in t.bug.messages:97 continue
94 if m.owner_link != me.self_link:98 if self.in_window(date):
95 continue99 updates.append(
96 if in_window(m.date_created):100 "\t" + s + ": " + re.sub("\s.*$", "", str(date)))
97 print_bugid(t)101
98 print102 if updates:
99 break103 self.print_bugid(t)
100 print104 for u in updates:
101105 print u
102def my_reported(me):106 print
103 tasks = me.searchTasks(bug_reporter=me)107 print
104 print_header("Reported Bugs")108
105 for t in tasks:109 def print_comments(self):
106 if my_bugs.has_key(t.bug.id):110 tasks = self.user.searchTasks(bug_commenter=self.user)
107 continue111 self.print_header("Commented Bugs")
108 if in_window(t.bug.date_created):112 for t in tasks:
109 print_bugid(t)113 if my_bugs.has_key(t.bug.id):
110 print114 continue
111115 for m in t.bug.messages:
112# In order of decreasing importance, search and display activity on116 if m.owner_link != self.user.self_link:
113# bugs assigned to me, then on bugs that I actually commented upon,117 continue
114# and finally bugs that I just opened, but did nothing further with.118 if self.in_window(m.date_created):
115#119 self.print_bugid(t)
116# Avoids duplication of activity. So if the status was changed on120 print
117# a bug assigned to you and you also commented on it, only report the121 break
118# status change.122 print
119def launch(lp):123
120 me = lp.me124 def print_reported(self):
121 my_assignments(me)125 tasks = self.user.searchTasks(bug_reporter=self.user)
122 my_comments(me)126 self.print_header("Reported Bugs")
123 my_reported(me)127 for t in tasks:
128 if my_bugs.has_key(t.bug.id):
129 continue
130 if self.in_window(t.bug.date_created):
131 self.print_bugid(t)
132 print
133
134 def render(self):
135 self.print_assignments()
136 self.print_comments()
137 self.print_reported()
138
124139
125def usage():140def usage():
126 print "Usage:"141 print "Usage:"
127 print "\tlaika [-u <login>] [-w <window>] [-h]"142 print "\tlaika [-u <login>] [-w <window>] [-h]"
128 print143 print
129 print "\t-u <login>"144 print "\t-u <login>"
130 print "\t\tSpecify your Launchpad user id."145 print "\t\tSpecify your Launchpad user id."
131 print "\t\tIf not specified, defaults to: %s." % (user)146 print "\t\tIf not specified, defaults to: %s." % (user)
132 print147 print
133 print "\t-w <num>"148 print "\t-w <num>"
134 print "\t\tLook for activity within the past <num> days."149 print "\t\tLook for activity within the past <num> days."
135 print "\t\tIf not specified, defaults to %d." % (window)150 print "\t\tIf not specified, defaults to %d." % (window)
136 print151 print
137 print "\t-h"152 print "\t-h"
138 print "\t\tDisplay this message."153 print "\t\tDisplay this message."
139154
140def main(argv):155def main(argv):
141 import getopt156
142 from launchpadlib.launchpad import Launchpad157 try:
143158 opts, args = getopt.getopt(argv, "hu:w:")
144 try:159 except getopt.GetoptError:
145 opts, args = getopt.getopt(argv, "hu:w:")160 usage()
146 except getopt.GetoptError:161 sys.exit(2)
147 usage()162
148 sys.exit(2)163 for opt, arg in opts:
149 164 if opt == '-h':
150 for opt, arg in opts:165 usage()
151 if opt == '-h':166 sys.exit()
152 usage()167 elif opt == '-u':
153 sys.exit()168 global user
154 elif opt == '-u':169 user = arg
155 global user170 elif opt == '-w':
156 user = arg171 global window
157 elif opt == '-w':172 window = int(arg)
158 global window173
159 window = int(arg)174 cachedir = "/home/" + user + "/.launchpadlib/cache/"
160 175 lp = Launchpad.login_with('laika', 'production', cachedir)
161 cachedir = "/home/" + user + "/.launchpadlib/cache/"176
162 lp = Launchpad.login_with('laika', 'production', cachedir)177 report = Report(lp.me)
163 launch(lp)178 report.render()
164179
165if __name__ == "__main__":180if __name__ == "__main__":
166 main(sys.argv[1:])181 main(sys.argv[1:])

Subscribers

People subscribed via source and target branches

to all changes: