| Conditions | 4 |
| Total Lines | 500 |
| Code Lines | 416 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | # |
||
| 181 | def init_args(self): |
||
| 182 | """Init all the command line arguments.""" |
||
| 183 | parser = argparse.ArgumentParser( |
||
| 184 | prog='glances', |
||
| 185 | conflict_handler='resolve', |
||
| 186 | formatter_class=argparse.RawDescriptionHelpFormatter, |
||
| 187 | epilog=self.example_of_use, |
||
| 188 | ) |
||
| 189 | if shtab_tag: |
||
| 190 | shtab.add_argument_to(parser, ["--print-completion"]) |
||
| 191 | parser.add_argument('-V', '--version', action='version', version=self.version_msg()) |
||
| 192 | parser.add_argument('-d', '--debug', action='store_true', default=False, dest='debug', help='enable debug mode') |
||
| 193 | if shtab_tag: |
||
| 194 | parser.add_argument( |
||
| 195 | '-C', '--config', dest='conf_file', help='path to the configuration file' |
||
| 196 | ).complete = shtab.FILE |
||
| 197 | else: |
||
| 198 | parser.add_argument('-C', '--config', dest='conf_file', help='path to the configuration file') |
||
| 199 | parser.add_argument('-P', '--plugins', dest='plugin_dir', help='path to additional plugin directory') |
||
| 200 | # Disable plugin |
||
| 201 | parser.add_argument( |
||
| 202 | '--modules-list', |
||
| 203 | '--module-list', |
||
| 204 | action='store_true', |
||
| 205 | default=False, |
||
| 206 | dest='modules_list', |
||
| 207 | help='display modules (plugins & exports) list and exit', |
||
| 208 | ) |
||
| 209 | parser.add_argument( |
||
| 210 | '--disable-plugin', |
||
| 211 | '--disable-plugins', |
||
| 212 | '--disable', |
||
| 213 | dest='disable_plugin', |
||
| 214 | help='disable plugin (comma-separated list or all). If all is used, \ |
||
| 215 | then you need to configure --enable-plugin.', |
||
| 216 | ) |
||
| 217 | parser.add_argument( |
||
| 218 | '--enable-plugin', |
||
| 219 | '--enable-plugins', |
||
| 220 | '--enable', |
||
| 221 | dest='enable_plugin', |
||
| 222 | help='enable plugin (comma-separated list)', |
||
| 223 | ) |
||
| 224 | parser.add_argument( |
||
| 225 | '--disable-process', |
||
| 226 | action='store_true', |
||
| 227 | default=False, |
||
| 228 | dest='disable_process', |
||
| 229 | help='disable process module', |
||
| 230 | ) |
||
| 231 | # Enable or disable option |
||
| 232 | parser.add_argument( |
||
| 233 | '--disable-webui', |
||
| 234 | action='store_true', |
||
| 235 | default=False, |
||
| 236 | dest='disable_webui', |
||
| 237 | help='disable the Web Interface', |
||
| 238 | ) |
||
| 239 | parser.add_argument( |
||
| 240 | '--light', |
||
| 241 | '--enable-light', |
||
| 242 | action='store_true', |
||
| 243 | default=False, |
||
| 244 | dest='enable_light', |
||
| 245 | help='light mode for Curses UI (disable all but the top menu)', |
||
| 246 | ) |
||
| 247 | parser.add_argument( |
||
| 248 | '-0', |
||
| 249 | '--disable-irix', |
||
| 250 | action='store_true', |
||
| 251 | default=False, |
||
| 252 | dest='disable_irix', |
||
| 253 | help='task\'s cpu usage will be divided by the total number of CPUs', |
||
| 254 | ) |
||
| 255 | parser.add_argument( |
||
| 256 | '-1', |
||
| 257 | '--percpu', |
||
| 258 | '--per-cpu', |
||
| 259 | action='store_true', |
||
| 260 | default=False, |
||
| 261 | dest='percpu', |
||
| 262 | help='start Glances in per CPU mode', |
||
| 263 | ) |
||
| 264 | parser.add_argument( |
||
| 265 | '-2', |
||
| 266 | '--disable-left-sidebar', |
||
| 267 | action='store_true', |
||
| 268 | default=False, |
||
| 269 | dest='disable_left_sidebar', |
||
| 270 | help='disable network, disk I/O, FS and sensors modules', |
||
| 271 | ) |
||
| 272 | parser.add_argument( |
||
| 273 | '-3', |
||
| 274 | '--disable-quicklook', |
||
| 275 | action='store_true', |
||
| 276 | default=False, |
||
| 277 | dest='disable_quicklook', |
||
| 278 | help='disable quick look module', |
||
| 279 | ) |
||
| 280 | parser.add_argument( |
||
| 281 | '-4', |
||
| 282 | '--full-quicklook', |
||
| 283 | action='store_true', |
||
| 284 | default=False, |
||
| 285 | dest='full_quicklook', |
||
| 286 | help='disable all but quick look and load', |
||
| 287 | ) |
||
| 288 | parser.add_argument( |
||
| 289 | '-5', |
||
| 290 | '--disable-top', |
||
| 291 | action='store_true', |
||
| 292 | default=False, |
||
| 293 | dest='disable_top', |
||
| 294 | help='disable top menu (QL, CPU, MEM, SWAP and LOAD)', |
||
| 295 | ) |
||
| 296 | parser.add_argument( |
||
| 297 | '-6', '--meangpu', action='store_true', default=False, dest='meangpu', help='start Glances in mean GPU mode' |
||
| 298 | ) |
||
| 299 | parser.add_argument( |
||
| 300 | '--disable-history', |
||
| 301 | action='store_true', |
||
| 302 | default=False, |
||
| 303 | dest='disable_history', |
||
| 304 | help='disable stats history', |
||
| 305 | ) |
||
| 306 | parser.add_argument( |
||
| 307 | '--disable-bold', |
||
| 308 | action='store_true', |
||
| 309 | default=False, |
||
| 310 | dest='disable_bold', |
||
| 311 | help='disable bold mode in the terminal', |
||
| 312 | ) |
||
| 313 | parser.add_argument( |
||
| 314 | '--disable-bg', |
||
| 315 | action='store_true', |
||
| 316 | default=False, |
||
| 317 | dest='disable_bg', |
||
| 318 | help='disable background colors in the terminal', |
||
| 319 | ) |
||
| 320 | parser.add_argument( |
||
| 321 | '--enable-irq', action='store_true', default=False, dest='enable_irq', help='enable IRQ module' |
||
| 322 | ) |
||
| 323 | parser.add_argument( |
||
| 324 | '--enable-process-extended', |
||
| 325 | action='store_true', |
||
| 326 | default=False, |
||
| 327 | dest='enable_process_extended', |
||
| 328 | help='enable extended stats on top process', |
||
| 329 | ) |
||
| 330 | parser.add_argument( |
||
| 331 | '--disable-separator', |
||
| 332 | action='store_false', |
||
| 333 | default=True, |
||
| 334 | dest='enable_separator', |
||
| 335 | help='disable separator in the UI (between top and others modules)', |
||
| 336 | ) |
||
| 337 | parser.add_argument( |
||
| 338 | '--disable-cursor', |
||
| 339 | action='store_true', |
||
| 340 | default=False, |
||
| 341 | dest='disable_cursor', |
||
| 342 | help='disable cursor (process selection) in the UI', |
||
| 343 | ) |
||
| 344 | # Sort processes list |
||
| 345 | parser.add_argument( |
||
| 346 | '--sort-processes', |
||
| 347 | dest='sort_processes_key', |
||
| 348 | choices=sort_processes_stats_list, |
||
| 349 | help='Sort processes by: {}'.format(', '.join(sort_processes_stats_list)), |
||
| 350 | ) |
||
| 351 | # Display processes list by program name and not by thread |
||
| 352 | parser.add_argument( |
||
| 353 | '--programs', |
||
| 354 | '--program', |
||
| 355 | action='store_true', |
||
| 356 | default=False, |
||
| 357 | dest='programs', |
||
| 358 | help='Accumulate processes by program', |
||
| 359 | ) |
||
| 360 | # Export modules feature |
||
| 361 | parser.add_argument('--export', dest='export', help='enable export module (comma-separated list)') |
||
| 362 | parser.add_argument( |
||
| 363 | '--export-csv-file', default='./glances.csv', dest='export_csv_file', help='file path for CSV exporter' |
||
| 364 | ) |
||
| 365 | parser.add_argument( |
||
| 366 | '--export-csv-overwrite', |
||
| 367 | action='store_true', |
||
| 368 | default=False, |
||
| 369 | dest='export_csv_overwrite', |
||
| 370 | help='overwrite existing CSV file', |
||
| 371 | ) |
||
| 372 | parser.add_argument( |
||
| 373 | '--export-json-file', default='./glances.json', dest='export_json_file', help='file path for JSON exporter' |
||
| 374 | ) |
||
| 375 | parser.add_argument( |
||
| 376 | '--export-graph-path', |
||
| 377 | default=tempfile.gettempdir(), |
||
| 378 | dest='export_graph_path', |
||
| 379 | help='Folder for Graph exporter', |
||
| 380 | ) |
||
| 381 | parser.add_argument( |
||
| 382 | '--export-process-filter', |
||
| 383 | default=None, |
||
| 384 | type=str, |
||
| 385 | dest='export_process_filter', |
||
| 386 | help='set the export process filter (comma-separated list of regular expression)', |
||
| 387 | ) |
||
| 388 | # Client/Server option |
||
| 389 | parser.add_argument( |
||
| 390 | '-c', '--client', dest='client', help='connect to a Glances server by IPv4/IPv6 address or hostname' |
||
| 391 | ) |
||
| 392 | parser.add_argument( |
||
| 393 | '-s', '--server', action='store_true', default=False, dest='server', help='run Glances in server mode' |
||
| 394 | ) |
||
| 395 | parser.add_argument( |
||
| 396 | '--browser', |
||
| 397 | action='store_true', |
||
| 398 | default=False, |
||
| 399 | dest='browser', |
||
| 400 | help='start TUI Central Glances Browser (use --browser -w to start WebUI Central Glances Browser)', |
||
| 401 | ) |
||
| 402 | parser.add_argument( |
||
| 403 | '--disable-autodiscover', |
||
| 404 | action='store_true', |
||
| 405 | default=False, |
||
| 406 | dest='disable_autodiscover', |
||
| 407 | help='disable autodiscover feature', |
||
| 408 | ) |
||
| 409 | parser.add_argument( |
||
| 410 | '-p', |
||
| 411 | '--port', |
||
| 412 | default=None, |
||
| 413 | type=int, |
||
| 414 | dest='port', |
||
| 415 | help=f'define the client/server TCP port [default: {self.server_port}]', |
||
| 416 | ) |
||
| 417 | parser.add_argument( |
||
| 418 | '-B', |
||
| 419 | '--bind', |
||
| 420 | default='0.0.0.0', |
||
| 421 | dest='bind_address', |
||
| 422 | help='bind server to the given IPv4/IPv6 address or hostname', |
||
| 423 | ) |
||
| 424 | parser.add_argument( |
||
| 425 | '--username', |
||
| 426 | action='store_true', |
||
| 427 | default=False, |
||
| 428 | dest='username_prompt', |
||
| 429 | help='define a client/server username', |
||
| 430 | ) |
||
| 431 | parser.add_argument( |
||
| 432 | '--password', |
||
| 433 | action='store_true', |
||
| 434 | default=False, |
||
| 435 | dest='password_prompt', |
||
| 436 | help='define a client/server password', |
||
| 437 | ) |
||
| 438 | parser.add_argument('-u', dest='username_used', help='use the given client/server username') |
||
| 439 | parser.add_argument('--snmp-community', default='public', dest='snmp_community', help='SNMP community') |
||
| 440 | parser.add_argument('--snmp-port', default=161, type=int, dest='snmp_port', help='SNMP port') |
||
| 441 | parser.add_argument('--snmp-version', default='2c', dest='snmp_version', help='SNMP version (1, 2c or 3)') |
||
| 442 | parser.add_argument('--snmp-user', default='private', dest='snmp_user', help='SNMP username (only for SNMPv3)') |
||
| 443 | parser.add_argument( |
||
| 444 | '--snmp-auth', default='password', dest='snmp_auth', help='SNMP authentication key (only for SNMPv3)' |
||
| 445 | ) |
||
| 446 | parser.add_argument( |
||
| 447 | '--snmp-force', action='store_true', default=False, dest='snmp_force', help='force SNMP mode' |
||
| 448 | ) |
||
| 449 | parser.add_argument( |
||
| 450 | '-t', |
||
| 451 | '--time', |
||
| 452 | default=self.DEFAULT_REFRESH_TIME, |
||
| 453 | type=float, |
||
| 454 | dest='time', |
||
| 455 | help=f'set minimum refresh rate in seconds [default: {self.DEFAULT_REFRESH_TIME} sec]', |
||
| 456 | ) |
||
| 457 | parser.add_argument( |
||
| 458 | '-w', |
||
| 459 | '--webserver', |
||
| 460 | action='store_true', |
||
| 461 | default=False, |
||
| 462 | dest='webserver', |
||
| 463 | help='run Glances in web server mode (FastAPI, Uvicorn, Jinja2 libs needed)', |
||
| 464 | ) |
||
| 465 | parser.add_argument( |
||
| 466 | '--cached-time', |
||
| 467 | default=self.cached_time, |
||
| 468 | type=int, |
||
| 469 | dest='cached_time', |
||
| 470 | help=f'set the server cache time [default: {self.cached_time} sec]', |
||
| 471 | ) |
||
| 472 | parser.add_argument( |
||
| 473 | '--stop-after', |
||
| 474 | default=None, |
||
| 475 | type=int, |
||
| 476 | dest='stop_after', |
||
| 477 | help='stop Glances after n refresh', |
||
| 478 | ) |
||
| 479 | parser.add_argument( |
||
| 480 | '--open-web-browser', |
||
| 481 | action='store_true', |
||
| 482 | default=False, |
||
| 483 | dest='open_web_browser', |
||
| 484 | help='try to open the Web UI in the default Web browser', |
||
| 485 | ) |
||
| 486 | # Display options |
||
| 487 | parser.add_argument( |
||
| 488 | '-q', |
||
| 489 | '--quiet', |
||
| 490 | default=False, |
||
| 491 | action='store_true', |
||
| 492 | dest='quiet', |
||
| 493 | help='do not display the curses interface', |
||
| 494 | ) |
||
| 495 | parser.add_argument( |
||
| 496 | '-f', |
||
| 497 | '--process-filter', |
||
| 498 | default=None, |
||
| 499 | type=str, |
||
| 500 | dest='process_filter', |
||
| 501 | help='set the process filter pattern (regular expression)', |
||
| 502 | ) |
||
| 503 | # Process will focus on some process (comma-separated list of Glances filter) |
||
| 504 | parser.add_argument( |
||
| 505 | '--process-focus', |
||
| 506 | default=None, |
||
| 507 | type=str, |
||
| 508 | dest='process_focus', |
||
| 509 | help='set a process list to focus on (comma-separated list of Glances filter)', |
||
| 510 | ) |
||
| 511 | parser.add_argument( |
||
| 512 | '--process-short-name', |
||
| 513 | action='store_true', |
||
| 514 | default=True, |
||
| 515 | dest='process_short_name', |
||
| 516 | help='force short name for processes name', |
||
| 517 | ) |
||
| 518 | parser.add_argument( |
||
| 519 | '--process-long-name', |
||
| 520 | action='store_false', |
||
| 521 | default=False, |
||
| 522 | dest='process_short_name', |
||
| 523 | help='force long name for processes name', |
||
| 524 | ) |
||
| 525 | parser.add_argument( |
||
| 526 | '--stdout', |
||
| 527 | default=None, |
||
| 528 | dest='stdout', |
||
| 529 | help='display stats to stdout, one stat per line (comma-separated list of plugins/plugins.attribute)', |
||
| 530 | ) |
||
| 531 | parser.add_argument( |
||
| 532 | '--stdout-json', |
||
| 533 | default=None, |
||
| 534 | dest='stdout_json', |
||
| 535 | help='display stats to stdout, JSON format (comma-separated list of plugins/plugins.attribute)', |
||
| 536 | ) |
||
| 537 | parser.add_argument( |
||
| 538 | '--stdout-csv', |
||
| 539 | default=None, |
||
| 540 | dest='stdout_csv', |
||
| 541 | help='display stats to stdout, CSV format (comma-separated list of plugins/plugins.attribute)', |
||
| 542 | ) |
||
| 543 | parser.add_argument( |
||
| 544 | '--issue', |
||
| 545 | default=None, |
||
| 546 | action='store_true', |
||
| 547 | dest='stdout_issue', |
||
| 548 | help='test all plugins and exit (please copy/paste the output if you open an issue)', |
||
| 549 | ) |
||
| 550 | parser.add_argument( |
||
| 551 | '--trace-malloc', |
||
| 552 | default=False, |
||
| 553 | action='store_true', |
||
| 554 | dest='trace_malloc', |
||
| 555 | help='trace memory allocation and display it at the end of the process (python 3.4 or higher needed)', |
||
| 556 | ) |
||
| 557 | parser.add_argument( |
||
| 558 | '--memory-leak', |
||
| 559 | default=False, |
||
| 560 | action='store_true', |
||
| 561 | dest='memory_leak', |
||
| 562 | help='test memory leak (python 3.4 or higher needed)', |
||
| 563 | ) |
||
| 564 | parser.add_argument( |
||
| 565 | '--api-doc', |
||
| 566 | default=None, |
||
| 567 | action='store_true', |
||
| 568 | dest='stdout_api_doc', |
||
| 569 | help='display Python API documentation', |
||
| 570 | ) |
||
| 571 | parser.add_argument( |
||
| 572 | '--api-restful-doc', |
||
| 573 | default=None, |
||
| 574 | action='store_true', |
||
| 575 | dest='stdout_api_restful_doc', |
||
| 576 | help='display Restful API documentation', |
||
| 577 | ) |
||
| 578 | if not WINDOWS: |
||
| 579 | parser.add_argument( |
||
| 580 | '--hide-kernel-threads', |
||
| 581 | action='store_true', |
||
| 582 | default=False, |
||
| 583 | dest='no_kernel_threads', |
||
| 584 | help='hide kernel threads in the process list (not available on Windows)', |
||
| 585 | ) |
||
| 586 | parser.add_argument( |
||
| 587 | '-b', |
||
| 588 | '--byte', |
||
| 589 | action='store_true', |
||
| 590 | default=False, |
||
| 591 | dest='byte', |
||
| 592 | help='display network rate in bytes per second', |
||
| 593 | ) |
||
| 594 | parser.add_argument( |
||
| 595 | '--diskio-show-ramfs', |
||
| 596 | action='store_true', |
||
| 597 | default=False, |
||
| 598 | dest='diskio_show_ramfs', |
||
| 599 | help='show RAM Fs in the DiskIO plugin', |
||
| 600 | ) |
||
| 601 | parser.add_argument( |
||
| 602 | '--diskio-iops', |
||
| 603 | action='store_true', |
||
| 604 | default=False, |
||
| 605 | dest='diskio_iops', |
||
| 606 | help='show IO per second in the DiskIO plugin', |
||
| 607 | ) |
||
| 608 | parser.add_argument( |
||
| 609 | '--diskio-latency', |
||
| 610 | action='store_true', |
||
| 611 | default=False, |
||
| 612 | dest='diskio_latency', |
||
| 613 | help='show IO latency in the DiskIO plugin', |
||
| 614 | ) |
||
| 615 | parser.add_argument( |
||
| 616 | '--fahrenheit', |
||
| 617 | action='store_true', |
||
| 618 | default=False, |
||
| 619 | dest='fahrenheit', |
||
| 620 | help='display temperature in Fahrenheit (default is Celsius)', |
||
| 621 | ) |
||
| 622 | parser.add_argument( |
||
| 623 | '--fs-free-space', |
||
| 624 | action='store_true', |
||
| 625 | default=False, |
||
| 626 | dest='fs_free_space', |
||
| 627 | help='display FS free space instead of used', |
||
| 628 | ) |
||
| 629 | parser.add_argument( |
||
| 630 | '--sparkline', |
||
| 631 | action='store_true', |
||
| 632 | default=False, |
||
| 633 | dest='sparkline', |
||
| 634 | help='display sparklines instead of bar in the curses interface', |
||
| 635 | ) |
||
| 636 | parser.add_argument( |
||
| 637 | '--disable-unicode', |
||
| 638 | action='store_true', |
||
| 639 | default=False, |
||
| 640 | dest='disable_unicode', |
||
| 641 | help='disable unicode characters in the curses interface', |
||
| 642 | ) |
||
| 643 | parser.add_argument( |
||
| 644 | '--hide-public-info', |
||
| 645 | action='store_true', |
||
| 646 | default=False, |
||
| 647 | help='hide public information (like public IP)', |
||
| 648 | ) |
||
| 649 | # Globals options |
||
| 650 | parser.add_argument( |
||
| 651 | '--disable-check-update', |
||
| 652 | action='store_true', |
||
| 653 | default=False, |
||
| 654 | dest='disable_check_update', |
||
| 655 | help='disable online Glances version ckeck', |
||
| 656 | ) |
||
| 657 | parser.add_argument( |
||
| 658 | '--strftime', |
||
| 659 | dest='strftime_format', |
||
| 660 | default='', |
||
| 661 | help='strftime format string for displaying current date in standalone mode', |
||
| 662 | ) |
||
| 663 | # Fetch |
||
| 664 | parser.add_argument( |
||
| 665 | '--fetch', |
||
| 666 | '--stdout-fetch', |
||
| 667 | action='store_true', |
||
| 668 | default=False, |
||
| 669 | dest='stdout_fetch', |
||
| 670 | help='display a (neo)fetch like summary and exit', |
||
| 671 | ) |
||
| 672 | parser.add_argument( |
||
| 673 | '--fetch-template', |
||
| 674 | '--stdout-fetch-template', |
||
| 675 | dest='fetch_template', |
||
| 676 | default='', |
||
| 677 | help='overwrite default fetch template file', |
||
| 678 | ) |
||
| 679 | |||
| 680 | return parser |
||
| 681 | |||
| 928 |