~ubuntu-archive/ubuntu-archive-scripts/trunk

« back to all changes in this revision

Viewing changes to compare-archives

  • Committer: Ubuntu Archive
  • Date: 2012-04-26 14:45:21 UTC
  • Revision ID: ubuntu-archive@lillypilly-20120426144521-4kvi3y9cq4gay4dx
compare-archives: added, moved from cocoplum

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import os
 
4
import sys
 
5
import subprocess
 
6
 
 
7
master = sys.argv[1]
 
8
testing = sys.argv[2]
 
9
 
 
10
def missing(what, path):
 
11
    print "E: %s %s is missing" % (what, path)
 
12
 
 
13
def compare(path, testpath):
 
14
    if (path.endswith('.tar.gz') or path.endswith('.tar.bz2') or
 
15
        path.endswith('.tar.xz')):
 
16
        compare_bin(path, testpath)
 
17
    elif path.endswith('.gz'):
 
18
        compare_diff('zdiff', path, testpath)
 
19
    elif path.endswith('.bz2'):
 
20
        compare_diff('bzdiff', path, testpath)
 
21
    elif path.endswith('/Release'):
 
22
        compare_Release(path, testpath)
 
23
    elif path.endswith('.deb'):
 
24
        compare_deb(path, testpath)
 
25
    else:
 
26
        compare_diff('diff', path, testpath)
 
27
 
 
28
def compare_diff(diffprog, path, testpath):
 
29
    args = [diffprog, '-u', '--ignore-matching-lines=^Bugs:', '--ignore-matching-lines=^Origin:', '--ignore-matching-lines=^Task:', '--ignore-matching-lines=^Build-Essential:', '--ignore-matching-lines=^Supported:', path, testpath]
 
30
    diff = subprocess.Popen(args, stdout=subprocess.PIPE)
 
31
    output = diff.stdout.read()
 
32
    if diff.wait() != 0:
 
33
        # zdiff's header information is useless, so prepend our own
 
34
        print ' '.join(args)
 
35
        print output,
 
36
 
 
37
def compare_bin(path, testpath):
 
38
    cmp = subprocess.Popen(['cmp', path, testpath])
 
39
    cmp.wait()
 
40
 
 
41
def compare_Release(path, testpath):
 
42
    return
 
43
    print "W: Release comparison not implemented yet"
 
44
 
 
45
def compare_deb(path, testpath):
 
46
    return
 
47
    print "W: .deb comparison not implemented yet"
 
48
 
 
49
for dirpath, dirnames, filenames in os.walk(master):
 
50
    relpath = dirpath[len(master):].strip('/')
 
51
 
 
52
    missing_dirs = []
 
53
    for path in dirnames:
 
54
        testpath = os.path.join(testing,relpath,path)
 
55
        if not os.path.isdir(testpath):
 
56
            missing('directory', os.path.join(relpath,path))
 
57
            missing_dirs.append(path)
 
58
    for path in missing_dirs:
 
59
        dirnames.remove(path)
 
60
 
 
61
    for path in filenames:
 
62
        testpath = os.path.join(testing,relpath,path)
 
63
        if not os.path.isfile(testpath):
 
64
            missing('file', testpath)
 
65
            continue
 
66
 
 
67
        compare(os.path.join(dirpath,path), testpath)
 
68