mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-01 10:05:50 +00:00
Open URLs automatically during OAuth
This commit is contained in:
parent
2f3b2cb4f1
commit
53bf33dd56
2 changed files with 31 additions and 1 deletions
|
|
@ -98,8 +98,13 @@ class Session(object):
|
|||
self._session.authorization_url(self.endpoints['oauth'])
|
||||
|
||||
click.echo('Opening {} ...'.format(authorization_url))
|
||||
webbrowser.open(authorization_url)
|
||||
try:
|
||||
utils.open_graphical_browser(authorization_url)
|
||||
except Exception as e:
|
||||
logger.warning(str(e))
|
||||
|
||||
click.echo('Follow the instructions on the page.')
|
||||
webbrowser.open(authorization_url)
|
||||
raise exceptions.UserError('Aborted!')
|
||||
|
||||
def _discover_endpoints(self, subpath):
|
||||
|
|
|
|||
|
|
@ -193,3 +193,28 @@ def synchronized(lock=None):
|
|||
return f(*args, **kwargs)
|
||||
return wrapper
|
||||
return inner
|
||||
|
||||
|
||||
def open_graphical_browser(url, new=0, autoraise=True):
|
||||
'''Open a graphical web browser.
|
||||
|
||||
This is basically like `webbrowser.open`, but without trying to launch CLI
|
||||
browsers at all. We're excluding those since it's undesirable to launch
|
||||
those when you're using vdirsyncer on a server. Rather copypaste the URL
|
||||
into the local browser, or use the URL-yanking features of your terminal
|
||||
emulator.
|
||||
'''
|
||||
import webbrowser
|
||||
cli_names = set(['www-browser', 'links', 'links2', 'elinks', 'lynx',
|
||||
'w3m'])
|
||||
|
||||
for name in webbrowser._tryorder:
|
||||
browser = webbrowser.get(name)
|
||||
if browser in cli_names:
|
||||
continue
|
||||
|
||||
if browser.open(url, new, autoraise):
|
||||
return
|
||||
|
||||
raise RuntimeError('No graphical browser found. Please open the URL '
|
||||
'manually.')
|
||||
|
|
|
|||
Loading…
Reference in a new issue