Merge lp:~dktrkranz/launchpadlib/bug-643699 into lp:launchpadlib

Proposed by Luca Falavigna
Status: Merged
Merged at revision: 138
Proposed branch: lp:~dktrkranz/launchpadlib/bug-643699
Merge into: lp:launchpadlib
Diff against target: 42 lines (+14/-2)
1 file modified
src/launchpadlib/credentials.py (+14/-2)
To merge this branch: bzr merge lp:~dktrkranz/launchpadlib/bug-643699
Reviewer Review Type Date Requested Status
Martin Pool (community) Needs Fixing
Review via email: mp+78650@code.launchpad.net

Description of the change

Fix for LP: #643699

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

Thanks for submitting this branch Luca. I have a couple of comments:

We really don't need a second string (TIMEOUT_MESSAGE). The two
strings should be combined into one. The string should end in something
like this:

    "Press any key to view the authentication page in a web browser."

There's no reason to have a timeout. If the intent is to avoid
censusing the user by suddenly showing them a web page, then we have no
guarantee that they'll read the message before the timeout ends. They
might be otherwise distracted when the message is shown, the message may
be generated at the end of a long shell pipeline or script that the user
has switched away from, the user may be a slow reader, etc.

Also, the code as-written won't actually proceed if they press any key,
only enter. Either the code should be changed or the prompt should be
re-worded to ask the user to press enter.

Thanks again for the branch. This bug certainly needs attention.

Revision history for this message
Martin Pool (mbp) wrote :

This code runs regardless of whether the user has a graphical or text web browser. If we pause indefinitely, and they are in the typical graphical environment, and the stdout of the process using launchpadlib is not visible to the user, it will apparently just hang, which will be bad.

As I said in <https://bugs.launchpad.net/launchpadlib/+bug/643699/comments/6> I'd strongly prefer guarding this by checking $DISPLAY (on X11) even though that's not 100% correlated with using a graphical browser.

You're right that readline will block until enter is pressed. In fact unless the code has already put stdin in uncooked mode (which it might have, but I don't see it) even the select will block until you press enter.

I do think the cleanest way to fix this (though perhaps less accessible to dktrkranz) is to just show an actually useful message in the web page and we should at least file a bug against <https://launchpad.net/canonical-identity-provider> or Launchpad or whatever is showing that page.

review: Needs Fixing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/launchpadlib/credentials.py'
2--- src/launchpadlib/credentials.py 2011-01-10 14:34:03 +0000
3+++ src/launchpadlib/credentials.py 2011-10-07 18:45:23 +0000
4@@ -31,7 +31,9 @@
5 from cStringIO import StringIO
6 import httplib2
7 import os
8+from select import select
9 import stat
10+from sys import stdin
11 import time
12 from urllib import urlencode
13 from urlparse import urljoin
14@@ -500,7 +502,10 @@
15 themselves.
16 """
17
18- WAITING_FOR_USER = "The authorization page:\n (%s)\nshould be opening in your browser. Use your browser to authorize\nthis program to access Launchpad on your behalf. \n\nWaiting to hear from Launchpad about your decision..."
19+ WAITING_FOR_USER = "The authorization page:\n (%s)\nshould be opening in your browser. Use your browser to authorize\nthis program to access Launchpad on your behalf."
20+ TIMEOUT_MESSAGE = "Press any key to continue or wait (%d) seconds..."
21+ TIMEOUT = 5
22+ WAITING_FOR_LAUNCHPAD = "Waiting to hear from Launchpad about your decision..."
23
24 def __init__(self, service_root, application_name, consumer_name=None,
25 credential_save_failed=None, allow_access_levels=None):
26@@ -536,8 +541,15 @@
27 """Have the end-user authorize the token in their browser."""
28
29 authorization_url = self.authorization_url(request_token)
30+ self.output(self.WAITING_FOR_USER % authorization_url)
31+ self.output(self.TIMEOUT_MESSAGE % self.TIMEOUT)
32+ # Wait a little time before attempting to launch browser,
33+ # give users the chance to press a key to skip it anyway.
34+ rlist, _, _ = select([stdin], [], [], self.TIMEOUT)
35+ if rlist:
36+ stdin.readline()
37+ self.output(self.WAITING_FOR_LAUNCHPAD)
38 webbrowser.open(authorization_url)
39- self.output(self.WAITING_FOR_USER % authorization_url)
40 while credentials.access_token is None:
41 time.sleep(access_token_poll_time)
42 try:

Subscribers

People subscribed via source and target branches