-
Notifications
You must be signed in to change notification settings - Fork 0
/
comp.py
executable file
·72 lines (59 loc) · 1.79 KB
/
comp.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import sys, getopt
def main(argv):
try:
opts, args = getopt.getopt(argv,"ha:b:o:",["inputa=","inputb=","output="])
except getopt.GetoptError:
print ('main.py -a <inputfile> -b <inputfile> -o <outputfile>')
sys.exit(2)
inputfile1 = ''
inputfile2 = ''
outputfile = ''
output = []
for opt, arg in opts:
if opt == '-h':
print ('test.py -a <firstfile> -b <secondfile> -o <reportfile>')
sys.exit()
elif opt in ("-a", "--inputa"):
inputfile1 = arg
elif opt in ("-b", "--inputb"):
inputfile2 = arg
elif opt in ("-o", "--output"):
outputfile = arg
print(inputfile1)
print(inputfile2)
print(outputfile)
input1_lines = []
input2_lines = []
with open(inputfile1, "r") as input_file:
for line in input_file:
l = line.strip()
if l != "" :
input1_lines.append(line.strip())
with open(inputfile2, "r") as input_file:
for line in input_file:
l = line.strip()
if l != "" :
input2_lines.append(line.strip())
if len(input1_lines) != len(input2_lines):
output = ["different line count in these files! : file {} : #{} , file {} : #{}".format(inputfile1, len(input1_lines), inputfile2, len(input2_lines)) ]
with open(outputfile, "w") as output_file:
for item in output:
output_file.write("{} \n".format(item))
return 1
is_ok = True
for i in range(len(input1_lines)):
if input1_lines[i] != input2_lines[i]:
output.append("difference in line #{}: file: {} -----> content: {} <> file: {} -----> content: {}".format(i+1, inputfile1, input1_lines[i], inputfile2, input2_lines[i]))
is_ok = False
if is_ok:
output.append("OK")
with open(outputfile, "w") as output_file:
for item in output:
output_file.write("{} \n".format(item))
if is_ok:
return 0
else:
return 1
if __name__ == '__main__':
result = main(sys.argv[1:])
sys.exit(result)