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

344.1.1 by Steve Langasek
Move all shebangs to python3.
1
#!/usr/bin/python3
46 by Ubuntu Archive
compare-archives: added, moved from cocoplum
2
79 by Colin Watson
compare-archives: use Python 3-compatible print functions
3
from __future__ import print_function
4
46 by Ubuntu Archive
compare-archives: added, moved from cocoplum
5
import os
6
import sys
7
import subprocess
8
9
master = sys.argv[1]
10
testing = sys.argv[2]
11
12
def missing(what, path):
79 by Colin Watson
compare-archives: use Python 3-compatible print functions
13
    print("E: %s %s is missing" % (what, path))
46 by Ubuntu Archive
compare-archives: added, moved from cocoplum
14
15
def compare(path, testpath):
16
    if (path.endswith('.tar.gz') or path.endswith('.tar.bz2') or
17
        path.endswith('.tar.xz')):
18
        compare_bin(path, testpath)
19
    elif path.endswith('.gz'):
20
        compare_diff('zdiff', path, testpath)
21
    elif path.endswith('.bz2'):
22
        compare_diff('bzdiff', path, testpath)
202 by Adam Conrad
compare-archives: Learn to love xz
23
    elif path.endswith('.xz'):
24
        compare_diff('xzdiff', path, testpath)
46 by Ubuntu Archive
compare-archives: added, moved from cocoplum
25
    elif path.endswith('/Release'):
26
        compare_Release(path, testpath)
27
    elif path.endswith('.deb'):
28
        compare_deb(path, testpath)
29
    else:
30
        compare_diff('diff', path, testpath)
31
32
def compare_diff(diffprog, path, testpath):
33
    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]
80 by Colin Watson
compare-archives: ensure diff output is Unicode in Python 3
34
    diff = subprocess.Popen(
35
        args, stdout=subprocess.PIPE, universal_newlines=True)
46 by Ubuntu Archive
compare-archives: added, moved from cocoplum
36
    output = diff.stdout.read()
37
    if diff.wait() != 0:
38
        # zdiff's header information is useless, so prepend our own
79 by Colin Watson
compare-archives: use Python 3-compatible print functions
39
        print(' '.join(args))
40
        print(output, end="")
46 by Ubuntu Archive
compare-archives: added, moved from cocoplum
41
42
def compare_bin(path, testpath):
81 by Colin Watson
compare-archives: simplify compare_bin function
43
    subprocess.call(['cmp', path, testpath])
46 by Ubuntu Archive
compare-archives: added, moved from cocoplum
44
45
def compare_Release(path, testpath):
46
    return
79 by Colin Watson
compare-archives: use Python 3-compatible print functions
47
    print("W: Release comparison not implemented yet")
46 by Ubuntu Archive
compare-archives: added, moved from cocoplum
48
49
def compare_deb(path, testpath):
50
    return
79 by Colin Watson
compare-archives: use Python 3-compatible print functions
51
    print("W: .deb comparison not implemented yet")
46 by Ubuntu Archive
compare-archives: added, moved from cocoplum
52
53
for dirpath, dirnames, filenames in os.walk(master):
54
    relpath = dirpath[len(master):].strip('/')
55
56
    missing_dirs = []
57
    for path in dirnames:
58
        testpath = os.path.join(testing,relpath,path)
59
        if not os.path.isdir(testpath):
60
            missing('directory', os.path.join(relpath,path))
61
            missing_dirs.append(path)
62
    for path in missing_dirs:
63
        dirnames.remove(path)
64
65
    for path in filenames:
66
        testpath = os.path.join(testing,relpath,path)
67
        if not os.path.isfile(testpath):
68
            missing('file', testpath)
69
            continue
70
71
        compare(os.path.join(dirpath,path), testpath)