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
1=== modified file 'laika.py'
2--- laika.py 2010-07-16 16:23:29 +0000
3+++ laika.py 2010-07-17 15:39:40 +0000
4@@ -12,20 +12,14 @@
5 # GNU General Public License version 2.
6
7 import datetime
8-import getopt
9+from optparse import OptionParser
10 import os
11 import re
12 import sys
13
14 from launchpadlib.launchpad import Launchpad
15
16-
17-# Number of days prior to search for Launchpad activity
18-window = 8
19-user = os.environ.get("USER")
20-
21-now = datetime.datetime.utcnow()
22-my_bugs = {}
23+UTCNOW = datetime.datetime.utcnow()
24
25
26 class Report(object):
27@@ -40,8 +34,14 @@
28 status change.
29 '''
30
31- def __init__(self, user):
32- self.user = user
33+ bugs = {}
34+
35+ def __init__(self, user, window):
36+ cachedir = "/home/" + user + "/.launchpadlib/cache/"
37+ self.launchpad = Launchpad.login_with('laika', 'production', cachedir)
38+
39+ self.user = self.launchpad.people[user]
40+ self.window = window
41
42 def print_header(self, header):
43 print "==", header, "=="
44@@ -52,16 +52,16 @@
45 Time zone aware means broken.
46 http://www.enricozini.org/2009/debian/using-python-datetime/
47 '''
48- win = datetime.timedelta(window)
49+ win = datetime.timedelta(self.window)
50 date = date.replace(tzinfo=None)
51- delta = now - date
52+ delta = UTCNOW - date
53 return delta <= win
54
55 def print_bugid(self, task):
56 '''Using this interface adds the bug to global bug list.'''
57 ago = ""
58- my_bugs[task.bug.id] = 1
59- delta = now - task.bug.date_last_updated.replace(tzinfo=None)
60+ self.bugs[task.bug.id] = 1
61+ delta = UTCNOW - task.bug.date_last_updated.replace(tzinfo=None)
62 if delta.days > 0:
63 ago = "%d day%s" % (delta.days, "s" if delta.days > 1 else "")
64
65@@ -87,7 +87,7 @@
66 self.print_header("Assigned Bugs")
67
68 for t in tasks:
69- if my_bugs.has_key(t.bug.id):
70+ if self.bugs.has_key(t.bug.id):
71 continue
72 updates = []
73 for s in statuses:
74@@ -110,7 +110,7 @@
75 tasks = self.user.searchTasks(bug_commenter=self.user)
76 self.print_header("Commented Bugs")
77 for t in tasks:
78- if my_bugs.has_key(t.bug.id):
79+ if self.bugs.has_key(t.bug.id):
80 continue
81 for m in t.bug.messages:
82 if m.owner_link != self.user.self_link:
83@@ -125,7 +125,7 @@
84 tasks = self.user.searchTasks(bug_reporter=self.user)
85 self.print_header("Reported Bugs")
86 for t in tasks:
87- if my_bugs.has_key(t.bug.id):
88+ if self.bugs.has_key(t.bug.id):
89 continue
90 if self.in_window(t.bug.date_created):
91 self.print_bugid(t)
92@@ -137,45 +137,22 @@
93 self.print_reported()
94
95
96-def usage():
97- print "Usage:"
98- print "\tlaika [-u <login>] [-w <window>] [-h]"
99- print
100- print "\t-u <login>"
101- print "\t\tSpecify your Launchpad user id."
102- print "\t\tIf not specified, defaults to: %s." % (user)
103- print
104- print "\t-w <num>"
105- print "\t\tLook for activity within the past <num> days."
106- print "\t\tIf not specified, defaults to %d." % (window)
107- print
108- print "\t-h"
109- print "\t\tDisplay this message."
110-
111-def main(argv):
112-
113- try:
114- opts, args = getopt.getopt(argv, "hu:w:")
115- except getopt.GetoptError:
116- usage()
117- sys.exit(2)
118-
119- for opt, arg in opts:
120- if opt == '-h':
121- usage()
122- sys.exit()
123- elif opt == '-u':
124- global user
125- user = arg
126- elif opt == '-w':
127- global window
128- window = int(arg)
129-
130- cachedir = "/home/" + user + "/.launchpadlib/cache/"
131- lp = Launchpad.login_with('laika', 'production', cachedir)
132-
133- report = Report(lp.me)
134+def main():
135+
136+ parser = OptionParser()
137+ parser.add_option('-u', '--user', dest='user',
138+ default=os.getenv('USER'),
139+ help='Specify the Launchpad user id. '
140+ 'Defaults to authenticated token owner.')
141+ parser.add_option('-w', '--window', dest='window', type='int',
142+ default=8,
143+ help='Number af days of past activity to look for. '
144+ 'Defaults to 8 days')
145+
146+ options, arguments = parser.parse_args()
147+
148+ report = Report(options.user, options.window)
149 report.render()
150
151 if __name__ == "__main__":
152- main(sys.argv[1:])
153+ main()

Subscribers

People subscribed via source and target branches

to all changes: