diff options
author | nicolargo <nicolas@nicolargo.com> | 2016-10-27 21:37:57 +0200 |
---|---|---|
committer | nicolargo <nicolas@nicolargo.com> | 2016-10-27 21:37:57 +0200 |
commit | 8866321a49a145049afe30d490378749f3b8ef41 (patch) | |
tree | aa53257dfea40c74a9d94a708020c8d9f62450b5 | |
parent | 19fc718fd8e642ce51e270ffcc3fa1b014fb78e1 (diff) |
Deprecate Windows Curse UI: automaticaly open Web Browser for the standalone mode #946
-rw-r--r-- | glances/__init__.py | 16 | ||||
-rw-r--r-- | glances/main.py | 2 | ||||
-rw-r--r-- | glances/outputs/glances_bottle.py | 14 | ||||
-rw-r--r-- | glances/webserver.py | 2 |
4 files changed, 28 insertions, 6 deletions
diff --git a/glances/__init__.py b/glances/__init__.py index efaca56d..2c16d18b 100644 --- a/glances/__init__.py +++ b/glances/__init__.py @@ -43,6 +43,7 @@ except ImportError: # Note: others Glances libs will be imported optionally from glances.logger import logger from glances.main import GlancesMain +from glances.globals import WINDOWS # Check locale try: @@ -118,7 +119,7 @@ def main(): signal.signal(signal.SIGINT, __signal_handler) # Glances can be ran in standalone, client or server mode - if core.is_standalone(): + if core.is_standalone() and not WINDOWS: logger.info("Start standalone mode") # Import the Glances standalone module @@ -131,7 +132,7 @@ def main(): # Start the standalone (CLI) loop standalone.serve_forever() - elif core.is_client(): + elif core.is_client() and not WINDOWS: if core.is_client_browser(): logger.info("Start client mode (browser)") @@ -185,15 +186,22 @@ def main(): # Shutdown the server? server.server_close() - elif core.is_webserver(): + elif core.is_webserver() or (core.is_standalone() and WINDOWS): logger.info("Start web server mode") # Import the Glances web server module from glances.webserver import GlancesWebServer + args = core.get_args() + + # Web server mode replace the standalone mode on Windows OS + # In this case, try to start the web browser mode automaticaly + if core.is_standalone() and WINDOWS: + args.open_web_browser = True + # Init the web server mode webserver = GlancesWebServer(config=core.get_config(), - args=core.get_args()) + args=args) # Start the web server loop webserver.serve_forever() diff --git a/glances/main.py b/glances/main.py index 960b7376..f6253ec0 100644 --- a/glances/main.py +++ b/glances/main.py @@ -215,6 +215,8 @@ Start the client browser (browser mode):\n\ dest='webserver', help='run Glances in web server mode (bottle needed)') parser.add_argument('--cached-time', default=self.cached_time, type=int, dest='cached_time', help='set the server cache time [default: {} sec]'.format(self.cached_time)) + parser.add_argument('--open-web-browser', action='store_true', default=False, + dest='open_web_browser', help='try to open the Web UI in the default Web browser') # Display options parser.add_argument('-q', '--quiet', default=False, action='store_true', dest='quiet', help='do not display the curses interface') diff --git a/glances/outputs/glances_bottle.py b/glances/outputs/glances_bottle.py index 82a68b47..7002b9fc 100644 --- a/glances/outputs/glances_bottle.py +++ b/glances/outputs/glances_bottle.py @@ -24,8 +24,10 @@ import os import sys import tempfile from io import open +import webbrowser from glances.timer import Timer +from glances.globals import WINDOWS from glances.logger import logger try: @@ -117,9 +119,19 @@ class GlancesBottle(object): self.plugins_list = self.stats.getAllPlugins() # Bind the Bottle TCP address/port - bindmsg = 'Glances web server started on http://{}:{}/'.format(self.args.bind_address, self.args.port) + bindurl = 'http://{}:{}/'.format(self.args.bind_address, + self.args.port) + bindmsg = 'Glances web server started on {}'.format(bindurl) logger.info(bindmsg) print(bindmsg) + if self.args.open_web_browser: + # Implementation of the issue #946 + # Try to open the Glances Web UI in the default Web browser if: + # 1) --open-web-browser option is used + # 2) Glances standalone mode is running on Windows OS + webbrowser.open(bindurl, + new=2, + autoraise=1) self._app.run(host=self.args.bind_address, port=self.args.port, quiet=not self.args.debug) def end(self): diff --git a/glances/webserver.py b/glances/webserver.py index 41bb9840..95e8151f 100644 --- a/glances/webserver.py +++ b/glances/webserver.py @@ -2,7 +2,7 @@ # # This file is part of Glances. # -# Copyright (C) 2015 Nicolargo <nicolas@nicolargo.com> +# Copyright (C) 2016 Nicolargo <nicolas@nicolargo.com> # # Glances is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by |