Skip to content

Commit

Permalink
compitable with tornado 5.0.0+
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongyihui committed Jul 9, 2018
1 parent 5a0d620 commit 0ecf0af
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions avs/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,37 +81,30 @@ def get(self):
self.redirect(p.url)


def login(config, output):
application = tornado.web.Application([(r".*", MainHandler, dict(config=config, output=output))])
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(3000)
tornado.ioloop.IOLoop.instance().start()
tornado.ioloop.IOLoop.instance().close()


@click.command()
@click.option('--config', '-c', help='configuration json file with product_id, client_id and client_secret')
@click.option('--output', '-o', default=avs.config.DEFAULT_CONFIG_FILE, help='output json file with refresh token')
def main(config, output):
def open_webbrowser():
try:
import webbrowser
except ImportError:
print('Go to http://{your device IP}:3000 to start')
login(config, output)
return

import threading
webserver = threading.Thread(target=login, args=(config, output))
webserver.daemon = True
webserver.start()
time.sleep(0.1)
print("A web page should is opened. If not, go to http://127.0.0.1:3000 to start")
webbrowser.open('http://127.0.0.1:3000')

while webserver.is_alive():
try:
time.sleep(1)
except KeyboardInterrupt:
break

@click.command()
@click.option('--config', '-c', help='configuration json file with product_id, client_id and client_secret')
@click.option('--output', '-o', default=avs.config.DEFAULT_CONFIG_FILE, help='output json file with refresh token')
def main(config, output):
import threading
threading.Thread(target=open_webbrowser).start()

application = tornado.web.Application([(r".*", MainHandler, dict(config=config, output=output))])
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(3000)
tornado.ioloop.IOLoop.instance().start()
tornado.ioloop.IOLoop.instance().close()


if __name__ == '__main__':
Expand Down

0 comments on commit 0ecf0af

Please sign in to comment.