-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomp.py
More file actions
90 lines (77 loc) · 3.16 KB
/
comp.py
File metadata and controls
90 lines (77 loc) · 3.16 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import getopt
import sys
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
input1_lines = []
input2_lines = []
back_str = ""
with open(inputfile1, "r") as input_file:
cntr = 0
for line in input_file:
if cntr < 5:
cntr += 1
continue
l = line.strip()
back_str += l
if l != "":
input1_lines.append(line.strip())
input_file.close()
with open(inputfile1, "w") as input_file:
input_file.write(back_str)
input_file.close()
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)