-
Notifications
You must be signed in to change notification settings - Fork 2
/
diffSettingFiles.py
executable file
·105 lines (79 loc) · 1.7 KB
/
diffSettingFiles.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
from sys import *
def parseValuePart(value):
if value=="":
return value
val=""
if value[0]=='"':
quote='"'
val=value[0]
elif value[0]=="'":
quote="'"
val=value[0]
else:
quote=None
if value[0] not in [" ","\t","#"]:
val=value[0]
level=0
for v in value[1:]:
if quote==None and v in [" ","\t","#"]:
return val
elif v==quote and level==0:
return val+v
elif v=="\\" and level==0:
level=1
val+=v
else:
level=0
val+=v
return val
def loadSettingFile(filename,keyvalsep="="):
settings=dict()
fil=open(filename)
for lin in fil:
lin=lin.strip("\r\n")
if len(lin)<1 or lin[0]=="#":
continue
splits=lin.split(keyvalsep)
key=splits[0].strip()
value=keyvalsep.join(splits[1:]).strip()
if len(key)==0:
continue
settings[key]=parseValuePart(value)
fil.close()
return settings
def printUsageAndExit(programName):
print >> stderr,programName,"infile1 infile2"
exit(1)
if __name__=='__main__':
programName=argv[0]
args=argv[1:]
try:
infile1,infile2=args
except:
printUsageAndExit(programName)
settings1=loadSettingFile(infile1)
settings2=loadSettingFile(infile2)
allkeys=list(settings1.keys())
allkeys.extend(settings2.keys())
allkeys=list(set(allkeys))
allkeys.sort()
NAValue="N/A"
firstLine=True
for key in allkeys:
try:
value1=settings1[key]
except KeyError:
value1=NAValue
try:
value2=settings2[key]
except KeyError:
value2=NAValue
#it is impossible to get both NAValues
if value1==value2:
#the same, ignore
continue
if firstLine:
print >> stdout,"key\t%s\t%s" %(infile1,infile2)
firstLine=False
print >> stdout,"%s\t%s\t%s" %(key,value1,value2)