Test Failed
Push — master ( 7e7379...128504 )
by Nicolas
03:31
created

glances.main.GlancesMain.init_args()   B

Complexity

Conditions 2

Size

Total Lines 418
Code Lines 346

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 346
nop 1
dl 0
loc 418
rs 7
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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