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