def check_include_exclude(path_str, include_pat=None, exclude_pat=None):
    '''
    Check for glob or regexp patterns for include_pat and exclude_pat in the
    'path_str' string and return True/False conditions as follows.
      - Default: return 'True' if no include_pat or exclude_pat patterns are
        supplied
      - If only include_pat or exclude_pat is supplied: return 'True' if string
        passes the include_pat test or fails exclude_pat test respectively
      - If both include_pat and exclude_pat are supplied: return 'True' if
        include_pat matches AND exclude_pat does not match
    '''
    def _pat_check(path_str, check_pat):
        if re.match('E@', check_pat):
            return True if re.search(
                check_pat[2:],
                path_str
            ) else False
        else:
            return True if fnmatch.fnmatch(
                path_str,
                check_pat
            ) else False

    ret = True  # -- default true
    # Before pattern match, check if it is regexp (E@'') or glob(default)
    if include_pat:
        if isinstance(include_pat, list):
            for include_line in include_pat:
                retchk_include = _pat_check(path_str, include_line)
                if retchk_include:
                    break
        else:
            retchk_include = _pat_check(path_str, include_pat)

    if exclude_pat:
        if isinstance(exclude_pat, list):
            for exclude_line in exclude_pat:
                retchk_exclude = not _pat_check(path_str, exclude_line)
                if not retchk_exclude:
                    break
        else:
            retchk_exclude = not _pat_check(path_str, exclude_pat)

    # Now apply include/exclude conditions
    if include_pat and not exclude_pat:
        ret = retchk_include
    elif exclude_pat and not include_pat:
        ret = retchk_exclude
    elif include_pat and exclude_pat:
        ret = retchk_include and retchk_exclude
    else:
        ret = True

    return ret
def check_include_exclude ( path_str , include_pat = None , exclude_pat = None ) : def _pat_check ( path_str , check_pat ) : if re . match ( 'E@' , check_pat ) : return True if re . search ( check_pat [ 2 : ] , path_str ) else False else : return True if fnmatch . fnmatch ( path_str , check_pat ) else False ret = True if include_pat : if isinstance ( include_pat , list ) : for include_line in include_pat : retchk_include = _pat_check ( path_str , include_line ) if retchk_include : break else : retchk_include = _pat_check ( path_str , include_pat ) if exclude_pat : if isinstance ( exclude_pat , list ) : for exclude_line in exclude_pat : retchk_exclude = not _pat_check ( path_str , exclude_line ) if not retchk_exclude : break else : retchk_exclude = not _pat_check ( path_str , exclude_pat ) if include_pat and not exclude_pat : ret = retchk_include elif exclude_pat and not include_pat : ret = retchk_exclude elif include_pat and exclude_pat : ret = retchk_include and retchk_exclude else : ret = True return ret
Check for glob or regexp patterns for include_pat and exclude_pat in the
    'path_str' string and return True/False conditions as follows.
      - Default: return 'True' if no include_pat or exclude_pat patterns are
        supplied
      - If only include_pat or exclude_pat is supplied: return 'True' if string
        passes the include_pat test or fails exclude_pat test respectively
      - If both include_pat and exclude_pat are supplied: return 'True' if
        include_pat matches AND exclude_pat does not match