Skip to content

Commit c61a7a9

Browse files
committed
Merge branch 'configargparse' into split-nrpe-convenience-methods
2 parents 5424543 + d8fa8b7 commit c61a7a9

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lib/vsc/utils/script_tools.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@
3434
import os
3535
import sys
3636

37-
from configargparse import ConfigArgParse
37+
from configargparse import ArgParser
3838
from copy import deepcopy
3939

4040
import logging
4141
from vsc.utils import fancylogger
4242
from vsc.utils.availability import proceed_on_ha_service
43-
from vsc.utils.generaloption import SimpleOption
4443
from vsc.utils.lock import lock_or_bork, release_or_bork, LOCKFILE_DIR, LOCKFILE_FILENAME_TEMPLATE
4544
from vsc.utils.nagios import (
4645
SimpleNagios, NAGIOS_CACHE_DIR, NAGIOS_CACHE_FILENAME_TEMPLATE, exit_from_errorcode,
@@ -60,6 +59,7 @@
6059
MAX_RTT = 2 * MAX_DELTA + 1
6160

6261

62+
6363
def _script_name(full_name):
6464
"""Return the script name without .py extension if any. This assumes that the script name does not contain a
6565
dot in case of lacking an extension.
@@ -303,7 +303,25 @@ def _merge_options(options):
303303
return opts
304304

305305

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):
307325
"""
308326
Extends the SimpleOption class to allow other checks to occur at script prologue and epilogue.
309327
@@ -427,6 +445,9 @@ def critical_exception_handler(self, tp, value, traceback):
427445
message = f"Script failure: {tp} - {value}"
428446
self.critical(message)
429447

448+
449+
450+
430451
class CLI:
431452
"""
432453
Base class to implement cli tools that require timestamps, nagios checks, etc.

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@
3838
'lockfile >= 0.9.1',
3939
'netifaces',
4040
'jsonpickle',
41+
'configargparse',
4142
]
4243

4344
PACKAGE = {
44-
'version': '2.2.8',
45+
'version': '2.3.0',
4546
'author': [ag, sdw],
4647
'maintainer': [ag, sdw],
4748
'excluded_pkgs_rpm': ['vsc', 'vsc.utils'], # vsc is default, vsc.utils is provided by vsc-base

0 commit comments

Comments
 (0)