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