summaryrefslogtreecommitdiffstats
path: root/roles/s3-mirror/files/symmetric_diff
blob: e7fb62c390c4ee8fbde3616a77a37cac284708fc (plain)
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
#!/usr/bin/python
# Copyright 2013 by Matt Domsch
# Licensed under the MIT/X11 license
# usage: symmetric_diff <file a> <file b>
#   given two text files a and b, returns the symmetric difference of the lines changed between them.
#   The order in which lines appear in each file is irrelevant.

import sys
import optparse

def read_file(filename):
    f = open(filename, 'r')
    lines = f.readlines()
    f.close()
    return set(lines)

def diff(a, b):
    file_a = read_file(a)
    file_b = read_file(b)
    sdiff = file_a.symmetric_difference(file_b)
    sdiff = list(sdiff)
    sdiff.sort()
    return sdiff

def main():
    parser = optparse.OptionParser(usage=sys.argv[0] + " [options]")
    (options, args) = parser.parse_args()
    if len(args) < 2:
        parser.print_help()
    sdiff = diff(args[0], args[1])
    for l in sdiff:
        sys.stdout.write(l)

if __name__ == "__main__":
    sys.exit(main())