-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffFileSet.py
More file actions
54 lines (41 loc) · 1.32 KB
/
DiffFileSet.py
File metadata and controls
54 lines (41 loc) · 1.32 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
import argparse
import difflib
class FileDiff:
def diffText(self, file1, file2) -> str:
txt1 = ''
with file1 as f:
txt1 = f.readlines()
txt2 = ''
with file2 as f:
txt2 = f.readlines()
text = ''
for line in difflib.unified_diff(txt1, txt2):
text += line
return text
def diffTextToBool(self, file1, file2) -> bool:
txt1 = ''
with file1 as f:
txt1 = f.readlines()
txt2 = ''
with file2 as f:
txt2 = f.readlines()
return txt1 == txt2
class App:
@staticmethod
def argumentParser():
parser = argparse.ArgumentParser(description='Diff Files')
parser.add_argument('File1', type=argparse.FileType('r'))
parser.add_argument('File2', type=argparse.FileType('r'))
parser.add_argument('-type', default='text', choices=['text', 'binary'], help='Type of diff')
return parser
@staticmethod
def exec(args):
fd = FileDiff()
if args.type == 'text':
print(fd.diffText(args.File1, args.File2))
elif args.type == 'binary':
print(fd.diffTextToBool(args.File1, args.File2))
if __name__ == '__main__':
parser = App.argumentParser()
args = parser.parse_args()
App.exec(args)