Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
dircmp Class Reference

Public Member Functions

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

Data Fields

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

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 85 of file filecmp.py.

Constructor & Destructor Documentation

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

Definition at line 119 of file filecmp.py.

120  def __init__(self, a, b, ignore=None, hide=None): # Initialize
121  self.left = a
122  self.right = b
123  if hide is None:
124  self.hide = [os.curdir, os.pardir] # Names never to be shown
125  else:
126  self.hide = hide
127  if ignore is None:
128  self.ignore = ['RCS', 'CVS', 'tags'] # Names ignored in comparison
129  else:
130  self.ignore = ignore

Member Function Documentation

def __getattr__ (   self,
  attr 
)

Definition at line 145 of file filecmp.py.

References dircmp.__p0_attrs, dircmp.__p1_attrs, dircmp.__p2_attrs, dircmp.__p3_attrs, dircmp.__p4_attrs, dircmp.phase0(), dircmp.phase1(), dircmp.phase2(), dircmp.phase3(), and dircmp.phase4().

146  def __getattr__(self, attr):
147  if attr in self.__p4_attrs:
148  self.phase4()
149  elif attr in self.__p3_attrs:
150  self.phase3()
151  elif attr in self.__p2_attrs:
152  self.phase2()
153  elif attr in self.__p1_attrs:
154  self.phase1()
155  elif attr in self.__p0_attrs:
156  self.phase0()
157  else:
158  raise AttributeError, attr
159  return getattr(self, attr)
def phase0 (   self)

Definition at line 131 of file filecmp.py.

132  def phase0(self): # Compare everything except common subdirectories
133  self.left_list = _filter(os.listdir(self.left),
134  self.hide+self.ignore)
135  self.right_list = _filter(os.listdir(self.right),
136  self.hide+self.ignore)
137  self.left_list.sort()
138  self.right_list.sort()
def phase1 (   self)

Definition at line 160 of file filecmp.py.

References dircmp.left_list, and dircmp.right_list.

161  def phase1(self): # Compute common names
162  a_only, b_only = [], []
163  common = {}
164  b = {}
165  for fnm in self.right_list:
166  b[fnm] = 1
167  for x in self.left_list:
168  if b.get(x, 0):
169  common[x] = 1
170  else:
171  a_only.append(x)
172  for x in self.right_list:
173  if common.get(x, 0):
174  pass
175  else:
176  b_only.append(x)
177  self.common = common.keys()
178  self.left_only = a_only
179  self.right_only = b_only
def phase2 (   self)

Definition at line 180 of file filecmp.py.

181  def phase2(self): # Distinguish files, directories, funnies
182  self.common_dirs = []
183  self.common_files = []
184  self.common_funny = []
185 
186  for x in self.common:
187  a_path = os.path.join(self.left, x)
188  b_path = os.path.join(self.right, x)
189 
190  ok = 1
191  try:
192  a_stat = statcache.stat(a_path)
193  except os.error, why:
194  # print 'Can\'t stat', a_path, ':', why[1]
195  ok = 0
196  try:
197  b_stat = statcache.stat(b_path)
198  except os.error, why:
199  # print 'Can\'t stat', b_path, ':', why[1]
200  ok = 0
201 
202  if ok:
203  a_type = stat.S_IFMT(a_stat[stat.ST_MODE])
204  b_type = stat.S_IFMT(b_stat[stat.ST_MODE])
205  if a_type != b_type:
206  self.common_funny.append(x)
207  elif stat.S_ISDIR(a_type):
208  self.common_dirs.append(x)
209  elif stat.S_ISREG(a_type):
210  self.common_files.append(x)
211  else:
212  self.common_funny.append(x)
213  else:
214  self.common_funny.append(x)
def phase3 (   self)

Definition at line 215 of file filecmp.py.

References filecmp.cmpfiles(), dircmp.common_files, dircmp.left, and dircmp.right.

216  def phase3(self): # Find out differences between common files
217  xx = cmpfiles(self.left, self.right, self.common_files)
218  self.same_files, self.diff_files, self.funny_files = xx
def phase4 (   self)

Definition at line 219 of file filecmp.py.

220  def phase4(self): # Find out differences between common subdirectories
221  # A new dircmp object is created for each common subdirectory,
222  # these are stored in a dictionary indexed by filename.
223  # The hide and ignore properties are inherited from the parent
224  self.subdirs = {}
225  for x in self.common_dirs:
226  a_x = os.path.join(self.left, x)
227  b_x = os.path.join(self.right, x)
228  self.subdirs[x] = dircmp(a_x, b_x, self.ignore, self.hide)
def phase4_closure (   self)

Definition at line 229 of file filecmp.py.

References dircmp.phase4(), and dircmp.subdirs.

230  def phase4_closure(self): # Recursively call phase4() on subdirectories
231  self.phase4()
232  for x in self.subdirs.keys():
233  self.subdirs[x].phase4_closure()
def report (   self)

Definition at line 234 of file filecmp.py.

References dircmp.common_dirs, dircmp.common_funny, dircmp.funny_files, dircmp.left, dircmp.left_only, dircmp.right, and dircmp.right_only.

235  def report(self): # Print a report on the differences between a and b
236  # Output format is purposely lousy
237  print 'diff', self.left, self.right
238  if self.left_only:
239  self.left_only.sort()
240  print 'Only in', self.left, ':', self.left_only
241  if self.right_only:
242  self.right_only.sort()
243  print 'Only in', self.right, ':', self.right_only
244  if self.same_files:
245  self.same_files.sort()
246  print 'Identical files :', self.same_files
247  if self.diff_files:
248  self.diff_files.sort()
249  print 'Differing files :', self.diff_files
250  if self.funny_files:
251  self.funny_files.sort()
252  print 'Trouble with common files :', self.funny_files
253  if self.common_dirs:
254  self.common_dirs.sort()
255  print 'Common subdirectories :', self.common_dirs
256  if self.common_funny:
257  self.common_funny.sort()
258  print 'Common funny cases :', self.common_funny
def report_full_closure (   self)

Definition at line 265 of file filecmp.py.

References dircmp.report(), and dircmp.subdirs.

266  def report_full_closure(self): # Report on self and subdirs recursively
267  self.report()
268  for x in self.subdirs.keys():
269  print
270  self.subdirs[x].report_full_closure()
271 
def report_partial_closure (   self)

Definition at line 259 of file filecmp.py.

References dircmp.report(), and dircmp.subdirs.

260  def report_partial_closure(self): # Print reports on self and on subdirs
261  self.report()
262  for x in self.subdirs.keys():
263  print
264  self.subdirs[x].report()

Field Documentation

common

Definition at line 176 of file filecmp.py.

common_dirs

Definition at line 181 of file filecmp.py.

common_files

Definition at line 182 of file filecmp.py.

common_funny

Definition at line 183 of file filecmp.py.

funny_files

Definition at line 217 of file filecmp.py.

hide

Definition at line 123 of file filecmp.py.

ignore

Definition at line 127 of file filecmp.py.

left

Definition at line 120 of file filecmp.py.

left_list

Definition at line 132 of file filecmp.py.

left_only

Definition at line 177 of file filecmp.py.

right

Definition at line 121 of file filecmp.py.

right_list

Definition at line 134 of file filecmp.py.

right_only

Definition at line 178 of file filecmp.py.

subdirs

Definition at line 223 of file filecmp.py.


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