/usr/lib/python2.7/dist-packages/arcnagios/confargparse.py is in nordugrid-arc-nagios-plugins 1.9.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | import argparse, ConfigParser
class UsageOrConfigError(Exception):
pass
class UsageError(Exception):
pass
class ConfigError(Exception):
def __init__(self, config_file, config_section, msg):
Exception.__init__(self,
'In %s, section %s or DEFAULT: %s'
% (config_file, config_section, msg))
self.config_file = config_file
self.config_section = config_section
class ConfigArgumentParser(argparse.ArgumentParser):
def error(self, message):
raise UsageError(message)
def configure_defaults(self, config, defaults_section):
"""Merge those configurations files in the list `config_paths` which
exist and return the corresponding `ConfigParser` object. Later files
take presedence over former. Variables from `defaults_section` will be
used as defaults for the argument parser options."""
if not isinstance(defaults_section, list):
defaults_section = [defaults_section]
for section in defaults_section:
if config.has_section(section):
defaults = [(var, config.get(section, var))
for var in config.options(section)]
self.set_defaults(**dict(defaults))
break
# TODO: Validation can be refined. Ideally we should check each config
# variable individually and report a) the variable name rather than
# the option name and b) the line number of the bad value.
try:
self.parse_args()
except argparse.ArgumentTypeError, err:
raise ConfigError(
'The configuration corresponding to a command-line '
'option failed: %s' % err)
|