How to use the configparser.NoOptionError function in configparser

To help you get started, we’ve selected a few configparser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stb-tester / lirc / python-pkg / lirc / client.py View on Github external
if 'LIRC_SOCKET_PATH' in os.environ:
        return os.environ['LIRC_SOCKET_PATH']
    path = lirc.config.SYSCONFDIR + '/lirc/lirc_options.conf'
    parser = configparser.SafeConfigParser()
    try:
        parser.read(path)
    except configparser.Error:
        pass
    else:
        if parser.has_section('lircd'):
            try:
                path = str(parser.get('lircd', 'output'))
                if os.path.exists(path):
                    return path
            except configparser.NoOptionError:
                pass
    return lirc.config.VARRUNDIR + '/lirc/lircd'
github NVISO-BE / ee-outliers / app / analyzers / beaconing.py View on Github external
def extract_additional_model_settings(self):
        try:
            self.model_settings["process_documents_chronologically"] = settings.config.getboolean(
                self.config_section_name, "process_documents_chronologically")
        except NoOptionError:
            self.model_settings["process_documents_chronologically"] = True

        self.model_settings["target"] = settings.config.get(self.config_section_name, "target")\
            .replace(' ', '').split(",")  # remove unnecessary whitespace, split fields
        self.model_settings["aggregator"] = settings.config.get(self.config_section_name, "aggregator")\
            .replace(' ', '').split(",")  # remove unnecessary whitespace, split fields
        self.model_settings["trigger_sensitivity"] = settings.config.getfloat(self.config_section_name,
                                                                              "trigger_sensitivity")
        self.model_settings["batch_eval_size"] = settings.config.getint("beaconing", "beaconing_batch_eval_size")

        try:
            self.model_settings["min_target_buckets"] = settings.config.getint(self.config_section_name,
                                                                               "min_target_buckets")
        except NoOptionError:
            self.model_settings["min_target_buckets"] = DEFAULT_MIN_TARGET_BUCKETS
