提交 616466f4 编写于 作者: N nicolargo

Merge branch 'issue946' into develop

......@@ -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()
......@@ -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')
......
......@@ -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):
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册