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

Data Structures

class  dircmp
 

Functions

def cmp
 
def cmpfiles
 
def demo
 

Variables

list __all__ = ["cmp","dircmp","cmpfiles"]
 
dictionary _cache = {}
 
int BUFSIZE = 8
 

Detailed Description

Utilities for comparing files and directories.

Classes:
    dircmp

Functions:
    cmp(f1, f2, shallow=1, use_statcache=0) -> int
    cmpfiles(a, b, common) -> ([], [], [])

Function Documentation

def filecmp.cmp (   f1,
  f2,
  shallow = 1,
  use_statcache = 0 
)
Compare two files.

Arguments:

f1 -- First file name

f2 -- Second file name

shallow -- Just check stat signature (do not read the files).
           defaults to 1.

use_statcache -- Do not stat() each file directly: go through
                 the statcache module for more efficiency.

Return value:

integer -- 1 if the files are the same, 0 otherwise.

This function uses a cache for past comparisons and the results,
with a cache invalidation mechanism relying on stale signatures.
Of course, if 'use_statcache' is true, this mechanism is defeated,
and the cache will never grow stale.

Definition at line 21 of file filecmp.py.

References aifc.open(), and stat.S_IFMT().

21 
22 def cmp(f1, f2, shallow=1, use_statcache=0):
23  """Compare two files.
24 
25  Arguments:
26 
27  f1 -- First file name
28 
29  f2 -- Second file name
30 
31  shallow -- Just check stat signature (do not read the files).
32  defaults to 1.
33 
34  use_statcache -- Do not stat() each file directly: go through
35  the statcache module for more efficiency.
36 
37  Return value:
38 
39  integer -- 1 if the files are the same, 0 otherwise.
40 
41  This function uses a cache for past comparisons and the results,
42  with a cache invalidation mechanism relying on stale signatures.
43  Of course, if 'use_statcache' is true, this mechanism is defeated,
44  and the cache will never grow stale.
45 
46  """
47  if use_statcache:
48  stat_function = statcache.stat
49  else:
50  stat_function = os.stat
51  s1 = _sig(stat_function(f1))
52  s2 = _sig(stat_function(f2))
53  if s1[0] != stat.S_IFREG or s2[0] != stat.S_IFREG:
54  return 0
55  if shallow and s1 == s2:
56  return 1
57  if s1[1] != s2[1]:
58  return 0
59 
60  result = _cache.get((f1, f2))
61  if result and (s1, s2) == result[:2]:
62  return result[2]
63  outcome = _do_cmp(f1, f2)
64  _cache[f1, f2] = s1, s2, outcome
65  return outcome
def filecmp.cmpfiles (   a,
  b,
  common,
  shallow = 1,
  use_statcache = 0 
)
Compare common files in two directories.

a, b -- directory names
common -- list of file names found in both directories
shallow -- if true, do comparison based solely on stat() information
use_statcache -- if true, use statcache.stat() instead of os.stat()

Returns a tuple of three lists:
  files that compare equal
  files that are different
  filenames that aren't regular files.

Definition at line 272 of file filecmp.py.

References reconvert.append, and cmp().

273 def cmpfiles(a, b, common, shallow=1, use_statcache=0):
274  """Compare common files in two directories.
275 
276  a, b -- directory names
277  common -- list of file names found in both directories
278  shallow -- if true, do comparison based solely on stat() information
279  use_statcache -- if true, use statcache.stat() instead of os.stat()
280 
281  Returns a tuple of three lists:
282  files that compare equal
283  files that are different
284  filenames that aren't regular files.
285 
286  """
287  res = ([], [], [])
288  for x in common:
289  ax = os.path.join(a, x)
290  bx = os.path.join(b, x)
291  res[_cmp(ax, bx, shallow, use_statcache)].append(x)
292  return res
293 
294 
295 # Compare two files.
296 # Return:
297 # 0 for equal
298 # 1 for different
299 # 2 for funny cases (can't stat, etc.)
#
def filecmp.demo ( )

Definition at line 318 of file filecmp.py.

References getopt.getopt().

319 def demo():
320  import sys
321  import getopt
322  options, args = getopt.getopt(sys.argv[1:], 'r')
323  if len(args) != 2:
324  raise getopt.error, 'need exactly two args'
325  dd = dircmp(args[0], args[1])
326  if ('-r', '') in options:
327  dd.report_full_closure()
328  else:
329  dd.report()

Variable Documentation

list __all__ = ["cmp","dircmp","cmpfiles"]

Definition at line 16 of file filecmp.py.

dictionary _cache = {}

Definition at line 18 of file filecmp.py.

int BUFSIZE = 8

Definition at line 19 of file filecmp.py.