|
34 | 34 | import os |
35 | 35 | import sys |
36 | 36 |
|
37 | | -from configargparse import ConfigArgParse |
| 37 | +from configargparse import ArgParser |
38 | 38 | from copy import deepcopy |
39 | 39 |
|
40 | 40 | import logging |
41 | 41 | from vsc.utils import fancylogger |
42 | 42 | from vsc.utils.availability import proceed_on_ha_service |
43 | | -from vsc.utils.generaloption import SimpleOption |
44 | 43 | from vsc.utils.lock import lock_or_bork, release_or_bork, LOCKFILE_DIR, LOCKFILE_FILENAME_TEMPLATE |
45 | 44 | from vsc.utils.nagios import ( |
46 | 45 | SimpleNagios, NAGIOS_CACHE_DIR, NAGIOS_CACHE_FILENAME_TEMPLATE, exit_from_errorcode, |
|
60 | 59 | MAX_RTT = 2 * MAX_DELTA + 1 |
61 | 60 |
|
62 | 61 |
|
| 62 | + |
63 | 63 | def _script_name(full_name): |
64 | 64 | """Return the script name without .py extension if any. This assumes that the script name does not contain a |
65 | 65 | dot in case of lacking an extension. |
@@ -303,7 +303,25 @@ def _merge_options(options): |
303 | 303 | return opts |
304 | 304 |
|
305 | 305 |
|
306 | | -class ExtendedSimpleOption(SimpleOption): |
| 306 | +class ConfigOption: |
| 307 | + """ |
| 308 | + Allow using configargparse.ArgParser instead of GeneralOption but with the same |
| 309 | + options-specifying syntax |
| 310 | + """ |
| 311 | + |
| 312 | + def __init__(self, options, config_files=None): |
| 313 | + self.parser = ArgParser(auto_env_var_prefix='') |
| 314 | + |
| 315 | + if config_files: |
| 316 | + self.parser.config_file_parser(config_files) |
| 317 | + |
| 318 | + for option, (help_str, type_, action, default_value) in options.items(): |
| 319 | + self.parser.add(f'--{option}', help=help_str, type=type_, action=action, default=default_value) |
| 320 | + |
| 321 | + self.options = self.parser.parse_args() |
| 322 | + |
| 323 | + |
| 324 | +class ExtendedSimpleOption(ConfigOption): |
307 | 325 | """ |
308 | 326 | Extends the SimpleOption class to allow other checks to occur at script prologue and epilogue. |
309 | 327 |
|
@@ -427,6 +445,9 @@ def critical_exception_handler(self, tp, value, traceback): |
427 | 445 | message = f"Script failure: {tp} - {value}" |
428 | 446 | self.critical(message) |
429 | 447 |
|
| 448 | + |
| 449 | + |
| 450 | + |
430 | 451 | class CLI: |
431 | 452 | """ |
432 | 453 | Base class to implement cli tools that require timestamps, nagios checks, etc. |
|
0 commit comments