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
评论列表
文章目录