Skip to content

Commit

Permalink
Merge pull request #36 from zalando-stups/23-stderr-output
Browse files Browse the repository at this point in the history
#23 Fixed stderr output
  • Loading branch information
gargravarr authored Dec 15, 2016
2 parents b95d15b + 1f05e91 commit e2641d7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion zign/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,21 @@ def get_token_implicit_flow(name=None, authorize_url=None, token_url=None, clien
browser_url = urlunsplit((parsed_authorize_url.scheme, parsed_authorize_url.netloc, parsed_authorize_url.path,
param_string, ''))

webbrowser.open(browser_url, new=1, autoraise=True)
# Redirect stdout and stderr. In Linux, a message is outputted to stdout when opening the browser
# (and then a message to stderr because it can't write).
saved_stdout = os.dup(1)
saved_stderr = os.dup(2)
os.close(1)
os.close(2)
os.open(os.devnull, os.O_RDWR)
try:
webbrowser.get().open(browser_url, new=1, autoraise=True)
finally:
os.dup2(saved_stdout, 1)
os.dup2(saved_stderr, 2)

info('Your browser has been opened to visit:\n\n\t{}\n'.format(browser_url))

else:
raise AuthenticationFailed('Failed to launch local server')

Expand Down

0 comments on commit e2641d7

Please sign in to comment.