36 lines
920 B
Text
36 lines
920 B
Text
|
#!/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())
|