pyrocopy.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:pyrocopy 作者: caskater4 项目源码 文件源码
def _normalizeFilePattern(pattern, filepath):
    bIsRegex = False
    tmpPattern = pattern
    if (isinstance(pattern, re._pattern_type)):
        tmpPattern = pattern.pattern
        bIsRegex = True
    elif (pattern.startswith('re:')):
        tmpPattern = pattern[3:]
        bIsRegex = True

    # Separate the file pattern from the dir/path pattern
    patternParts = os.path.split(tmpPattern)
    tmpPattern = patternParts[0]

    numPathSep = filepath.count(os.path.sep)
    numPatternSep = tmpPattern.count(os.path.sep)
    if (tmpPattern != ''):
        numPatternSep = numPatternSep + 1

    # When the path has more levels, fill in the pattern with wildcards
    if (numPathSep > numPatternSep):
        while (numPathSep > numPatternSep):
            if (bIsRegex):
                if (tmpPattern != ''):
                    tmpPattern = tmpPattern + "/.*"
                else:
                    tmpPattern = '.*'
            else:
                tmpPattern = os.path.join(tmpPattern, "*")
            numPatternSep = numPatternSep + 1

    # Append the file pattern back
    if (bIsRegex):
        tmpPattern = tmpPattern + "/" + patternParts[1]
    else:
        tmpPattern = os.path.join(tmpPattern, patternParts[1])

    if (bIsRegex):
        return re.compile(tmpPattern)
    else:
        return tmpPattern
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号