def env_str_to_bool(varname, val):
    """Convert the boolean environment value string `val` to a Python bool
    on behalf of environment variable `varname`.
    """
    if val in ["False", "false", "FALSE", "F", "f", "0", False, 0]:
        rval = False
    elif val in ["True", "true", "TRUE", "T", "t", "1", True, 1]:
        rval = True
    else:
        raise ValueError("Invalid value " +  repr(val) + 
                         " for boolean env var " + repr(varname))
    return rval