forked from dilawar/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diff.py
executable file
·79 lines (67 loc) · 2.06 KB
/
diff.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
73
74
75
76
77
78
79
#!/usr/bin/env python
import sys, os
import time
def checkTwoFiles(string) :
# This is already verified.
if string.strip()[0] == "#" :
return
files = string.split(",")
filesToCompare = list()
for file in files :
file = file.strip()
file = file.replace('"', '')
if os.path.isfile(file) :
filesToCompare.append(file.replace(' ','\ '))
command = "vimdiff "
for file in filesToCompare :
command += (file+" ")
os.system(command)
if __name__ == "__main__" :
if len(sys.argv) < 2 :
print("USAGE : ./diff.py [-f filename] OR [filenames separated by comma]")
sys.exit(0)
fileMode = False
filePath = ""
if sys.argv[1] == "-f" :
fileMode = True
filePath = sys.argv[2]
print("Processing file : {0}".format(filePath))
if fileMode :
verified = ""
# If verified files list exists then load it.
verifyFilePath = filePath+"_verified"
if os.path.isfile(verifyFilePath) :
verified = open(verifyFilePath, "r").read()
# And append new entries
print filePath
txt = open(filePath, "r").read()
lines = txt.split("\n")
newText = ""
keepGoing = True
while len(lines) > 0 and keepGoing :
line = lines.pop()
if verified.find(line) != -1 :
print("These files are already accepted. continuing ... ")
continue
string = line[:]
checkTwoFiles(string)
res = raw_input("Press any character to reject [x to exit]:")
if len(res.strip()) == 0 :
newline = time.strftime("%Y-%m-%D:%t")+" == "+line
verified += newline+"\n"
# remove this line from origial list
elif res.strip() == "x" :
keepGoing = False
else : pass
# write back the modified text.
newText += "#"+line+"\n"
os.remove(filePath)
with open(filePath, "w") as outF :
outF.write(newText)
# write the unprocessed lines.
for line in lines :
outF.write(line+"\n")
with open(verifyFilePath, "a") as vf :
vf.write(verified)
else :
checkTwoFiles("".join(sys.argv[1:]))