| Conditions | 3 |
| Total Lines | 178 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 -*- |
||
| 86 | def init_args(self): |
||
| 87 | """Init all the command line arguments.""" |
||
| 88 | version = "Glances v" + __version__ + " with psutil v" + psutil_version |
||
| 89 | parser = argparse.ArgumentParser( |
||
| 90 | prog='glances', |
||
| 91 | conflict_handler='resolve', |
||
| 92 | formatter_class=argparse.RawDescriptionHelpFormatter, |
||
| 93 | epilog=self.example_of_use) |
||
| 94 | parser.add_argument( |
||
| 95 | '-V', '--version', action='version', version=version) |
||
| 96 | parser.add_argument('-d', '--debug', action='store_true', default=False, |
||
| 97 | dest='debug', help='enable debug mode') |
||
| 98 | parser.add_argument('-C', '--config', dest='conf_file', |
||
| 99 | help='path to the configuration file') |
||
| 100 | # Enable or disable option on startup |
||
| 101 | parser.add_argument('--disable-alert', action='store_true', default=False, |
||
| 102 | dest='disable_alert', help='disable alert module') |
||
| 103 | parser.add_argument('--disable-amps', action='store_true', default=False, |
||
| 104 | dest='disable_amps', help='disable applications monitoring process (AMP) module') |
||
| 105 | parser.add_argument('--disable-cloud', action='store_true', default=False, |
||
| 106 | dest='disable_cloud', help='disable Cloud module') |
||
| 107 | parser.add_argument('--disable-cpu', action='store_true', default=False, |
||
| 108 | dest='disable_cpu', help='disable CPU module') |
||
| 109 | parser.add_argument('--disable-diskio', action='store_true', default=False, |
||
| 110 | dest='disable_diskio', help='disable disk I/O module') |
||
| 111 | parser.add_argument('--disable-docker', action='store_true', default=False, |
||
| 112 | dest='disable_docker', help='disable Docker module') |
||
| 113 | parser.add_argument('--disable-folders', action='store_true', default=False, |
||
| 114 | dest='disable_folders', help='disable folder module') |
||
| 115 | parser.add_argument('--disable-fs', action='store_true', default=False, |
||
| 116 | dest='disable_fs', help='disable filesystem module') |
||
| 117 | parser.add_argument('--disable-gpu', action='store_true', default=False, |
||
| 118 | dest='disable_gpu', help='disable GPU module') |
||
| 119 | parser.add_argument('--disable-hddtemp', action='store_true', default=False, |
||
| 120 | dest='disable_hddtemp', help='disable HD temperature module') |
||
| 121 | parser.add_argument('--disable-ip', action='store_true', default=False, |
||
| 122 | dest='disable_ip', help='disable IP module') |
||
| 123 | parser.add_argument('--disable-load', action='store_true', default=False, |
||
| 124 | dest='disable_load', help='disable load module') |
||
| 125 | parser.add_argument('--disable-mem', action='store_true', default=False, |
||
| 126 | dest='disable_mem', help='disable memory module') |
||
| 127 | parser.add_argument('--disable-memswap', action='store_true', default=False, |
||
| 128 | dest='disable_memswap', help='disable memory swap module') |
||
| 129 | parser.add_argument('--disable-network', action='store_true', default=False, |
||
| 130 | dest='disable_network', help='disable network module') |
||
| 131 | parser.add_argument('--disable-now', action='store_true', default=False, |
||
| 132 | dest='disable_now', help='disable current time module') |
||
| 133 | parser.add_argument('--disable-ports', action='store_true', default=False, |
||
| 134 | dest='disable_ports', help='disable ports scanner module') |
||
| 135 | parser.add_argument('--disable-process', action='store_true', default=False, |
||
| 136 | dest='disable_process', help='disable process module') |
||
| 137 | parser.add_argument('--disable-raid', action='store_true', default=False, |
||
| 138 | dest='disable_raid', help='disable RAID module') |
||
| 139 | parser.add_argument('--disable-sensors', action='store_true', default=False, |
||
| 140 | dest='disable_sensors', help='disable sensors module') |
||
| 141 | parser.add_argument('--disable-wifi', action='store_true', default=False, |
||
| 142 | dest='disable_wifi', help='disable wifi module') |
||
| 143 | parser.add_argument('-0', '--disable-irix', action='store_true', default=False, |
||
| 144 | dest='disable_irix', help='task\'s cpu usage will be divided by the total number of CPUs') |
||
| 145 | parser.add_argument('-1', '--percpu', action='store_true', default=False, |
||
| 146 | dest='percpu', help='start Glances in per CPU mode') |
||
| 147 | parser.add_argument('-2', '--disable-left-sidebar', action='store_true', |
||
| 148 | default=False, dest='disable_left_sidebar', |
||
| 149 | help='disable network, disk I/O, FS and sensors modules') |
||
| 150 | parser.add_argument('-3', '--disable-quicklook', action='store_true', default=False, |
||
| 151 | dest='disable_quicklook', help='disable quick look module') |
||
| 152 | parser.add_argument('-4', '--full-quicklook', action='store_true', default=False, |
||
| 153 | dest='full_quicklook', help='disable all but quick look and load') |
||
| 154 | parser.add_argument('-5', '--disable-top', action='store_true', |
||
| 155 | default=False, dest='disable_top', |
||
| 156 | help='disable top menu (QL, CPU, MEM, SWAP and LOAD)') |
||
| 157 | parser.add_argument('-6', '--meangpu', action='store_true', default=False, |
||
| 158 | dest='meangpu', help='start Glances in mean GPU mode') |
||
| 159 | parser.add_argument('--disable-history', action='store_true', default=False, |
||
| 160 | dest='disable_history', help='disable stats history') |
||
| 161 | parser.add_argument('--disable-bold', action='store_true', default=False, |
||
| 162 | dest='disable_bold', help='disable bold mode in the terminal') |
||
| 163 | parser.add_argument('--disable-bg', action='store_true', default=False, |
||
| 164 | dest='disable_bg', help='disable background colors in the terminal') |
||
| 165 | parser.add_argument('--enable-irq', action='store_true', default=False, |
||
| 166 | dest='enable_irq', help='enable IRQ module'), |
||
| 167 | parser.add_argument('--enable-process-extended', action='store_true', default=False, |
||
| 168 | dest='enable_process_extended', help='enable extended stats on top process') |
||
| 169 | # Export modules feature |
||
| 170 | parser.add_argument('--export-graph', action='store_true', default=None, |
||
| 171 | dest='export_graph', help='export stats to graphs') |
||
| 172 | parser.add_argument('--path-graph', default=tempfile.gettempdir(), |
||
| 173 | dest='path_graph', help='set the export path for graphs (default is {})'.format(tempfile.gettempdir())) |
||
| 174 | parser.add_argument('--export-csv', default=None, |
||
| 175 | dest='export_csv', help='export stats to a CSV file') |
||
| 176 | parser.add_argument('--export-cassandra', action='store_true', default=False, |
||
| 177 | dest='export_cassandra', help='export stats to a Cassandra or Scylla server (cassandra lib needed)') |
||
| 178 | parser.add_argument('--export-couchdb', action='store_true', default=False, |
||
| 179 | dest='export_couchdb', help='export stats to a CouchDB server (couch lib needed)') |
||
| 180 | parser.add_argument('--export-elasticsearch', action='store_true', default=False, |
||
| 181 | dest='export_elasticsearch', help='export stats to an ElasticSearch server (elasticsearch lib needed)') |
||
| 182 | parser.add_argument('--export-influxdb', action='store_true', default=False, |
||
| 183 | dest='export_influxdb', help='export stats to an InfluxDB server (influxdb lib needed)') |
||
| 184 | parser.add_argument('--export-kafka', action='store_true', default=False, |
||
| 185 | dest='export_kafka', help='export stats to a Kafka server (kafka-python lib needed)') |
||
| 186 | parser.add_argument('--export-opentsdb', action='store_true', default=False, |
||
| 187 | dest='export_opentsdb', help='export stats to an OpenTSDB server (potsdb lib needed)') |
||
| 188 | parser.add_argument('--export-prometheus', action='store_true', default=False, |
||
| 189 | dest='export_prometheus', help='export stats to a Prometheus exporter (prometheus_client lib needed)') |
||
| 190 | parser.add_argument('--export-rabbitmq', action='store_true', default=False, |
||
| 191 | dest='export_rabbitmq', help='export stats to rabbitmq broker (pika lib needed)') |
||
| 192 | parser.add_argument('--export-riemann', action='store_true', default=False, |
||
| 193 | dest='export_riemann', help='export stats to riemann broker (bernhard lib needed)') |
||
| 194 | parser.add_argument('--export-statsd', action='store_true', default=False, |
||
| 195 | dest='export_statsd', help='export stats to a StatsD server (statsd lib needed)') |
||
| 196 | parser.add_argument('--export-zeromq', action='store_true', default=False, |
||
| 197 | dest='export_zeromq', help='export stats to a ZeroMQ server (pyzmq lib needed)') |
||
| 198 | # Client/Server option |
||
| 199 | parser.add_argument('-c', '--client', dest='client', |
||
| 200 | help='connect to a Glances server by IPv4/IPv6 address or hostname') |
||
| 201 | parser.add_argument('-s', '--server', action='store_true', default=False, |
||
| 202 | dest='server', help='run Glances in server mode') |
||
| 203 | parser.add_argument('--browser', action='store_true', default=False, |
||
| 204 | dest='browser', help='start the client browser (list of servers)') |
||
| 205 | parser.add_argument('--disable-autodiscover', action='store_true', default=False, |
||
| 206 | dest='disable_autodiscover', help='disable autodiscover feature') |
||
| 207 | parser.add_argument('-p', '--port', default=None, type=int, dest='port', |
||
| 208 | help='define the client/server TCP port [default: {}]'.format(self.server_port)) |
||
| 209 | parser.add_argument('-B', '--bind', default='0.0.0.0', dest='bind_address', |
||
| 210 | help='bind server to the given IPv4/IPv6 address or hostname') |
||
| 211 | parser.add_argument('--username', action='store_true', default=False, dest='username_prompt', |
||
| 212 | help='define a client/server username') |
||
| 213 | parser.add_argument('--password', action='store_true', default=False, dest='password_prompt', |
||
| 214 | help='define a client/server password') |
||
| 215 | parser.add_argument('--snmp-community', default='public', dest='snmp_community', |
||
| 216 | help='SNMP community') |
||
| 217 | parser.add_argument('--snmp-port', default=161, type=int, |
||
| 218 | dest='snmp_port', help='SNMP port') |
||
| 219 | parser.add_argument('--snmp-version', default='2c', dest='snmp_version', |
||
| 220 | help='SNMP version (1, 2c or 3)') |
||
| 221 | parser.add_argument('--snmp-user', default='private', dest='snmp_user', |
||
| 222 | help='SNMP username (only for SNMPv3)') |
||
| 223 | parser.add_argument('--snmp-auth', default='password', dest='snmp_auth', |
||
| 224 | help='SNMP authentication key (only for SNMPv3)') |
||
| 225 | parser.add_argument('--snmp-force', action='store_true', default=False, |
||
| 226 | dest='snmp_force', help='force SNMP mode') |
||
| 227 | parser.add_argument('-t', '--time', default=self.refresh_time, type=float, |
||
| 228 | dest='time', help='set refresh time in seconds [default: {} sec]'.format(self.refresh_time)) |
||
| 229 | parser.add_argument('-w', '--webserver', action='store_true', default=False, |
||
| 230 | dest='webserver', help='run Glances in web server mode (bottle needed)') |
||
| 231 | parser.add_argument('--cached-time', default=self.cached_time, type=int, |
||
| 232 | dest='cached_time', help='set the server cache time [default: {} sec]'.format(self.cached_time)) |
||
| 233 | parser.add_argument('--open-web-browser', action='store_true', default=False, |
||
| 234 | dest='open_web_browser', help='try to open the Web UI in the default Web browser') |
||
| 235 | # Display options |
||
| 236 | parser.add_argument('-q', '--quiet', default=False, action='store_true', |
||
| 237 | dest='quiet', help='do not display the curses interface') |
||
| 238 | parser.add_argument('-f', '--process-filter', default=None, type=str, |
||
| 239 | dest='process_filter', help='set the process filter pattern (regular expression)') |
||
| 240 | parser.add_argument('--process-short-name', action='store_true', default=False, |
||
| 241 | dest='process_short_name', help='force short name for processes name') |
||
| 242 | if not WINDOWS: |
||
| 243 | parser.add_argument('--hide-kernel-threads', action='store_true', default=False, |
||
| 244 | dest='no_kernel_threads', help='hide kernel threads in process list') |
||
| 245 | if LINUX: |
||
| 246 | parser.add_argument('--tree', action='store_true', default=False, |
||
| 247 | dest='process_tree', help='display processes as a tree') |
||
| 248 | parser.add_argument('-b', '--byte', action='store_true', default=False, |
||
| 249 | dest='byte', help='display network rate in byte per second') |
||
| 250 | parser.add_argument('--diskio-show-ramfs', action='store_true', default=False, |
||
| 251 | dest='diskio_show_ramfs', help='show RAM Fs in the DiskIO plugin') |
||
| 252 | parser.add_argument('--diskio-iops', action='store_true', default=False, |
||
| 253 | dest='diskio_iops', help='show IO per second in the DiskIO plugin') |
||
| 254 | parser.add_argument('--fahrenheit', action='store_true', default=False, |
||
| 255 | dest='fahrenheit', help='display temperature in Fahrenheit (default is Celsius)') |
||
| 256 | parser.add_argument('--fs-free-space', action='store_true', default=False, |
||
| 257 | dest='fs_free_space', help='display FS free space instead of used') |
||
| 258 | parser.add_argument('--theme-white', action='store_true', default=False, |
||
| 259 | dest='theme_white', help='optimize display colors for white background') |
||
| 260 | # Globals options |
||
| 261 | parser.add_argument('--disable-check-update', action='store_true', default=False, |
||
| 262 | dest='disable_check_update', help='disable online Glances version ckeck') |
||
| 263 | return parser |
||
| 264 | |||
| 469 |