From 0ecf0afaec654f2a53c484b8bc59a508174ee8a2 Mon Sep 17 00:00:00 2001 From: Yihui Xiong Date: Mon, 9 Jul 2018 19:03:05 +0800 Subject: [PATCH] compitable with tornado 5.0.0+ --- avs/auth.py | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/avs/auth.py b/avs/auth.py index 439dfba..0e20510 100644 --- a/avs/auth.py +++ b/avs/auth.py @@ -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__':