| Conditions | 3 |
| Total Lines | 142 |
| Lines | 0 |
| Ratio | 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 -*- |
||
| 87 | def init_args(self): |
||
| 88 | """Init all the command line arguments.""" |
||
| 89 | _version = "Glances v" + version + " with psutil v" + psutil_version |
||
| 90 | parser = argparse.ArgumentParser( |
||
| 91 | prog=appname, |
||
| 92 | conflict_handler='resolve', |
||
| 93 | formatter_class=argparse.RawDescriptionHelpFormatter, |
||
| 94 | epilog=self.example_of_use) |
||
| 95 | parser.add_argument( |
||
| 96 | '-V', '--version', action='version', version=_version) |
||
| 97 | parser.add_argument('-d', '--debug', action='store_true', default=False, |
||
| 98 | dest='debug', help='enable debug mode') |
||
| 99 | parser.add_argument('-C', '--config', dest='conf_file', |
||
| 100 | help='path to the configuration file') |
||
| 101 | # Enable or disable option on startup |
||
| 102 | parser.add_argument('-3', '--disable-quicklook', action='store_true', default=False, |
||
| 103 | dest='disable_quicklook', help='disable quick look module') |
||
| 104 | parser.add_argument('-4', '--full-quicklook', action='store_true', default=False, |
||
| 105 | dest='full_quicklook', help='disable all but quick look and load') |
||
| 106 | parser.add_argument('--disable-cpu', action='store_true', default=False, |
||
| 107 | dest='disable_cpu', help='disable CPU module') |
||
| 108 | parser.add_argument('--disable-mem', action='store_true', default=False, |
||
| 109 | dest='disable_mem', help='disable memory module') |
||
| 110 | parser.add_argument('--disable-swap', action='store_true', default=False, |
||
| 111 | dest='disable_swap', help='disable swap module') |
||
| 112 | parser.add_argument('--disable-load', action='store_true', default=False, |
||
| 113 | dest='disable_load', help='disable load module') |
||
| 114 | parser.add_argument('--disable-network', action='store_true', default=False, |
||
| 115 | dest='disable_network', help='disable network module') |
||
| 116 | parser.add_argument('--disable-ip', action='store_true', default=False, |
||
| 117 | dest='disable_ip', help='disable IP module') |
||
| 118 | parser.add_argument('--disable-diskio', action='store_true', default=False, |
||
| 119 | dest='disable_diskio', help='disable disk I/O module') |
||
| 120 | parser.add_argument('--disable-fs', action='store_true', default=False, |
||
| 121 | dest='disable_fs', help='disable filesystem module') |
||
| 122 | parser.add_argument('--disable-folder', action='store_true', default=False, |
||
| 123 | dest='disable_folder', help='disable folder module') |
||
| 124 | parser.add_argument('--disable-sensors', action='store_true', default=False, |
||
| 125 | dest='disable_sensors', help='disable sensors module') |
||
| 126 | parser.add_argument('--disable-hddtemp', action='store_true', default=False, |
||
| 127 | dest='disable_hddtemp', help='disable HD temperature module') |
||
| 128 | parser.add_argument('--disable-raid', action='store_true', default=False, |
||
| 129 | dest='disable_raid', help='disable RAID module') |
||
| 130 | parser.add_argument('--disable-docker', action='store_true', default=False, |
||
| 131 | dest='disable_docker', help='disable Docker module') |
||
| 132 | parser.add_argument('-5', '--disable-top', action='store_true', |
||
| 133 | default=False, dest='disable_top', |
||
| 134 | help='disable top menu (QL, CPU, MEM, SWAP and LOAD)') |
||
| 135 | parser.add_argument('-2', '--disable-left-sidebar', action='store_true', |
||
| 136 | default=False, dest='disable_left_sidebar', |
||
| 137 | help='disable network, disk I/O, FS and sensors modules') |
||
| 138 | parser.add_argument('--disable-process', action='store_true', default=False, |
||
| 139 | dest='disable_process', help='disable process module') |
||
| 140 | parser.add_argument('--disable-log', action='store_true', default=False, |
||
| 141 | dest='disable_log', help='disable log module') |
||
| 142 | parser.add_argument('--disable-bold', action='store_true', default=False, |
||
| 143 | dest='disable_bold', help='disable bold mode in the terminal') |
||
| 144 | parser.add_argument('--disable-bg', action='store_true', default=False, |
||
| 145 | dest='disable_bg', help='disable background colors in the terminal') |
||
| 146 | parser.add_argument('--enable-process-extended', action='store_true', default=False, |
||
| 147 | dest='enable_process_extended', help='enable extended stats on top process') |
||
| 148 | parser.add_argument('--enable-history', action='store_true', default=False, |
||
| 149 | dest='enable_history', help='enable the history mode (matplotlib needed)') |
||
| 150 | parser.add_argument('--path-history', default=tempfile.gettempdir(), |
||
| 151 | dest='path_history', help='set the export path for graph history') |
||
| 152 | # Export modules feature |
||
| 153 | parser.add_argument('--export-csv', default=None, |
||
| 154 | dest='export_csv', help='export stats to a CSV file') |
||
| 155 | parser.add_argument('--export-influxdb', action='store_true', default=False, |
||
| 156 | dest='export_influxdb', help='export stats to an InfluxDB server (influxdb lib needed)') |
||
| 157 | parser.add_argument('--export-opentsdb', action='store_true', default=False, |
||
| 158 | dest='export_opentsdb', help='export stats to an OpenTSDB server (potsdb lib needed)') |
||
| 159 | parser.add_argument('--export-statsd', action='store_true', default=False, |
||
| 160 | dest='export_statsd', help='export stats to a StatsD server (statsd lib needed)') |
||
| 161 | parser.add_argument('--export-elasticsearch', action='store_true', default=False, |
||
| 162 | dest='export_elasticsearch', help='export stats to an ElasticSearch server (elasticsearch lib needed)') |
||
| 163 | parser.add_argument('--export-rabbitmq', action='store_true', default=False, |
||
| 164 | dest='export_rabbitmq', help='export stats to rabbitmq broker (pika lib needed)') |
||
| 165 | # Client/Server option |
||
| 166 | parser.add_argument('-c', '--client', dest='client', |
||
| 167 | help='connect to a Glances server by IPv4/IPv6 address or hostname') |
||
| 168 | parser.add_argument('-s', '--server', action='store_true', default=False, |
||
| 169 | dest='server', help='run Glances in server mode') |
||
| 170 | parser.add_argument('--browser', action='store_true', default=False, |
||
| 171 | dest='browser', help='start the client browser (list of servers)') |
||
| 172 | parser.add_argument('--disable-autodiscover', action='store_true', default=False, |
||
| 173 | dest='disable_autodiscover', help='disable autodiscover feature') |
||
| 174 | parser.add_argument('-p', '--port', default=None, type=int, dest='port', |
||
| 175 | help='define the client/server TCP port [default: {0}]'.format(self.server_port)) |
||
| 176 | parser.add_argument('-B', '--bind', default='0.0.0.0', dest='bind_address', |
||
| 177 | help='bind server to the given IPv4/IPv6 address or hostname') |
||
| 178 | parser.add_argument('--username', action='store_true', default=False, dest='username_prompt', |
||
| 179 | help='define a client/server username') |
||
| 180 | parser.add_argument('--password', action='store_true', default=False, dest='password_prompt', |
||
| 181 | help='define a client/server password') |
||
| 182 | parser.add_argument('--snmp-community', default='public', dest='snmp_community', |
||
| 183 | help='SNMP community') |
||
| 184 | parser.add_argument('--snmp-port', default=161, type=int, |
||
| 185 | dest='snmp_port', help='SNMP port') |
||
| 186 | parser.add_argument('--snmp-version', default='2c', dest='snmp_version', |
||
| 187 | help='SNMP version (1, 2c or 3)') |
||
| 188 | parser.add_argument('--snmp-user', default='private', dest='snmp_user', |
||
| 189 | help='SNMP username (only for SNMPv3)') |
||
| 190 | parser.add_argument('--snmp-auth', default='password', dest='snmp_auth', |
||
| 191 | help='SNMP authentication key (only for SNMPv3)') |
||
| 192 | parser.add_argument('--snmp-force', action='store_true', default=False, |
||
| 193 | dest='snmp_force', help='force SNMP mode') |
||
| 194 | parser.add_argument('-t', '--time', default=self.refresh_time, type=float, |
||
| 195 | dest='time', help='set refresh time in seconds [default: {0} sec]'.format(self.refresh_time)) |
||
| 196 | parser.add_argument('-w', '--webserver', action='store_true', default=False, |
||
| 197 | dest='webserver', help='run Glances in web server mode (bottle needed)') |
||
| 198 | # Display options |
||
| 199 | parser.add_argument('-q', '--quiet', default=False, action='store_true', |
||
| 200 | dest='quiet', help='do not display the curses interface') |
||
| 201 | parser.add_argument('-f', '--process-filter', default=None, type=str, |
||
| 202 | dest='process_filter', help='set the process filter pattern (regular expression)') |
||
| 203 | parser.add_argument('--process-short-name', action='store_true', default=False, |
||
| 204 | dest='process_short_name', help='force short name for processes name') |
||
| 205 | parser.add_argument('-0', '--disable-irix', action='store_true', default=False, |
||
| 206 | dest='disable_irix', help='Task\'s cpu usage will be divided by the total number of CPUs') |
||
| 207 | if not WINDOWS: |
||
| 208 | parser.add_argument('--hide-kernel-threads', action='store_true', default=False, |
||
| 209 | dest='no_kernel_threads', help='hide kernel threads in process list') |
||
| 210 | if LINUX: |
||
| 211 | parser.add_argument('--tree', action='store_true', default=False, |
||
| 212 | dest='process_tree', help='display processes as a tree') |
||
| 213 | parser.add_argument('-b', '--byte', action='store_true', default=False, |
||
| 214 | dest='byte', help='display network rate in byte per second') |
||
| 215 | parser.add_argument('--diskio-show-ramfs', action='store_true', default=False, |
||
| 216 | dest='diskio_show_ramfs', help='show RAM Fs in the DiskIO plugin') |
||
| 217 | parser.add_argument('--diskio-iops', action='store_true', default=False, |
||
| 218 | dest='diskio_iops', help='show IO per second in the DiskIO plugin') |
||
| 219 | parser.add_argument('--fahrenheit', action='store_true', default=False, |
||
| 220 | dest='fahrenheit', help='display temperature in Fahrenheit (default is Celsius)') |
||
| 221 | parser.add_argument('-1', '--percpu', action='store_true', default=False, |
||
| 222 | dest='percpu', help='start Glances in per CPU mode') |
||
| 223 | parser.add_argument('--fs-free-space', action='store_true', default=False, |
||
| 224 | dest='fs_free_space', help='display FS free space instead of used') |
||
| 225 | parser.add_argument('--theme-white', action='store_true', default=False, |
||
| 226 | dest='theme_white', help='optimize display colors for white background') |
||
| 227 | |||
| 228 | return parser |
||
| 229 | |||
| 388 |