github rucio / rucio / lib / rucio / core / permission / __init__.py View on Github external
PY3K COMPATIBLE
"""

try:
    from ConfigParser import NoOptionError, NoSectionError
except ImportError:
    from configparser import NoOptionError, NoSectionError
from rucio.common import config, exception

import importlib

if config.config_has_section('permission'):
    try:
        FALLBACK_POLICY = config.config_get('permission', 'policy')
    except (NoOptionError, NoSectionError) as error:
        FALLBACK_POLICY = 'generic'
elif config.config_has_section('policy'):
    try:
        FALLBACK_POLICY = config.config_get('policy', 'permission')
    except (NoOptionError, NoSectionError) as error:
        FALLBACK_POLICY = 'generic'
else:
    FALLBACK_POLICY = 'generic'

if config.config_has_section('policy'):
    try:
        POLICY = config.config_get('policy', 'package') + ".permission"
    except (NoOptionError, NoSectionError) as error:
        # fall back to old system for now
        POLICY = 'rucio.core.permission.' + FALLBACK_POLICY.lower()
else:
github ForensicArtifacts / artifacts / utils / dependencies.py View on Github external
def _GetConfigValue(self, config_parser, section_name, value_name):
    """Retrieves a value from the config parser.

    Args:
      config_parser (ConfigParser): configuration parser.
      section_name (str): name of the section that contains the value.
      value_name (str): name of the value.

    Returns:
      object: configuration value or None if the value does not exists.
    """
    try:
      return config_parser.get(section_name, value_name)
    except configparser.NoOptionError:
      return
github QUANTAXIS / QUANTAXIS / docs / lib / QUANTAXIS / QAUtil / QASetting.py View on Github external
def get_config(self):
        config = configparser.ConfigParser()
        if os.path.exists(CONFIGFILE_PATH):
            config.read(CONFIGFILE_PATH)
            try:
                return config.get('MONGODB', 'uri')
            except configparser.NoSectionError:
                config.add_section('MONGODB')
                config.set('MONGODB', 'uri', DEFAULT_DB_URI)
                return DEFAULT_DB_URI
            except configparser.NoOptionError:
                config.set('MONGODB', 'uri', DEFAULT_DB_URI)
                return DEFAULT_DB_URI
            finally:

                with open(CONFIGFILE_PATH, 'w') as f:
                    config.write(f)

        else:
            f=open(CONFIGFILE_PATH, 'w')
            config.add_section('MONGODB')
            config.set('MONGODB', 'uri', DEFAULT_DB_URI)
            config.write(f)
            f.close()
            return DEFAULT_DB_URI
github NickleDave / vak / cnn_bilstm / train_utils / train.py View on Github external
n_max_iter = int(config['TRAIN']['n_max_iter'])
    logger.info('maximum number of training steps will be {}'
                .format(n_max_iter))

    normalize_spectrograms = config.getboolean('TRAIN', 'normalize_spectrograms')
    if normalize_spectrograms:
        logger.info('will normalize spectrograms for each training set')
        # need a copy of X_val when we normalize it below
        X_val_copy = copy.deepcopy(X_val)

    use_train_subsets_from_previous_run = config.getboolean(
        'TRAIN', 'use_train_subsets_from_previous_run')
    if use_train_subsets_from_previous_run:
        try:
            previous_run_path = config['TRAIN']['previous_run_path']
        except NoOptionError:
            raise ('In config.file {}, '
                   'use_train_subsets_from_previous_run = Yes, but'
                   'no previous_run_path option was found.\n'
                   'Please add previous_run_path to config file.'
                   .format(config_file))

    for train_set_dur in TRAIN_SET_DURS:
        for replicate in REPLICATES:
            costs = []
            val_errs = []
            curr_min_err = 1  # i.e. 100%
            err_patience_counter = 0

            logger.info("training with training set duration of {} seconds,"
                        "replicate #{}".format(train_set_dur, replicate))
            training_records_dir = ('records_for_training_set_with_duration_of_'
github rkoshak / sensorReporter / sensorreporter / gpio / rpiGPIOActuator.py View on Github external
def __init__(self, publishers, logger, params, sensors, actuators):
        """Sets the output and changes its state when it receives a command"""

        self.logger = logger

        self.pin = int(params("Pin"))

        GPIO.setmode(GPIO.BCM) # uses BCM numbering, not Board numbering
        GPIO.setup(self.pin, GPIO.OUT)
        out = GPIO.LOW
        
        try:
            out = GPIO.HIGH if params("InitialState")=="ON" else GPIO.LOW
        except configparser.NoOptionError:
            pass

        GPIO.output(self.pin, out)

        self.destination = params("Topic")
        self.connections = publishers
        self.toggle = False if params("Toggle").lower() == 'false' else True

        logger.info('----------Configuring rpiGPIOActuator: pin {0} on destination {1} with toggle {2}'.format(self.pin, self.destination, self.toggle))
        
        for connection in self.connections:
            connection.register(self.destination, self.on_message)
github koldinger / Tardis / src / Tardis / Util.py View on Github external
def loadKeys(name, client):
    config = configparser.ConfigParser({'ContentKey': None, 'FilenameKey': None}, allow_no_value=True)
    client = str(client)
    config.add_section(client)
    config.read(fullPath(name))
    try:
        contentKey =  _updateLen(config.get(client, 'ContentKey'), 32)
        nameKey    =  _updateLen(config.get(client, 'FilenameKey'), 32)
        return (nameKey, contentKey)
    except configparser.NoOptionError as e:
        raise Exception("No keys available for client " + client)
github stratosphereips / StratosphereLinuxIPS / modules / ThreatIntelligence / threat_intelligence.py View on Github external
def __read_configuration(self, section: str, name: str) -> str:
        """ Read the configuration file for what we need """
        # Get the time of log report
        try:
             conf_variable = self.config.get(section, name)
        except (configparser.NoOptionError, configparser.NoSectionError, NameError):
            # There is a conf, but there is no option, or no section or no configuration file specified
            conf_variable = None
        return conf_variable