|
34 | 34 | import os |
35 | 35 | import sys |
36 | 36 |
|
| 37 | +from configargparse import ConfigArgParser |
37 | 38 | from copy import deepcopy |
38 | 39 |
|
39 | 40 | import logging |
40 | 41 | from vsc.utils import fancylogger |
41 | 42 | from vsc.utils.availability import proceed_on_ha_service |
42 | | -from vsc.utils.generaloption import SimpleOption |
| 43 | +from vsc.utils.generaloption import SimpleOption as GOSimpleOption |
43 | 44 | from vsc.utils.lock import lock_or_bork, release_or_bork, LOCKFILE_DIR, LOCKFILE_FILENAME_TEMPLATE |
44 | 45 | from vsc.utils.nagios import ( |
45 | 46 | SimpleNagios, NAGIOS_CACHE_DIR, NAGIOS_CACHE_FILENAME_TEMPLATE, exit_from_errorcode, |
|
58 | 59 | MAX_RTT = 2 * MAX_DELTA + 1 |
59 | 60 |
|
60 | 61 |
|
| 62 | + |
61 | 63 | def _script_name(full_name): |
62 | 64 | """Return the script name without .py extension if any. This assumes that the script name does not contain a |
63 | 65 | dot in case of lacking an extension. |
@@ -102,7 +104,26 @@ def _merge_options(options): |
102 | 104 | return opts |
103 | 105 |
|
104 | 106 |
|
105 | | -class ExtendedSimpleOption(SimpleOption): |
| 107 | +class ConfigOption: |
| 108 | + """ |
| 109 | + Allow using ConfigArgParser instead of GeneralOption but with the same |
| 110 | + options-specifying syntax |
| 111 | + """ |
| 112 | + |
| 113 | + def __init__(self, options, config_files=None): |
| 114 | + self.parser = ConfigArgParser(auto_env_var_prefix='') |
| 115 | + |
| 116 | + if config_files: |
| 117 | + self.parser.config_file_parser(config_files) |
| 118 | + |
| 119 | + for option, (help_str, type_, action, default_value) in options.items(): |
| 120 | + self.parser.add_argument(f'--{option}', help=help_str, type=type_, action=action, default=default_value) |
| 121 | + |
| 122 | + self.options = self.parser.parse_args() |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | +class ExtendedSimpleOption(ConfigOption): |
106 | 127 | """ |
107 | 128 | Extends the SimpleOption class to allow other checks to occur at script prologue and epilogue. |
108 | 129 |
|
@@ -227,6 +248,8 @@ def critical_exception_handler(self, tp, value, traceback): |
227 | 248 | self.critical(message) |
228 | 249 |
|
229 | 250 |
|
| 251 | + |
| 252 | + |
230 | 253 | class CLI: |
231 | 254 | """ |
232 | 255 | Base class to implement cli tools that require timestamps, nagios checks, etc. |
|
0 commit comments