1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
Description: Add a delay before attempting to launch browser
Author: Luca Falavigna <dktrkranz@debian.org>
Bug-Debian: http://bugs.debian.org/584556
Forwarded: https://launchpad.net/launchpadlib/+bug/643699
--- a/src/launchpadlib/credentials.py
+++ b/src/launchpadlib/credentials.py
@@ -31,7 +31,9 @@
from cStringIO import StringIO
import httplib2
import os
+from select import select
import stat
+from sys import stdin
import time
from urllib import urlencode
from urlparse import urljoin
@@ -553,7 +555,10 @@
themselves.
"""
- 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..."
+ 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."
+ TIMEOUT_MESSAGE = "Press any key to continue or wait (%d) seconds..."
+ TIMEOUT = 5
+ WAITING_FOR_LAUNCHPAD = "Waiting to hear from Launchpad about your decision..."
def __init__(self, service_root, application_name, consumer_name=None,
credential_save_failed=None, allow_access_levels=None):
@@ -589,8 +594,15 @@
"""Have the end-user authorize the token in their browser."""
authorization_url = self.authorization_url(request_token)
- webbrowser.open(authorization_url)
self.output(self.WAITING_FOR_USER % authorization_url)
+ self.output(self.TIMEOUT_MESSAGE % self.TIMEOUT)
+ # Wait a little time before attempting to launch browser,
+ # give users the chance to press a key to skip it anyway.
+ rlist, _, _ = select([stdin], [], [], self.TIMEOUT)
+ if rlist:
+ stdin.readline()
+ self.output(self.WAITING_FOR_LAUNCHPAD)
+ webbrowser.open(authorization_url)
while credentials.access_token is None:
time.sleep(access_token_poll_time)
try:
|