File: compare.py

package info (click to toggle)
ori 0.8.1%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,204 kB
  • ctags: 2,659
  • sloc: cpp: 22,383; ansic: 5,870; sh: 451; python: 205; makefile: 21
file content (47 lines) | stat: -rw-r--r-- 1,134 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import os.path
import sys

dir1 = sys.argv[1]
dir2 = sys.argv[2]

def filenames(dname):
    rval = set()
    for root, dirs, files in os.walk(dname):
        relroot = root[len(dname):].lstrip('/')
        if relroot.startswith('.ori'):
            continue

        for fn in files:
            if fn.startswith('.ori'):
                continue
            fullfn = os.path.join(relroot, fn)
            rval.add(fullfn)
    return rval

print("Checking directory trees")
set1 = filenames(dir1)
set2 = filenames(dir2)
diff = set1.symmetric_difference(set2)
if len(diff) > 0:
    print("Some files are not present in both directories:")
    print(diff)
    sys.exit(1)

# Check file contents
def readall(fname):
    with open(fname, 'rb') as f:
        try:
            return f.read()
        except IOError as e:
            print("{}: {}".format(fname, e.strerror))
            return ''

print("Checking file contents")
for fn in set1:
    f1 = readall(os.path.join(dir1, fn))
    f2 = readall(os.path.join(dir2, fn))
    if f1 != f2:
        print("File contents not identical!")
        print(fn)
        sys.exit(1)