analyser.py 文件源码

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

项目:wp-file-analyser 作者: racwn 项目源码 文件源码
def analyze(dcres, wpPath):
    """Get extra, changed and missing files from a dircmp results object.

    From dircmp results find:
        1. Any files that differ.
        2. Extra files in left that are not in right.
        3. Missing files that are in right but not in left.
    Recursively enter sub directories to continue search.

    When searching for extra files, certain files and directories that are
    user modifiable should be ignored. For example, 'wp-content/themes' will
    likely contain unique files that will not appear in a new copy of the
    same WordPress version. These should be ignored to avoid giving false
    positives.
    """

    diff = set()
    extra = set()
    missing = set()

    # 1. Get modified files
    [diff.add(os.path.join(dcres.left, f)) for f in dcres.diff_files]

    # 2. Get extra files
    for name in dcres.left_only:
        path = os.path.join(dcres.left, name)
        if not ignored_file(path, wpPath):  # ignore user modified
            if not os.path.isdir(path):  # do not add directories
                extra.add(path)

    # 3. Get missing files
    [missing.add(os.path.join(dcres.right, f)) for f in dcres.right_only]

    # Recurse into each sub dir
    for sub_dcres in dcres.subdirs.values():
        newDiff, newExtra, newMissing = analyze(sub_dcres, wpPath)
        diff = diff.union(newDiff)
        extra = extra.union(newExtra)
        missing = missing.union(newMissing)

    return diff, extra, missing
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号