Merge lp:~rockstar/laika/more-cleanup into lp:laika

Proposed by Paul Hummer
Status: Merged
Approved by: Alex Chiang
Approved revision: 21
Merged at revision: 5
Proposed branch: lp:~rockstar/laika/more-cleanup
Merge into: lp:laika
Prerequisite: lp:~rockstar/laika/foolin
Diff against target: 153 lines (+33/-56)
1 file modified
laika.py (+33/-56)
To merge this branch: bzr merge lp:~rockstar/laika/more-cleanup
Reviewer Review Type Date Requested Status
Alex Chiang Approve
Review via email: mp+30178@code.launchpad.net

Description of the change

Here's what I did in this branch:

- Moved the global my_bugs var to be a member attr.
- Converted getopt usage to OptionParser, because it's a nicer API, and does the stuff from usage() automatically (try laika.py --help now). This meant I could remove a lot of code, and it'll be much easier to add more args.
- I noticed a bug where user wasn't anything but lp.me, so now we actually specify what user you want.
- There was a now var that was driving me nuts, because it really shouldn't be changed. In python, we don't really have true constants, but we denote variables that shouldn't be changed with all caps. Lame, yes, but I made it obvious.
- Main no longer cared about sys.args, so I killed that.
- cachedir didn't respect $HOME, so if was set to something other that /home/rockstar/, it was broken. I find that with os.path.expanduser, which knows how to expand ~ to $HOME.

The branch itself is bigger than I thought. Sorry about that.

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

No worries about large changes. I can handle those just fine, as long as the individual commits are sane.

The end result is good, but I'd like to see a little more discipline in the individual commits.

Two examples:

Commit 18 should have been folded into 16 in your development branch, so that I only see the a final, good commit. There's no need to clutter up the development history with bogus commits and then fixup commits. The Linux kernel will never knowingly merge a bad commit and then a fixup commit. [of course, bugs happen, but the goal is certainly clean commit history.] The reason is that bisection is an important tool, and we want to minimize the pain of landing on a bad commit during a bisect run. Of course, we don't have the same problem with laika, but I think it's still worth it to keep this discipline.

The last few lines of commit 14 logically seem like they belong with commit 13. When I was reading 13, I thought to myself, "hm, he added another call to Launchpad.login_with(), but didn't remove the old one... why not?" I then inspected the final diff and saw that we indeed only ended up with a single call to Launchpad.login_with(), but had to re-review the other commits until I found that 14 removed the double call.

Ok, in my opinion, these are nitpicky comments, but they address a real, fundamental philosophy about development.

