def cascade_value(opt=None, opt_name=None, # optparse
                  env_name=None, # os.environ
                  cfg=None, cfg_section=None, cfg_name=None, # ConfigParser
                  default=None):
    """
    Allow a posix style cascading config
    """
    # get from cmd line
    value = _Unset()
    if opt and opt_name:
        try:
            value = opt.__getattr__(opt_name)
        except __HOLE__, e:
            pass
    if not isinstance(value, _Unset):
        return value

    # get from env
    if env_name:
        try:
            value = os.environ[env_name]
        except KeyError, e:
            pass
    if not isinstance(value, _Unset):
        return value

    # get from config file
    if cfg and cfg_section and cfg_name:
        try:
            value = cfg.get(cfg_section, cfg_name)
        except ConfigParser.NoOptionError, e:
            pass
    if not isinstance(value, _Unset):
        return value

    return default
dataset/ETHPy150Open mattharrison/poachplate/poachplatelib/package.py/cascade_value