Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
filecmp.dircmp Class Reference

List of all members.

Public Member Functions

def __init__
def phase0
def phase1
def phase2
def phase3
def phase4
def phase4_closure
def report
def report_partial_closure
def report_full_closure
def __getattr__

Public Attributes

 left
 right
 hide
 ignore
 left_list
 right_list
 common
 left_only
 right_only
 common_dirs
 common_files
 common_funny
 funny_files
 subdirs

Static Public Attributes

tuple methodmap

Detailed Description

A class that manages the comparison of 2 directories.

dircmp(a, b, ignore=None, hide=None)
  A and B are directories.
  IGNORE is a list of names to ignore,
    defaults to ['RCS', 'CVS', 'tags'].
  HIDE is a list of names to hide,
    defaults to [os.curdir, os.pardir].

High level usage:
  x = dircmp(dir1, dir2)
  x.report() -> prints a report on the differences between dir1 and dir2
   or
  x.report_partial_closure() -> prints report on differences between dir1
        and dir2, and reports on common immediate subdirectories.
  x.report_full_closure() -> like report_partial_closure,
        but fully recursive.

Attributes:
 left_list, right_list: The files in dir1 and dir2,
    filtered by hide and ignore.
 common: a list of names in both dir1 and dir2.
 left_only, right_only: names only in dir1, dir2.
 common_dirs: subdirectories in both dir1 and dir2.
 common_files: files in both dir1 and dir2.
 common_funny: names in both dir1 and dir2 where the type differs between
    dir1 and dir2, or the name is not stat-able.
 same_files: list of identical files.
 diff_files: list of filenames which differ.
 funny_files: list of files which could not be compared.
 subdirs: a dictionary of dircmp objects, keyed by names in common_dirs.

Definition at line 77 of file filecmp.py.


Constructor & Destructor Documentation

def filecmp.dircmp.__init__ (   self,
  a,
  b,
  ignore = None,
  hide = None 
)

Definition at line 111 of file filecmp.py.

00111 
00112     def __init__(self, a, b, ignore=None, hide=None): # Initialize
00113         self.left = a
00114         self.right = b
00115         if hide is None:
00116             self.hide = [os.curdir, os.pardir] # Names never to be shown
00117         else:
00118             self.hide = hide
00119         if ignore is None:
00120             self.ignore = ['RCS', 'CVS', 'tags'] # Names ignored in comparison
00121         else:
00122             self.ignore = ignore

Here is the caller graph for this function:


Member Function Documentation

def filecmp.dircmp.__getattr__ (   self,
  attr 
)

Definition at line 235 of file filecmp.py.

00235 
00236     def __getattr__(self, attr):
00237         if attr not in self.methodmap:
00238             raise AttributeError(attr)
00239         self.methodmap[attr](self)
00240         return getattr(self, attr)

Here is the call graph for this function:

def filecmp.dircmp.phase0 (   self)

Definition at line 123 of file filecmp.py.

00123 
00124     def phase0(self): # Compare everything except common subdirectories
00125         self.left_list = _filter(os.listdir(self.left),
00126                                  self.hide+self.ignore)
00127         self.right_list = _filter(os.listdir(self.right),
00128                                   self.hide+self.ignore)
00129         self.left_list.sort()
00130         self.right_list.sort()

def filecmp.dircmp.phase1 (   self)

Definition at line 131 of file filecmp.py.

00131 
00132     def phase1(self): # Compute common names
00133         a = dict(zip(map(os.path.normcase, self.left_list), self.left_list))
00134         b = dict(zip(map(os.path.normcase, self.right_list), self.right_list))
00135         self.common = list(map(a.__getitem__, filter(b.__contains__, a)))
00136         self.left_only = list(map(a.__getitem__, filterfalse(b.__contains__, a)))
00137         self.right_only = list(map(b.__getitem__, filterfalse(a.__contains__, b)))

def filecmp.dircmp.phase2 (   self)

Definition at line 138 of file filecmp.py.

