summaryrefslogtreecommitdiffstats
path: root/Lib/filecmp.py
diff options
context:
space:
mode:
authorTobias Rautenkranz <github@tobias.rautenkranz.ch>2024-03-04 17:27:43 (GMT)
committerGitHub <noreply@github.com>2024-03-04 17:27:43 (GMT)
commit60743a9a7ee3c3c16a61ff6715e8d170237b5458 (patch)
treedc0a9d6951338c5951f3740c2bf796f002c7997f /Lib/filecmp.py
parentea1b1c579f600cc85d145c60862b2e6b98701b24 (diff)
downloadcpython-60743a9a7ee3c3c16a61ff6715e8d170237b5458.zip
cpython-60743a9a7ee3c3c16a61ff6715e8d170237b5458.tar.gz
cpython-60743a9a7ee3c3c16a61ff6715e8d170237b5458.tar.bz2
gh-57141: Add dircmp shallow option (GH-109499)
Co-authored-by: Steve Ward <planet36@gmail.com> Co-authored-by: Sanyam Khurana <8039608+CuriousLearner@users.noreply.github.com>
Diffstat (limited to 'Lib/filecmp.py')
-rw-r--r--Lib/filecmp.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/Lib/filecmp.py b/Lib/filecmp.py
index 30bd900..6ffc71f 100644
--- a/Lib/filecmp.py
+++ b/Lib/filecmp.py
@@ -88,12 +88,15 @@ def _do_cmp(f1, f2):
class dircmp:
"""A class that manages the comparison of 2 directories.
- dircmp(a, b, ignore=None, hide=None)
+ dircmp(a, b, ignore=None, hide=None, shallow=True)
A and B are directories.
IGNORE is a list of names to ignore,
defaults to DEFAULT_IGNORES.
HIDE is a list of names to hide,
defaults to [os.curdir, os.pardir].
+ SHALLOW specifies whether to just check the stat signature (do not read
+ the files).
+ defaults to True.
High level usage:
x = dircmp(dir1, dir2)
@@ -121,7 +124,7 @@ class dircmp:
in common_dirs.
"""
- def __init__(self, a, b, ignore=None, hide=None): # Initialize
+ def __init__(self, a, b, ignore=None, hide=None, shallow=True): # Initialize
self.left = a
self.right = b
if hide is None:
@@ -132,6 +135,7 @@ class dircmp:
self.ignore = DEFAULT_IGNORES
else:
self.ignore = ignore
+ self.shallow = shallow
def phase0(self): # Compare everything except common subdirectories
self.left_list = _filter(os.listdir(self.left),
@@ -184,7 +188,7 @@ class dircmp:
self.common_funny.append(x)
def phase3(self): # Find out differences between common files
- xx = cmpfiles(self.left, self.right, self.common_files)
+ xx = cmpfiles(self.left, self.right, self.common_files, self.shallow)
self.same_files, self.diff_files, self.funny_files = xx
def phase4(self): # Find out differences between common subdirectories
@@ -196,7 +200,8 @@ class dircmp:
for x in self.common_dirs:
a_x = os.path.join(self.left, x)
b_x = os.path.join(self.right, x)
- self.subdirs[x] = self.__class__(a_x, b_x, self.ignore, self.hide)
+ self.subdirs[x] = self.__class__(a_x, b_x, self.ignore, self.hide,
+ self.shallow)
def phase4_closure(self): # Recursively call phase4() on subdirectories
self.phase4()