Parse a boolean environment variable.

def parse_boolean_envvar(val):
    """Parse a boolean environment variable."""
    if not val or val.lower() in {'false', '0'}:
        return False
    elif val.lower() in {'true', '1'}:
        return True
    else:
        raise ValueError('Invalid boolean environment variable: %s' % val)