| Conditions | 2 |
| Total Lines | 418 |
| Code Lines | 346 |
| 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 -*- |
||
| 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 | |||
| 764 |