00138 
00139     def phase2(self): # Distinguish files, directories, funnies
00140         self.common_dirs = []
00141         self.common_files = []
00142         self.common_funny = []
00143 
00144         for x in self.common:
00145             a_path = os.path.join(self.left, x)
00146             b_path = os.path.join(self.right, x)
00147 
00148             ok = 1
00149             try:
00150                 a_stat = os.stat(a_path)
00151             except os.error as why:
00152                 # print('Can\'t stat', a_path, ':', why.args[1])
00153                 ok = 0
00154             try:
00155                 b_stat = os.stat(b_path)
00156             except os.error as why:
00157                 # print('Can\'t stat', b_path, ':', why.args[1])
00158                 ok = 0
00159 
00160             if ok:
00161                 a_type = stat.S_IFMT(a_stat.st_mode)
00162                 b_type = stat.S_IFMT(b_stat.st_mode)
00163                 if a_type != b_type:
00164                     self.common_funny.append(x)
00165                 elif stat.S_ISDIR(a_type):
00166                     self.common_dirs.append(x)
00167                 elif stat.S_ISREG(a_type):
00168                     self.common_files.append(x)
00169                 else:
00170                     self.common_funny.append(x)
00171             else:
00172                 self.common_funny.append(x)

def filecmp.dircmp.phase3 (   self)

Definition at line 173 of file filecmp.py.

00173 
00174     def phase3(self): # Find out differences between common files
00175         xx = cmpfiles(self.left, self.right, self.common_files)
00176         self.same_files, self.diff_files, self.funny_files = xx

Here is the call graph for this function:

def filecmp.dircmp.phase4 (   self)

Definition at line 177 of file filecmp.py.

00177 
00178     def phase4(self): # Find out differences between common subdirectories
00179         # A new dircmp object is created for each common subdirectory,
00180         # these are stored in a dictionary indexed by filename.
00181         # The hide and ignore properties are inherited from the parent
00182         self.subdirs = {}
00183         for x in self.common_dirs:
00184             a_x = os.path.join(self.left, x)
00185             b_x = os.path.join(self.right, x)
00186             self.subdirs[x]  = dircmp(a_x, b_x, self.ignore, self.hide)

Here is the caller graph for this function:

Definition at line 187 of file filecmp.py.

00187 
00188     def phase4_closure(self): # Recursively call phase4() on subdirectories
00189         self.phase4()
00190         for sd in self.subdirs.values():
00191             sd.phase4_closure()

Here is the call graph for this function:

def filecmp.dircmp.report (   self)

Definition at line 192 of file filecmp.py.

00192 
00193     def report(self): # Print a report on the differences between a and b
00194         # Output format is purposely lousy
00195         print('diff', self.left, self.right)
00196         if self.left_only:
00197             self.left_only.sort()
00198             print('Only in', self.left, ':', self.left_only)
00199         if self.right_only:
00200             self.right_only.sort()
00201             print('Only in', self.right, ':', self.right_only)
00202         if self.same_files:
00203             self.same_files.sort()
00204             print('Identical files :', self.same_files)
00205         if self.diff_files:
00206             self.diff_files.sort()
00207             print('Differing files :', self.diff_files)
00208         if self.funny_files:
00209             self.funny_files.sort()
00210             print('Trouble with common files :', self.funny_files)
00211         if self.common_dirs:
00212             self.common_dirs.sort()
00213             print('Common subdirectories :', self.common_dirs)
00214         if self.common_funny:
00215             self.common_funny.sort()
00216             print('Common funny cases :', self.common_funny)

Here is the caller graph for this function:

Definition at line 223 of file filecmp.py.

00223 
00224     def report_full_closure(self): # Report on self and subdirs recursively
00225         self.report()
00226         for sd in self.subdirs.values():
00227             print()
00228             sd.report_full_closure()

Here is the call graph for this function:

Definition at line 217 of file filecmp.py.

00217 
00218     def report_partial_closure(self): # Print reports on self and on subdirs
00219         self.report()
00220         for sd in self.subdirs.values():
00221             print()
00222             sd.report()

Here is the call graph for this function:


Member Data Documentation

Definition at line 134 of file filecmp.py.

Definition at line 139 of file filecmp.py.

Definition at line 140 of file filecmp.py.

Definition at line 141 of file filecmp.py.

Definition at line 175 of file filecmp.py.

Definition at line 115 of file filecmp.py.

Definition at line 119 of file filecmp.py.

Definition at line 112 of file filecmp.py.

Definition at line 124 of file filecmp.py.

Definition at line 135 of file filecmp.py.

tuple filecmp.dircmp.methodmap [static]
Initial value:
dict(subdirs=phase4,
                     same_files=phase3, diff_files=phase3, funny_files=phase3,
                     common_dirs = phase2, common_files=phase2, common_funny=phase2,
                     common=phase1, left_only=phase1, right_only=phase1,
                     left_list=phase0, right_list=phase0)

Definition at line 229 of file filecmp.py.

Definition at line 113 of file filecmp.py.

Definition at line 126 of file filecmp.py.

Definition at line 136 of file filecmp.py.

Definition at line 181 of file filecmp.py.


The documentation for this class was generated from the following file: