Merge lp:~brian-murray/merge-o-matic/linkify-uploader into lp:merge-o-matic

Proposed by Brian Murray
Status: Merged
Merged at revision: 244
Proposed branch: lp:~brian-murray/merge-o-matic/linkify-uploader
Merge into: lp:merge-o-matic
Diff against target: 142 lines (+59/-16)
3 files modified
manual-status.py (+16/-8)
merge-status.py (+16/-8)
momlib.py (+27/-0)
To merge this branch: bzr merge lp:~brian-murray/merge-o-matic/linkify-uploader
Reviewer Review Type Date Requested Status
Colin Watson Approve
Review via email: mp+264066@code.launchpad.net

Description of the change

Use urlopen and json parsing to look up the Launchpad account associated with an email address so that we can then link to the uploaders Launchpad page.

To post a comment you must log in.
245. By Brian Murray

also update manual-status.py to linkify the uploader's name / email address.

246. By Brian Murray

fix number of blank lines.

Revision history for this message
Colin Watson (cjwatson) :
review: Needs Fixing
247. By Brian Murray

move get_person_lp_page to momlib.py, address reviewer feedback

Revision history for this message
Colin Watson (cjwatson) :
review: Approve
Revision history for this message
Brian Murray (brian-murray) wrote :
Download full text (6.8 KiB)

On Wed, Jul 08, 2015 at 04:00:31PM -0000, Colin Watson wrote:
> Review: Approve
>
>
>
> Diff comments:
>
> > === modified file 'manual-status.py'
> > --- manual-status.py 2013-12-25 22:01:26 +0000
> > +++ manual-status.py 2015-07-07 21:29:21 +0000
> > @@ -244,23 +244,31 @@
> > for uploaded, priority, package, user, uploader, source, \
> > left_version, right_version in merges:
> > if user is not None:
> > - who = user
> > - who = who.replace("&", "&")
> > - who = who.replace("<", "&lt;")
> > - who = who.replace(">", "&gt;")
> > + (usr_name, usr_mail) = parseaddr(user)
> > + user_lp_page = get_person_lp_page(usr_mail)
> > + user = user.replace("&", "&amp;")
> > + user = user.replace("<", "&lt;")
> > + user = user.replace(">", "&gt;")
> > + if user_lp_page:
> > + who = "<a href='%s'>%s</a>" % (user_lp_page.encode("utf-8"), user)
> > + else:
> > + who = "%s" % user
>
> user is already a string, so no need for the format operator here.

Fixed.

> >
> > if uploader is not None:
> > - (usr_name, usr_mail) = parseaddr(user)
> > (upl_name, upl_mail) = parseaddr(uploader)
> > + upl_lp_page = get_person_lp_page(upl_mail)
> >
> > if len(usr_name) and usr_name != upl_name:
> > u_who = uploader
> > u_who = u_who.replace("&", "&amp;")
> > u_who = u_who.replace("<", "&lt;")
> > u_who = u_who.replace(">", "&gt;")
> > -
> > - who = "%s<br><small><em>Uploader:</em> %s</small>" \
> > - % (who, u_who)
> > + if upl_lp_page:
> > + who = "%s<br><small><em>Uploader:</em> <a href='%s'>%s</a></small>" \
> > + % (who, upl_lp_page.encode("utf-8"), u_who)
> > + else:
> > + who = "%s<br><small><em>Uploader:</em> %s</small>" \
> > + % (who, u_who)
> > else:
> > who = "&nbsp;"
> >
> > === modified file 'merge-status.py'
> > --- merge-status.py 2013-08-02 10:09:52 +0000
> > +++ merge-status.py 2015-07-07 21:29:21 +0000
> > @@ -266,23 +266,31 @@
> > for uploaded, priority, package, user, uploader, source, \
> > base_version, left_version, right_version in merges:
> > if user is not None:
> > - who = user
> > - who = who.replace("&", "&amp;")
> > - who = who.replace("<", "&lt;")
> > - who = who.replace(">", "&gt;")
> > + (usr_name, usr_mail) = parseaddr(user)
> > + user_lp_page = get_person_lp_page(usr_mail)
> > + user = user.replace("&", "&amp;")
> > + user = user.replace("<", "&lt;")
> > + user = user.replace(">", "&gt;")
> > + if user_lp_page:
> > + who = "<a href='%s'>%s</a>" % (user_lp_page.encode("utf-8"), user)
> > + else:
> > + who = "%s"...

Read more...

248. By Brian Murray

address cjwaton's feedback and document get_person_lp_page

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'manual-status.py'
2--- manual-status.py 2013-12-25 22:01:26 +0000
3+++ manual-status.py 2015-07-08 16:40:28 +0000
4@@ -244,23 +244,31 @@
5 for uploaded, priority, package, user, uploader, source, \
6 left_version, right_version in merges:
7 if user is not None:
8- who = user
9- who = who.replace("&", "&amp;")
10- who = who.replace("<", "&lt;")
11- who = who.replace(">", "&gt;")
12+ (usr_name, usr_mail) = parseaddr(user)
13+ user_lp_page = get_person_lp_page(usr_mail)
14+ user = user.replace("&", "&amp;")
15+ user = user.replace("<", "&lt;")
16+ user = user.replace(">", "&gt;")
17+ if user_lp_page:
18+ who = "<a href='%s'>%s</a>" % (user_lp_page.encode("utf-8"), user)
19+ else:
20+ who = user
21
22 if uploader is not None:
23- (usr_name, usr_mail) = parseaddr(user)
24 (upl_name, upl_mail) = parseaddr(uploader)
25+ upl_lp_page = get_person_lp_page(upl_mail)
26
27 if len(usr_name) and usr_name != upl_name:
28 u_who = uploader
29 u_who = u_who.replace("&", "&amp;")
30 u_who = u_who.replace("<", "&lt;")
31 u_who = u_who.replace(">", "&gt;")
32-
33- who = "%s<br><small><em>Uploader:</em> %s</small>" \
34- % (who, u_who)
35+ if upl_lp_page:
36+ who = "%s<br><small><em>Uploader:</em> <a href='%s'>%s</a></small>" \
37+ % (who, upl_lp_page.encode("utf-8"), u_who)
38+ else:
39+ who = "%s<br><small><em>Uploader:</em> %s</small>" \
40+ % (who, u_who)
41 else:
42 who = "&nbsp;"
43
44
45=== modified file 'merge-status.py'
46--- merge-status.py 2013-08-02 10:09:52 +0000
47+++ merge-status.py 2015-07-08 16:40:28 +0000
48@@ -266,23 +266,31 @@
49 for uploaded, priority, package, user, uploader, source, \
50 base_version, left_version, right_version in merges:
51 if user is not None:
52- who = user
53- who = who.replace("&", "&amp;")
54- who = who.replace("<", "&lt;")
55- who = who.replace(">", "&gt;")
56+ (usr_name, usr_mail) = parseaddr(user)
57+ user_lp_page = get_person_lp_page(usr_mail)
58+ user = user.replace("&", "&amp;")
59+ user = user.replace("<", "&lt;")
60+ user = user.replace(">", "&gt;")
61+ if user_lp_page:
62+ who = "<a href='%s'>%s</a>" % (user_lp_page.encode("utf-8"), user)
63+ else:
64+ who = user
65
66 if uploader is not None:
67- (usr_name, usr_mail) = parseaddr(user)
68 (upl_name, upl_mail) = parseaddr(uploader)
69+ upl_lp_page = get_person_lp_page(upl_mail)
70
71 if len(usr_name) and usr_name != upl_name:
72 u_who = uploader
73 u_who = u_who.replace("&", "&amp;")
74 u_who = u_who.replace("<", "&lt;")
75 u_who = u_who.replace(">", "&gt;")
76-
77- who = "%s<br><small><em>Uploader:</em> %s</small>" \
78- % (who, u_who)
79+ if upl_lp_page:
80+ who = "%s<br><small><em>Uploader:</em> <a href='%s'>%s</a></small>" \
81+ % (who, upl_lp_page.encode("utf-8"), u_who)
82+ else:
83+ who = "%s<br><small><em>Uploader:</em> %s</small>" \
84+ % (who, u_who)
85 else:
86 who = "&nbsp;"
87
88
89=== modified file 'momlib.py'
90--- momlib.py 2015-05-05 08:59:52 +0000
91+++ momlib.py 2015-07-08 16:40:28 +0000
92@@ -33,9 +33,13 @@
93 import logging
94 import datetime
95 import stat
96+import json
97
98 from cgi import escape
99 from optparse import OptionParser
100+from urllib import quote
101+from urllib2 import urlopen
102+from contextlib import closing
103
104 from deb.controlfile import ControlFile
105 from deb.version import Version
106@@ -106,6 +110,9 @@
107 # Cache of parsed sources files
108 SOURCES_CACHE = {}
109
110+# mapping of uploader emails to Launchpad pages
111+person_lp_page_mapping = {}
112+
113
114 # --------------------------------------------------------------------------- #
115 # Command-line tool functions
116@@ -169,6 +176,26 @@
117 """Return an md5sum."""
118 return md5(open(filename).read()).hexdigest()
119
120+def get_person_lp_page(person_email):
121+ """Make a best guess at what the person's LP page is."""
122+ if person_email in person_lp_page_mapping:
123+ return person_lp_page_mapping[person_email]
124+ email = quote(person_email)
125+ find_person = "https://api.launchpad.net/devel/people/?ws.op=findPerson&text=%s" % email
126+ try:
127+ with closing(urlopen(find_person)) as response:
128+ content = response.read()
129+ except IOError:
130+ return None
131+ data = json.loads(content)["entries"]
132+ # findPerson does a startswith match so could return multiple entries, if
133+ # that happens return None as credentials are needed to confirm the email.
134+ if len(data) != 1:
135+ person_lp_page_mapping[person_email] = None
136+ else:
137+ person_lp_page_mapping[person_email] = data[0]["web_link"]
138+ return person_lp_page_mapping[person_email]
139+
140
141 # --------------------------------------------------------------------------- #
142 # Location functions

Subscribers

People subscribed via source and target branches

to status/vote changes: