Issues (46)

glances/main.py (2 issues)

1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of Glances.
4
#
5
# SPDX-FileCopyrightText: 2023 Nicolas Hennion <[email protected]>
6
#
7
# SPDX-License-Identifier: LGPL-3.0-only
8
#
9
10
"""Glances main class."""
11
12
import argparse
13
import sys
14
import tempfile
15
16
from glances import __version__, psutil_version
17
from glances.compat import input, disable, enable, PY3
18
from glances.config import Config
19
from glances.globals import WINDOWS
20
from glances.processes import sort_processes_key_list
21
from glances.logger import logger, LOG_FILENAME
22
23
24
class GlancesMain(object):
25
    """Main class to manage Glances instance."""
26
27
    # Default stats' minimum refresh time is 2 seconds
28
    DEFAULT_REFRESH_TIME = 2
29
    # Set the default cache lifetime to 1 second (only for server)
30
    cached_time = 1
31
    # By default, Glances is ran in standalone mode (no client/server)
32
    client_tag = False
33
    # Server TCP port number (default is 61209)
34
    server_port = 61209
35
    # Web Server TCP port number (default is 61208)
36
    web_server_port = 61208
37
    # Default username/password for client/server mode
38
    username = "glances"
39
    password = ""
40
41
    # Examples of use
42
    example_of_use = """
43
Examples of use:
44
  Monitor local machine (standalone mode):
45
    $ glances
46
47
  Display all Glances modules (plugins and exporters) and exit:
48
    $ glances --module-list
49
50
  Monitor local machine with the Web interface and start RESTful server:
51
    $ glances -w
52
    Glances web server started on http://0.0.0.0:61208/
53
54
  Only start RESTful API (without the WebUI):
55
    $ glances -w --disable-webui
56
    Glances API available on http://0.0.0.0:61208/api/
57
58
  Monitor local machine and export stats to a CSV file (standalone mode):
59
    $ glances --export csv --export-csv-file /tmp/glances.csv
60
61
  Monitor local machine and export stats to a InfluxDB server with 5s refresh rate (standalone mode):
62
    $ glances -t 5 --export influxdb
63
64
  Start a Glances XML-RPC server (server mode):
65
    $ glances -s
66
67
  Connect Glances to a Glances XML-RPC server (client mode):
68
    $ glances -c <ip_server>
69
70
  Connect Glances to a Glances server and export stats to a StatsD server (client mode):
71
    $ glances -c <ip_server> --export statsd
72
73
  Start the client browser (browser mode):
74
    $ glances --browser
75
76
  Display stats to stdout (one stat per line, possible to go inside stats using plugin.attribute):
77
    $ glances --stdout now,cpu.user,mem.used,load
78
79
  Display JSON stats to stdout (one stats per line):
80
    $ glances --stdout-json now,cpu,mem,load
81
82
  Display CSV stats to stdout (all stats in one line):
83
    $ glances --stdout-csv now,cpu.user,mem.used,load
84
85
  Enable some plugins disabled by default (comma separated list):
86
    $ glances --enable-plugin sensors
87
88
  Disable some plugins (comma separated list):
89
    $ glances --disable-plugin network,ports
90
91
  Disable all plugins except some (comma separated list):
92
    $ glances --disable-plugin all --enable-plugin cpu,mem,load
93
94
"""
95
96
    def __init__(self):
97
        """Manage the command line arguments."""
98
        # Read the command line arguments
99
        self.args = self.parse_args()
100
101
    def init_args(self):
102
        """Init all the command line arguments."""
103
        version = 'Glances v{} with PsUtil v{}\nLog file: {}'.format(__version__, psutil_version, LOG_FILENAME)
104
        parser = argparse.ArgumentParser(
105
            prog='glances',
106
            conflict_handler='resolve',
107
            formatter_class=argparse.RawDescriptionHelpFormatter,
108
            epilog=self.example_of_use,
109
        )
110
        parser.add_argument('-V', '--version', action='version', version=version)
111
        parser.add_argument('-d', '--debug', action='store_true', default=False, dest='debug', help='enable debug mode')
112
        parser.add_argument('-C', '--config', dest='conf_file', help='path to the configuration file')
113
        # Disable plugin
114
        parser.add_argument(
115
            '--modules-list',
116
            '--module-list',
117
            action='store_true',
118
            default=False,
119
            dest='modules_list',
120
            help='display modules (plugins & exports) list and exit',
121
        )
122
        parser.add_argument(
123
            '--disable-plugin',
124
            '--disable-plugins',
125
            dest='disable_plugin',
126
            help='disable plugin (comma separated list or all). If all is used, \
127
                then you need to configure --enable-plugin.',
128
        )
129
        parser.add_argument(
130
            '--enable-plugin', '--enable-plugins', dest='enable_plugin', help='enable plugin (comma separated list)'
131
        )
132
        parser.add_argument(
133
            '--disable-process',
134
            action='store_true',
135
            default=False,
136
            dest='disable_process',
137
            help='disable process module',
138
        )
139
        # Enable or disable option
140
        parser.add_argument(
141
            '--disable-webui',
142
            action='store_true',
143
            default=False,
144
            dest='disable_webui',
145
            help='disable the Web Interface',
146
        )
147
        parser.add_argument(
148
            '--light',
149
            '--enable-light',
150
            action='store_true',
151
            default=False,
152
            dest='enable_light',
153
            help='light mode for Curses UI (disable all but top menu)',
154
        )
155
        parser.add_argument(
156
            '-0',
157
            '--disable-irix',
158
            action='store_true',
159
            default=False,
160
            dest='disable_irix',
161
            help='task\'s cpu usage will be divided by the total number of CPUs',
162
        )
163
        parser.add_argument(
164
            '-1', '--percpu', action='store_true', default=False, dest='percpu', help='start Glances in per CPU mode'
165
        )
166
        parser.add_argument(
167
            '-2',
168
            '--disable-left-sidebar',
169
            action='store_true',
170
            default=False,
171
            dest='disable_left_sidebar',
172
            help='disable network, disk I/O, FS and sensors modules',
173
        )
174
        parser.add_argument(
175
            '-3',
176
            '--disable-quicklook',
177
            action='store_true',
178
            default=False,
179
            dest='disable_quicklook',
180
            help='disable quick look module',
181
        )
182
        parser.add_argument(
183
            '-4',
184
            '--full-quicklook',
185
            action='store_true',
186
            default=False,
187
            dest='full_quicklook',
188
            help='disable all but quick look and load',
189
        )
190
        parser.add_argument(
191
            '-5',
192
            '--disable-top',
193
            action='store_true',
194
            default=False,
195
            dest='disable_top',
196
            help='disable top menu (QL, CPU, MEM, SWAP and LOAD)',
197
        )
198
        parser.add_argument(
199
            '-6', '--meangpu', action='store_true', default=False, dest='meangpu', help='start Glances in mean GPU mode'
200
        )
201
        parser.add_argument(
202
            '--disable-history',
203
            action='store_true',
204
            default=False,
205
            dest='disable_history',
206
            help='disable stats history',
207
        )
208
        parser.add_argument(
209
            '--disable-bold',
210
            action='store_true',
211
            default=False,
212
            dest='disable_bold',
213
            help='disable bold mode in the terminal',
214
        )
215
        parser.add_argument(
216
            '--disable-bg',
217
            action='store_true',
218
            default=False,
219
            dest='disable_bg',
220
            help='disable background colors in the terminal',
221
        )
222
        parser.add_argument(
223
            '--enable-irq', action='store_true', default=False, dest='enable_irq', help='enable IRQ module'
224
        ),
225
        parser.add_argument(
226
            '--enable-process-extended',
227
            action='store_true',
228
            default=False,
229
            dest='enable_process_extended',
230
            help='enable extended stats on top process',
231
        )
232
        parser.add_argument(
233
            '--separator',
234
            '--enable-separator',
235
            action='store_true',
236
            default=False,
237
            dest='enable_separator',
238
            help='enable separator in the UI',
239
        ),
240
        parser.add_argument(
241
            '--disable-cursor',
242
            action='store_true',
243
            default=False,
244
            dest='disable_cursor',
245
            help='disable cursor (process selection) in the UI',
246
        ),
247
        # Sort processes list
248
        parser.add_argument(
249
            '--sort-processes',
250
            dest='sort_processes_key',
251
            choices=sort_processes_key_list,
252
            help='Sort processes by: {}'.format(', '.join(sort_processes_key_list)),
253
        )
254
        # Display processes list by program name and not by thread
255
        parser.add_argument(
256
            '--programs',
257
            '--program',
258
            action='store_true',
259
            default=False,
260
            dest='programs',
261
            help='Accumulate processes by program',
262
        )
263
        # Export modules feature
264
        parser.add_argument('--export', dest='export', help='enable export module (comma separated list)')
265
        parser.add_argument(
266
            '--export-csv-file', default='./glances.csv', dest='export_csv_file', help='file path for CSV exporter'
267
        )
268
        parser.add_argument(
269
            '--export-csv-overwrite',
270
            action='store_true',
271
            default=False,
272
            dest='export_csv_overwrite',
273
            help='overwrite existing CSV file',
274
        )
275
        parser.add_argument(
276
            '--export-json-file', default='./glances.json', dest='export_json_file', help='file path for JSON exporter'
277
        )
278
        parser.add_argument(
279
            '--export-graph-path',
280
            default=tempfile.gettempdir(),
281
            dest='export_graph_path',
282
            help='Folder for Graph exporter',
283
        )
284
        # Client/Server option
285
        parser.add_argument(
286
            '-c', '--client', dest='client', help='connect to a Glances server by IPv4/IPv6 address or hostname'
287
        )
288
        parser.add_argument(
289
            '-s', '--server', action='store_true', default=False, dest='server', help='run Glances in server mode'
290
        )
291
        parser.add_argument(
292
            '--browser',
293
            action='store_true',
294
            default=False,
295
            dest='browser',
296
            help='start the client browser (list of servers)',
297
        )
298
        parser.add_argument(
299
            '--disable-autodiscover',
300
            action='store_true',
301
            default=False,
302
            dest='disable_autodiscover',
303
            help='disable autodiscover feature',
304
        )
305
        parser.add_argument(
306
            '-p',
307
            '--port',
308
            default=None,
309
            type=int,
310
            dest='port',
311
            help='define the client/server TCP port [default: {}]'.format(self.server_port),
312
        )
313
        parser.add_argument(
314
            '-B',
315
            '--bind',
316
            default='0.0.0.0',
317
            dest='bind_address',
318
            help='bind server to the given IPv4/IPv6 address or hostname',
319
        )
320
        parser.add_argument(
321
            '--username',
322
            action='store_true',
323
            default=False,
324
            dest='username_prompt',
325
            help='define a client/server username',
326
        )
327
        parser.add_argument(
328
            '--password',
329
            action='store_true',
330
            default=False,
331
            dest='password_prompt',
332
            help='define a client/server password',
333
        )
334
        parser.add_argument('-u', dest='username_used', help='use the given client/server username')
335
        parser.add_argument('--snmp-community', default='public', dest='snmp_community', help='SNMP community')
336
        parser.add_argument('--snmp-port', default=161, type=int, dest='snmp_port', help='SNMP port')
337
        parser.add_argument('--snmp-version', default='2c', dest='snmp_version', help='SNMP version (1, 2c or 3)')
338
        parser.add_argument('--snmp-user', default='private', dest='snmp_user', help='SNMP username (only for SNMPv3)')
339
        parser.add_argument(
340
            '--snmp-auth', default='password', dest='snmp_auth', help='SNMP authentication key (only for SNMPv3)'
341
        )
342
        parser.add_argument(
343
            '--snmp-force', action='store_true', default=False, dest='snmp_force', help='force SNMP mode'
344
        )
345
        parser.add_argument(
346
            '-t',
347
            '--time',
348
            default=self.DEFAULT_REFRESH_TIME,
349
            type=float,
350
            dest='time',
351
            help='set minimum refresh rate in seconds [default: {} sec]'.format(self.DEFAULT_REFRESH_TIME),
352
        )
353
        parser.add_argument(
354
            '-w',
355
            '--webserver',
356
            action='store_true',
357
            default=False,
358
            dest='webserver',
359
            help='run Glances in web server mode (bottle needed)',
360
        )
361
        parser.add_argument(
362
            '--cached-time',
363
            default=self.cached_time,
364
            type=int,
365
            dest='cached_time',
366
            help='set the server cache time [default: {} sec]'.format(self.cached_time),
367
        )
368
        parser.add_argument(
369
            '--stop-after',
370
            default=None,
371
            type=int,
372
            dest='stop_after',
373
            help='stop Glances after n refresh',
374
        )
375
        parser.add_argument(
376
            '--open-web-browser',
377
            action='store_true',
378
            default=False,
379
            dest='open_web_browser',
380
            help='try to open the Web UI in the default Web browser',
381
        )
382
        # Display options
383
        parser.add_argument(
384
            '-q',
385
            '--quiet',
386
            default=False,
387
            action='store_true',
388
            dest='quiet',
389
            help='do not display the curses interface',
390
        )
391
        parser.add_argument(
392
            '-f',
393
            '--process-filter',
394
            default=None,
395
            type=str,
396
            dest='process_filter',
397
            help='set the process filter pattern (regular expression)',
398
        )
399
        parser.add_argument(
400
            '--process-short-name',
401
            action='store_true',
402
            default=True,
403
            dest='process_short_name',
404
            help='force short name for processes name',
405
        )
406
        parser.add_argument(
407
            '--process-long-name',
408
            action='store_false',
409
            default=False,
410
            dest='process_short_name',
411
            help='force long name for processes name',
412
        )
413
        parser.add_argument(
414
            '--stdout',
415
            default=None,
416
            dest='stdout',
417
            help='display stats to stdout, one stat per line (comma separated list of plugins/plugins.attribute)',
418
        )
419
        parser.add_argument(
420
            '--stdout-json',
421
            default=None,
422
            dest='stdout_json',
423
            help='display stats to stdout, JSON format (comma separated list of plugins/plugins.attribute)',
424
        )
425
        parser.add_argument(
426
            '--stdout-csv',
427
            default=None,
428
            dest='stdout_csv',
429
            help='display stats to stdout, CSV format (comma separated list of plugins/plugins.attribute)',
430
        )
431
        parser.add_argument(
432
            '--issue',
433
            default=None,
434
            action='store_true',
435
            dest='stdout_issue',
436
            help='test all plugins and exit (please copy/paste the output if you open an issue)',
437
        )
438
        parser.add_argument(
439
            '--trace-malloc',
440
            default=False,
441
            action='store_true',
442
            dest='trace_malloc',
443
            help='trace memory allocation and display it at the end of the process (python 3.4 or higher needed)',
444
        )
445
        parser.add_argument(
446
            '--memory-leak',
447
            default=False,
448
            action='store_true',
449
            dest='memory_leak',
450
            help='test memory leak (python 3.4 or higher needed)',
451
        )
452
        parser.add_argument(
453
            '--api-doc', default=None, action='store_true', dest='stdout_apidoc', help='display fields descriptions'
454
        )
455
        if not WINDOWS:
456
            parser.add_argument(
457
                '--hide-kernel-threads',
458
                action='store_true',
459
                default=False,
460
                dest='no_kernel_threads',
461
                help='hide kernel threads in process list (not available on Windows)',
462
            )
463
        parser.add_argument(
464
            '-b',
465
            '--byte',
466
            action='store_true',
467
            default=False,
468
            dest='byte',
469
            help='display network rate in byte per second',
470
        )
471
        parser.add_argument(
472
            '--diskio-show-ramfs',
473
            action='store_true',
474
            default=False,
475
            dest='diskio_show_ramfs',
476
            help='show RAM Fs in the DiskIO plugin',
477
        )
478
        parser.add_argument(
479
            '--diskio-iops',
480
            action='store_true',
481
            default=False,
482
            dest='diskio_iops',
483
            help='show IO per second in the DiskIO plugin',
484
        )
485
        parser.add_argument(
486
            '--fahrenheit',
487
            action='store_true',
488
            default=False,
489
            dest='fahrenheit',
490
            help='display temperature in Fahrenheit (default is Celsius)',
491
        )
492
        parser.add_argument(
493
            '--fs-free-space',
494
            action='store_true',
495
            default=False,
496
            dest='fs_free_space',
497
            help='display FS free space instead of used',
498
        )
499
        parser.add_argument(
500
            '--sparkline',
501
            action='store_true',
502
            default=False,
503
            dest='sparkline',
504
            help='display sparklines instead of bar in the curses interface',
505
        )
506
        parser.add_argument(
507
            '--disable-unicode',
508
            action='store_true',
509
            default=False,
510
            dest='disable_unicode',
511
            help='disable unicode characters in the curses interface',
512
        )
513
        parser.add_argument(
514
            '--theme-white',
515
            action='store_true',
516
            default=False,
517
            dest='theme_white',
518
            help='optimize display colors for white background',
519
        )
520
        # Globals options
521
        parser.add_argument(
522
            '--disable-check-update',
523
            action='store_true',
524
            default=False,
525
            dest='disable_check_update',
526
            help='disable online Glances version ckeck',
527
        )
528
        parser.add_argument(
529
            '--strftime',
530
            dest='strftime_format',
531
            default='',
532
            help='strftime format string for displaying current date in standalone mode',
533
        )
534
535
        return parser
536
537
    def parse_args(self):
538
        """Parse command line arguments."""
539
        args = self.init_args().parse_args()
540
541
        # Load the configuration file, if it exists
542
        # This function should be called after the parse_args
543
        # because the configuration file path can be defined
544
        self.config = Config(args.conf_file)
545
546
        # Debug mode
547
        if args.debug:
548
            from logging import DEBUG
549
550
            logger.setLevel(DEBUG)
551
        else:
552
            from warnings import simplefilter
553
554
            simplefilter("ignore")
555
556
        # Plugins refresh rate
557
        if self.config.has_section('global'):
558
            global_refresh = self.config.get_float_value('global', 'refresh', default=self.DEFAULT_REFRESH_TIME)
559
        else:
560
            global_refresh = self.DEFAULT_REFRESH_TIME
561
        # The configuration key can be overwrite from the command line
562
        if args.time == self.DEFAULT_REFRESH_TIME:
563
            args.time = global_refresh
564
        logger.debug('Global refresh rate is set to {} seconds'.format(args.time))
565
566
        # Plugins disable/enable
567
        # Allow users to disable plugins from the glances.conf (issue #1378)
568
        for s in self.config.sections():
569
            if self.config.has_section(s) and (self.config.get_bool_value(s, 'disable', False)):
570
                disable(args, s)
571
                logger.debug('{} disabled by the configuration file'.format(s))
572
        # The configuration key can be overwrite from the command line
573
        if args and args.disable_plugin and 'all' in args.disable_plugin.split(','):
574
            if not args.enable_plugin:
575
                logger.critical("'all' key in --disable-plugin needs to be used with --enable-plugin")
576
                sys.exit(2)
577
            else:
578
                logger.info(
579
                    "'all' key in --disable-plugin, only plugins defined with --enable-plugin will be available"
580
                )
581
        if args.disable_plugin is not None:
582
            for p in args.disable_plugin.split(','):
583
                disable(args, p)
584
        if args.enable_plugin is not None:
585
            for p in args.enable_plugin.split(','):
586
                enable(args, p)
587
588
        # Exporters activation
589
        if args.export is not None:
590
            for p in args.export.split(','):
591
                setattr(args, 'export_' + p, True)
592
593
        # Client/server Port
594
        if args.port is None:
595
            if args.webserver:
596
                args.port = self.web_server_port
597
            else:
598
                args.port = self.server_port
599
        # Port in the -c URI #996
600
        if args.client is not None:
601
            args.client, args.port = (
602
                x if x else y for (x, y) in zip(args.client.partition(':')[::2], (args.client, args.port))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable x does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable y does not seem to be defined.
Loading history...
603
            )
604
605
        # Autodiscover
606
        if args.disable_autodiscover:
607
            logger.info("Auto discover mode is disabled")
608
609
        # In web server mode
610
        if args.webserver:
611
            args.process_short_name = True
612
613
        # Server or client login/password
614
        if args.username_prompt:
615
            # Every username needs a password
616
            args.password_prompt = True
617
            # Prompt username
618
            if args.server:
619
                args.username = self.__get_username(description='Define the Glances server username: ')
620
            elif args.webserver:
621
                args.username = self.__get_username(description='Define the Glances webserver username: ')
622
            elif args.client:
623
                args.username = self.__get_username(description='Enter the Glances server username: ')
624
        else:
625
            if args.username_used:
626
                # A username has been set using the -u option ?
627
                args.username = args.username_used
628
            else:
629
                # Default user name is 'glances'
630
                args.username = self.username
631
632
        if args.password_prompt or args.username_used:
633
            # Interactive or file password
634
            if args.server:
635
                args.password = self.__get_password(
636
                    description='Define the Glances server password ({} username): '.format(args.username),
637
                    confirm=True,
638
                    username=args.username,
639
                )
640
            elif args.webserver:
641
                args.password = self.__get_password(
642
                    description='Define the Glances webserver password ({} username): '.format(args.username),
643
                    confirm=True,
644
                    username=args.username,
645
                )
646
            elif args.client:
647
                args.password = self.__get_password(
648
                    description='Enter the Glances server password ({} username): '.format(args.username),
649
                    clear=True,
650
                    username=args.username,
651
                )
652
        else:
653
            # Default is no password
654
            args.password = self.password
655
656
        # By default help is hidden
657
        args.help_tag = False
658
659
        # Display Rx and Tx, not the sum for the network
660
        args.network_sum = False
661
        args.network_cumul = False
662
663
        # Manage light mode
664
        if args.enable_light:
665
            logger.info("Light mode is on")
666
            args.disable_left_sidebar = True
667
            disable(args, 'process')
668
            disable(args, 'alert')
669
            disable(args, 'amps')
670
            disable(args, 'docker')
671
672
        # Manage full quicklook option
673
        if args.full_quicklook:
674
            logger.info("Full quicklook mode")
675
            enable(args, 'quicklook')
676
            disable(args, 'cpu')
677
            disable(args, 'mem')
678
            disable(args, 'memswap')
679
            enable(args, 'load')
680
681
        # Manage disable_top option
682
        if args.disable_top:
683
            logger.info("Disable top menu")
684
            disable(args, 'quicklook')
685
            disable(args, 'cpu')
686
            disable(args, 'mem')
687
            disable(args, 'memswap')
688
            disable(args, 'load')
689
690
        # Init the generate_graph tag
691
        # Should be set to True to generate graphs
692
        args.generate_graph = False
693
694
        # Control parameter and exit if it is not OK
695
        self.args = args
696
697
        # Export is only available in standalone or client mode (issue #614)
698
        export_tag = self.args.export is not None and any(self.args.export)
699
        if WINDOWS and export_tag:
700
            # On Windows, export is possible but only in quiet mode
701
            # See issue #1038
702
            logger.info("On Windows OS, export disable the Web interface")
703
            self.args.quiet = True
704
            self.args.webserver = False
705
        elif not (self.is_standalone() or self.is_client()) and export_tag:
706
            logger.critical("Export is only available in standalone or client mode")
707
            sys.exit(2)
708
709
        # Filter is only available in standalone mode
710
        if not args.process_filter and not self.is_standalone():
711
            logger.debug("Process filter is only available in standalone mode")
712
713
        # Cursor option is only available in standalone mode
714
        if not args.disable_cursor and not self.is_standalone():
715
            logger.debug("Cursor is only available in standalone mode")
716
717
        # Disable HDDTemp if sensors are disabled
718
        if getattr(self.args, 'disable_sensors', False):
719
            disable(self.args, 'hddtemp')
720
            logger.debug("Sensors and HDDTemp are disabled")
721
722
        if getattr(self.args, 'trace_malloc', True) and not (PY3 or self.is_standalone()):
723
            logger.critical("Option --trace-malloc is only available with Python 3 and terminal mode")
724
            sys.exit(2)
725
726
        if getattr(self.args, 'memory_leak', True) and not (PY3 or self.is_standalone()):
727
            logger.critical("Option --memory-leak is only available with Python 3 and terminal mode")
728
            sys.exit(2)
729
        elif getattr(self.args, 'memory_leak', True) and (PY3 or self.is_standalone()):
730
            logger.info('Memory leak detection enabled')
731
            self.args.quiet = True
732
            if not self.args.stop_after:
733
                self.args.stop_after = 60
734
            self.args.time = 1
735
            self.args.disable_history = True
736
737
        # Let the plugins known the Glances mode
738
        self.args.is_standalone = self.is_standalone()
739
        self.args.is_client = self.is_client()
740
        self.args.is_client_browser = self.is_client_browser()
741
        self.args.is_server = self.is_server()
742
        self.args.is_webserver = self.is_webserver()
743
744
        # Check mode compatibility
745
        self.check_mode_compatibility()
746
747
        return args
748
749
    def check_mode_compatibility(self):
750
        """Check mode compatibility"""
751
        if self.args.is_server and self.args.is_webserver:
752
            logger.critical("Server and Web server mode are incompatible")
753
            sys.exit(2)
754
755
    def is_standalone(self):
756
        """Return True if Glances is running in standalone mode."""
757
        return not self.args.client and not self.args.browser and not self.args.server and not self.args.webserver
758
759
    def is_client(self):
760
        """Return True if Glances is running in client mode."""
761
        return (self.args.client or self.args.browser) and not self.args.server
762
763
    def is_client_browser(self):
764
        """Return True if Glances is running in client browser mode."""
765
        return self.args.browser and not self.args.server
766
767
    def is_server(self):
768
        """Return True if Glances is running in server mode."""
769
        return not self.args.client and self.args.server
770
771
    def is_webserver(self):
772
        """Return True if Glances is running in Web server mode."""
773
        return not self.args.client and self.args.webserver
774
775
    def get_config(self):
776
        """Return configuration file object."""
777
        return self.config
778
779
    def get_args(self):
780
        """Return the arguments."""
781
        return self.args
782
783
    def get_mode(self):
784
        """Return the mode."""
785
        return self.mode
786
787
    def __get_username(self, description=''):
788
        """Read an username from the command line."""
789
        return input(description)
790
791
    def __get_password(self, description='', confirm=False, clear=False, username='glances'):
792
        """Read a password from the command line.
793
794
        - if confirm = True, with confirmation
795
        - if clear = True, plain (clear password)
796
        """
797
        from glances.password import GlancesPassword
798
799
        password = GlancesPassword(username=username, config=self.get_config())
800
        return password.get_password(description, confirm, clear)
801