blob: 1b42f1f2f7022fe5f48a9c1700d28370034be10f (
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
36
37
38
39
40
41
42
43
44
45
|
#!/usr/bin/env python
"""
line_diff.py - Simple tool that compares two files with the same number of lines and prints the
characters (if any) on the right line (moving left to right) that are present that
weren't present in the left line
"""
import sys
left_file = sys.argv[1]
right_file = sys.argv[2]
left_lines = []
right_lines = []
with open(left_file) as left:
for line in left.readlines():
left_lines.append(line.strip())
with open(right_file) as right:
for line in right.readlines():
right_lines.append(line.strip())
if len(left_lines) != len(right_lines):
print("Files didn't have the same number of lines, exiting...")
sys.exit(0)
for i in range(len(left_lines)):
left_contents = left_lines[i]
right_contents = right_lines[i]
if len(left_contents) > len(right_contents):
print("Line " + str(i) + " has longer left contents than right contents.")
print("Left contents: " + left_contents)
print("Right contents: " + right_contents)
break
else:
left_list = list(left_contents)
right_list = list(right_contents)
while len(left_list) > 0:
if right_list.pop(0) != left_list.pop(0):
print("Line " + str(i) + ": Right contents that are not a prefix of left contents.")
print("Left contents: " + left_contents)
print("Right contents: " + right_contents)
break
if len(right_list) > 0:
print("Line " + str(i) + ": Right contents have extra characters: " + ''.join(right_list))
|