def dircmp(a, b): # Compare whether two directories are the same # To make this as fast as possible, it uses the statcache print ' dircmp', a, b a_list = dircache.listdir(a) b_list = dircache.listdir(b) for x in a_list: if skipthis(x): pass elif x not in b_list: return 0 else: ax = os.path.join(a, x) bx = os.path.join(b, x) if statcache.isdir(ax) and statcache.isdir(bx): if not dircmp(ax, bx): return 0 else: try: if not cmpcache.cmp(ax, bx): return 0 except (RuntimeError, os.error): return 0 for x in b_list: if skipthis(x): pass elif x not in a_list: return 0 return 1
def dircmp(a, b): # Compare whether two directories are the same # To make this as fast as possible, it uses the statcache print ' dircmp', a, b a_list = dircache.listdir(a) b_list = dircache.listdir(b) for x in a_list: if x in skiplist: pass elif x not in b_list: return 0 else: ax = path.cat(a, x) bx = path.cat(b, x) if statcache.isdir(ax) and statcache.isdir(bx): if not dircmp(ax, bx): return 0 else: try: if not cmpcache.cmp(ax, bx): return 0 except posix.error: return 0 for x in b_list: if x in skiplist: pass elif x not in a_list: return 0 return 1
def dircmp(a, b): # Compare whether two directories are the same # To make this as fast as possible, it uses the statcache print " dircmp", a, b a_list = dircache.listdir(a) b_list = dircache.listdir(b) for x in a_list: if skipthis(x): pass elif x not in b_list: return 0 else: ax = os.path.join(a, x) bx = os.path.join(b, x) if statcache.isdir(ax) and statcache.isdir(bx): if not dircmp(ax, bx): return 0 else: try: if not cmpcache.cmp(ax, bx): return 0 except (RuntimeError, os.error): return 0 for x in b_list: if skipthis(x): pass elif x not in a_list: return 0 return 1
def cmp(a, b): """Compare two files. Return: 0 for equal 1 for different 2 for funny cases (can't stat, etc.)""" try: if cmpcache.cmp(a, b): return 0 return 1 except os.error: return 2
def cmp(a, b): try: if cmpcache.cmp(a, b): return 0 return 1 except posix.error: return 2
import cmpcache if cmpcache.cmp("samples/sample.au", "samples/sample.wav"): print "files are identical" else: print "files differ!" ## files differ!
"""A class to build directory diff tools on."""
import cmpcache if cmpcache.cmp("samples/sample.au", "samples/sample.wav"): print("files are identical") else: print("files differ!") ## files differ!