__init__.py 2.7 KB
Newer Older
N
Nicolas Hennion 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Glances - An eye on your system
#
# Copyright (C) 2014 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Glances is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

N
Nicolas Hennion 已提交
21 22
# Import Glances libs
# Note: others Glances libs will be imported optionnaly
23
from .core.glances_main import GlancesMain
N
Nicolas Hennion 已提交
24 25

def main(argv=None):
26 27
    # Create the Glances main instance
    core = GlancesMain()
N
Nicolas Hennion 已提交
28 29 30

    # Glances can be ran in standalone, client or server mode
    if (core.is_standalone()):
31 32 33 34
        # Import the Glances standalone module
        from .core.glances_standalone import GlancesStandalone

        # Init the standalone mode
N
Nicolas Hennion 已提交
35 36
        standalone = GlancesStandalone(config=core.get_config(),
                                       args=core.get_args(),
37 38 39 40 41 42
                                       refresh_time=core.refresh_time,
                                       use_bold=core.use_bold)

        # Start the standalone (CLI) loop
        standalone.serve_forever()

N
Nicolas Hennion 已提交
43 44
    elif (core.is_client()):
        # !!!
N
Nicolas Hennion 已提交
45 46
        print(_("Glances client connected to %s:%s") % (core.server_ip, core.server_port))
        print("TODO...")
N
Nicolas Hennion 已提交
47 48 49 50 51 52 53
    elif (core.is_server()):
        # Import the Glances server module
        from .core.glances_server import GlancesServer

        # Init the server
        server = GlancesServer(bind_address=core.bind_ip, 
                               bind_port=int(core.server_port), 
54
                               cached_time=core.cached_time,
N
Nicolas Hennion 已提交
55
                               config=core.get_config())
56 57
        # print(_("Glances server is running on %s:%s with config file %s") % (core.bind_ip, core.server_port, core.config.get_config_path()))
        print(_("Glances server is running on %s:%s") % (core.bind_ip, core.server_port))
N
Nicolas Hennion 已提交
58 59 60 61 62

        # Set the server login/password (if -P/--password tag)
        if (core.password != ""):
            server.add_user(core.username, core.password)

N
Nicolas Hennion 已提交
63 64
        # Start the server loop
        server.serve_forever()
N
Nicolas Hennion 已提交
65 66 67 68 69

        # Shutdown the server
        # !!! How to close the server with CTRL-C
        # !!! Call core.end() with parameters ?
        server.server_close()