Conditions | 2 |
Total Lines | 145 |
Code Lines | 138 |
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 -*- |
||
113 | def init_args(self): |
||
114 | """Init all the command line arguments.""" |
||
115 | version = "Glances v" + __version__ + " with psutil v" + psutil_version |
||
116 | parser = argparse.ArgumentParser( |
||
117 | prog='glances', |
||
118 | conflict_handler='resolve', |
||
119 | formatter_class=argparse.RawDescriptionHelpFormatter, |
||
120 | epilog=self.example_of_use) |
||
121 | parser.add_argument( |
||
122 | '-V', '--version', action='version', version=version) |
||
123 | parser.add_argument('-d', '--debug', action='store_true', default=False, |
||
124 | dest='debug', help='enable debug mode') |
||
125 | parser.add_argument('-C', '--config', dest='conf_file', |
||
126 | help='path to the configuration file') |
||
127 | # Disable plugin |
||
128 | parser.add_argument('--modules-list', '--module-list', |
||
129 | action='store_true', default=False, |
||
130 | dest='modules_list', |
||
131 | help='display modules (plugins & exports) list and exit') |
||
132 | parser.add_argument('--disable-plugin', '--disable-plugins', dest='disable_plugin', |
||
133 | help='disable plugin (comma separed list)') |
||
134 | parser.add_argument('--enable-plugin', '--enable-plugins', dest='enable_plugin', |
||
135 | help='enable plugin (comma separed list)') |
||
136 | parser.add_argument('--disable-process', action='store_true', default=False, |
||
137 | dest='disable_process', help='disable process module') |
||
138 | # Enable or disable option |
||
139 | parser.add_argument('--disable-webui', action='store_true', default=False, |
||
140 | dest='disable_webui', help='disable the Web Interface') |
||
141 | parser.add_argument('--light', '--enable-light', action='store_true', |
||
142 | default=False, dest='enable_light', |
||
143 | help='light mode for Curses UI (disable all but top menu)') |
||
144 | parser.add_argument('-0', '--disable-irix', action='store_true', default=False, |
||
145 | dest='disable_irix', help='task\'s cpu usage will be divided by the total number of CPUs') |
||
146 | parser.add_argument('-1', '--percpu', action='store_true', default=False, |
||
147 | dest='percpu', help='start Glances in per CPU mode') |
||
148 | parser.add_argument('-2', '--disable-left-sidebar', action='store_true', |
||
149 | default=False, dest='disable_left_sidebar', |
||
150 | help='disable network, disk I/O, FS and sensors modules') |
||
151 | parser.add_argument('-3', '--disable-quicklook', action='store_true', default=False, |
||
152 | dest='disable_quicklook', help='disable quick look module') |
||
153 | parser.add_argument('-4', '--full-quicklook', action='store_true', default=False, |
||
154 | dest='full_quicklook', help='disable all but quick look and load') |
||
155 | parser.add_argument('-5', '--disable-top', action='store_true', |
||
156 | default=False, dest='disable_top', |
||
157 | help='disable top menu (QL, CPU, MEM, SWAP and LOAD)') |
||
158 | parser.add_argument('-6', '--meangpu', action='store_true', default=False, |
||
159 | dest='meangpu', help='start Glances in mean GPU mode') |
||
160 | parser.add_argument('--disable-history', action='store_true', default=False, |
||
161 | dest='disable_history', help='disable stats history') |
||
162 | parser.add_argument('--disable-bold', action='store_true', default=False, |
||
163 | dest='disable_bold', help='disable bold mode in the terminal') |
||
164 | parser.add_argument('--disable-bg', action='store_true', default=False, |
||
165 | dest='disable_bg', help='disable background colors in the terminal') |
||
166 | parser.add_argument('--enable-irq', action='store_true', default=False, |
||
167 | dest='enable_irq', help='enable IRQ module'), |
||
168 | parser.add_argument('--enable-process-extended', action='store_true', default=False, |
||
169 | dest='enable_process_extended', help='enable extended stats on top process') |
||
170 | # Export modules feature |
||
171 | parser.add_argument('--export', dest='export', |
||
172 | help='enable export module (comma separed list)') |
||
173 | parser.add_argument('--export-csv-file', |
||
174 | default='./glances.csv', |
||
175 | dest='export_csv_file', |
||
176 | help='file path for CSV exporter') |
||
177 | parser.add_argument('--export-csv-overwrite', action='store_true', default=False, |
||
178 | dest='export_csv_overwrite', help='overwrite existing CSV file') |
||
179 | parser.add_argument('--export-json-file', |
||
180 | default='./glances.json', |
||
181 | dest='export_json_file', |
||
182 | help='file path for JSON exporter') |
||
183 | parser.add_argument('--export-graph-path', |
||
184 | default=tempfile.gettempdir(), |
||
185 | dest='export_graph_path', |
||
186 | help='Folder for Graph exporter') |
||
187 | # Client/Server option |
||
188 | parser.add_argument('-c', '--client', dest='client', |
||
189 | help='connect to a Glances server by IPv4/IPv6 address or hostname') |
||
190 | parser.add_argument('-s', '--server', action='store_true', default=False, |
||
191 | dest='server', help='run Glances in server mode') |
||
192 | parser.add_argument('--browser', action='store_true', default=False, |
||
193 | dest='browser', help='start the client browser (list of servers)') |
||
194 | parser.add_argument('--disable-autodiscover', action='store_true', default=False, |
||
195 | dest='disable_autodiscover', help='disable autodiscover feature') |
||
196 | parser.add_argument('-p', '--port', default=None, type=int, dest='port', |
||
197 | help='define the client/server TCP port [default: {}]'.format(self.server_port)) |
||
198 | parser.add_argument('-B', '--bind', default='0.0.0.0', dest='bind_address', |
||
199 | help='bind server to the given IPv4/IPv6 address or hostname') |
||
200 | parser.add_argument('--username', action='store_true', default=False, dest='username_prompt', |
||
201 | help='define a client/server username') |
||
202 | parser.add_argument('--password', action='store_true', default=False, dest='password_prompt', |
||
203 | help='define a client/server password') |
||
204 | parser.add_argument('-u', dest='username_used', |
||
205 | help='use the given client/server username') |
||
206 | parser.add_argument('--snmp-community', default='public', dest='snmp_community', |
||
207 | help='SNMP community') |
||
208 | parser.add_argument('--snmp-port', default=161, type=int, |
||
209 | dest='snmp_port', help='SNMP port') |
||
210 | parser.add_argument('--snmp-version', default='2c', dest='snmp_version', |
||
211 | help='SNMP version (1, 2c or 3)') |
||
212 | parser.add_argument('--snmp-user', default='private', dest='snmp_user', |
||
213 | help='SNMP username (only for SNMPv3)') |
||
214 | parser.add_argument('--snmp-auth', default='password', dest='snmp_auth', |
||
215 | help='SNMP authentication key (only for SNMPv3)') |
||
216 | parser.add_argument('--snmp-force', action='store_true', default=False, |
||
217 | dest='snmp_force', help='force SNMP mode') |
||
218 | parser.add_argument('-t', '--time', default=self.refresh_time, type=float, |
||
219 | dest='time', help='set refresh time in seconds [default: {} sec]'.format(self.refresh_time)) |
||
220 | parser.add_argument('-w', '--webserver', action='store_true', default=False, |
||
221 | dest='webserver', help='run Glances in web server mode (bottle needed)') |
||
222 | parser.add_argument('--cached-time', default=self.cached_time, type=int, |
||
223 | dest='cached_time', help='set the server cache time [default: {} sec]'.format(self.cached_time)) |
||
224 | parser.add_argument('--open-web-browser', action='store_true', default=False, |
||
225 | dest='open_web_browser', help='try to open the Web UI in the default Web browser') |
||
226 | # Display options |
||
227 | parser.add_argument('-q', '--quiet', default=False, action='store_true', |
||
228 | dest='quiet', help='do not display the curses interface') |
||
229 | parser.add_argument('-f', '--process-filter', default=None, type=str, |
||
230 | dest='process_filter', help='set the process filter pattern (regular expression)') |
||
231 | parser.add_argument('--process-short-name', action='store_true', default=False, |
||
232 | dest='process_short_name', help='force short name for processes name') |
||
233 | parser.add_argument('--stdout', default=None, |
||
234 | dest='stdout', help='display stats to stdout, one stat per line (comma separated list of plugins/plugins.attribute)') |
||
235 | parser.add_argument('--stdout-csv', default=None, |
||
236 | dest='stdout_csv', help='display stats to stdout, csv format (comma separated list of plugins/plugins.attribute)') |
||
237 | if not WINDOWS: |
||
238 | parser.add_argument('--hide-kernel-threads', action='store_true', default=False, |
||
239 | dest='no_kernel_threads', help='hide kernel threads in process list (not available on Windows)') |
||
240 | parser.add_argument('-b', '--byte', action='store_true', default=False, |
||
241 | dest='byte', help='display network rate in byte per second') |
||
242 | parser.add_argument('--diskio-show-ramfs', action='store_true', default=False, |
||
243 | dest='diskio_show_ramfs', help='show RAM Fs in the DiskIO plugin') |
||
244 | parser.add_argument('--diskio-iops', action='store_true', default=False, |
||
245 | dest='diskio_iops', help='show IO per second in the DiskIO plugin') |
||
246 | parser.add_argument('--fahrenheit', action='store_true', default=False, |
||
247 | dest='fahrenheit', help='display temperature in Fahrenheit (default is Celsius)') |
||
248 | parser.add_argument('--fs-free-space', action='store_true', default=False, |
||
249 | dest='fs_free_space', help='display FS free space instead of used') |
||
250 | parser.add_argument('--sparkline', action='store_true', default=False, |
||
251 | dest='sparkline', help='display sparklines instead of bar in the curses interface') |
||
252 | parser.add_argument('--theme-white', action='store_true', default=False, |
||
253 | dest='theme_white', help='optimize display colors for white background') |
||
254 | # Globals options |
||
255 | parser.add_argument('--disable-check-update', action='store_true', default=False, |
||
256 | dest='disable_check_update', help='disable online Glances version ckeck') |
||
257 | return parser |
||
258 | |||
477 |