Thanks for the patches, the refactoring is really nice.

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-07-16 16:23:29 +0000
+++ laika.py 2010-07-17 15:39:40 +0000
@@ -12,20 +12,14 @@
12# GNU General Public License version 2.12# GNU General Public License version 2.
1313
14import datetime14import datetime
15import getopt15from optparse import OptionParser
16import os16import os
17import re17import re
18import sys18import sys
1919
20from launchpadlib.launchpad import Launchpad20from launchpadlib.launchpad import Launchpad
2121
2222UTCNOW = datetime.datetime.utcnow()
23# Number of days prior to search for Launchpad activity
24window = 8
25user = os.environ.get("USER")
26
27now = datetime.datetime.utcnow()
28my_bugs = {}
2923
3024
31class Report(object):25class Report(object):
@@ -40,8 +34,14 @@
40 status change.34 status change.
41 '''35 '''
4236
43 def __init__(self, user):37 bugs = {}
44 self.user = user38
39 def __init__(self, user, window):
40 cachedir = "/home/" + user + "/.launchpadlib/cache/"
41 self.launchpad = Launchpad.login_with('laika', 'production', cachedir)
42
43 self.user = self.launchpad.people[user]
44 self.window = window
4545
46 def print_header(self, header):46 def print_header(self, header):
47 print "==", header, "=="47 print "==", header, "=="
@@ -52,16 +52,16 @@
52 Time zone aware means broken.52 Time zone aware means broken.
53 http://www.enricozini.org/2009/debian/using-python-datetime/53 http://www.enricozini.org/2009/debian/using-python-datetime/
54 '''54 '''
55 win = datetime.timedelta(window)55 win = datetime.timedelta(self.window)
56 date = date.replace(tzinfo=None)56 date = date.replace(tzinfo=None)
57 delta = now - date57 delta = UTCNOW - date
58 return delta <= win58 return delta <= win
5959
60 def print_bugid(self, task):60 def print_bugid(self, task):
61 '''Using this interface adds the bug to global bug list.'''61 '''Using this interface adds the bug to global bug list.'''
62 ago = ""62 ago = ""
63 my_bugs[task.bug.id] = 163 self.bugs[task.bug.id] = 1
64 delta = now - task.bug.date_last_updated.replace(tzinfo=None)64 delta = UTCNOW - task.bug.date_last_updated.replace(tzinfo=None)
65 if delta.days > 0:65 if delta.days > 0:
66 ago = "%d day%s" % (delta.days, "s" if delta.days > 1 else "")66 ago = "%d day%s" % (delta.days, "s" if delta.days > 1 else "")
6767
@@ -87,7 +87,7 @@
87 self.print_header("Assigned Bugs")87 self.print_header("Assigned Bugs")
8888
89 for t in tasks:89 for t in tasks:
90 if my_bugs.has_key(t.bug.id):90 if self.bugs.has_key(t.bug.id):
91 continue91 continue
92 updates = []92 updates = []
93 for s in statuses:93 for s in statuses:
@@ -110,7 +110,7 @@
110 tasks = self.user.searchTasks(bug_commenter=self.user)110 tasks = self.user.searchTasks(bug_commenter=self.user)
111 self.print_header("Commented Bugs")111 self.print_header("Commented Bugs")
112 for t in tasks:112 for t in tasks:
113 if my_bugs.has_key(t.bug.id):113 if self.bugs.has_key(t.bug.id):
114 continue114 continue
115 for m in t.bug.messages:115 for m in t.bug.messages:
116 if m.owner_link != self.user.self_link:116 if m.owner_link != self.user.self_link:
@@ -125,7 +125,7 @@
125 tasks = self.user.searchTasks(bug_reporter=self.user)125 tasks = self.user.searchTasks(bug_reporter=self.user)
126 self.print_header("Reported Bugs")126 self.print_header("Reported Bugs")
127 for t in tasks:127 for t in tasks:
128 if my_bugs.has_key(t.bug.id):128 if self.bugs.has_key(t.bug.id):
129 continue129 continue
130 if self.in_window(t.bug.date_created):130 if self.in_window(t.bug.date_created):
131 self.print_bugid(t)131 self.print_bugid(t)
@@ -137,45 +137,22 @@
137 self.print_reported()137 self.print_reported()
138138
139139
140def usage():140def main():
141 print "Usage:"141
142 print "\tlaika [-u <login>] [-w <window>] [-h]"142 parser = OptionParser()
143 print143 parser.add_option('-u', '--user', dest='user',
144 print "\t-u <login>"144 default=os.getenv('USER'),
145 print "\t\tSpecify your Launchpad user id."145 help='Specify the Launchpad user id. '
146 print "\t\tIf not specified, defaults to: %s." % (user)146 'Defaults to authenticated token owner.')
147 print147 parser.add_option('-w', '--window', dest='window', type='int',
148 print "\t-w <num>"148 default=8,
149 print "\t\tLook for activity within the past <num> days."149 help='Number af days of past activity to look for. '
150 print "\t\tIf not specified, defaults to %d." % (window)150 'Defaults to 8 days')
151 print151
152 print "\t-h"152 options, arguments = parser.parse_args()
153 print "\t\tDisplay this message."153
154154 report = Report(options.user, options.window)
155def main(argv):
156
157 try:
158 opts, args = getopt.getopt(argv, "hu:w:")
159 except getopt.GetoptError:
160 usage()
161 sys.exit(2)
162
163 for opt, arg in opts:
164 if opt == '-h':
165 usage()
166 sys.exit()
167 elif opt == '-u':
168 global user
169 user = arg
170 elif opt == '-w':
171 global window
172 window = int(arg)
173
174 cachedir = "/home/" + user + "/.launchpadlib/cache/"
175 lp = Launchpad.login_with('laika', 'production', cachedir)
176
177 report = Report(lp.me)
178 report.render()155 report.render()
179156
180if __name__ == "__main__":157if __name__ == "__main__":
181 main(sys.argv[1:])158 main()

Subscribers

People subscribed via source and target branches

to all changes: