-
Notifications
You must be signed in to change notification settings - Fork 12
/
diffconfig.py
executable file
·136 lines (101 loc) · 3.5 KB
/
diffconfig.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env python
import sys, getopt
def read_config(config_file):
config = {}
try:
fh = open(config_file)
except:
print 'Error opening ' . config_file
sys.exit()
try:
lines = fh.read().splitlines()
finally:
fh.close()
for line in lines:
line = line.rstrip()
if line.endswith('=y'):
config[line[:-2]] = 'y'
elif line.endswith('=m'):
config[line[:-2]] = 'm'
elif line.endswith(' is not set'):
config[line[:-11]] = 'n'
return config
def a_and_b(a, b, state):
result_list = []
for entry in sorted(a):
if a[entry] == state:
if b.has_key(entry):
if b[entry] == state:
result_list.append(entry)
return result_list
def a_not_b(a, b, state):
result_dict = {}
for entry in sorted(a):
if a[entry] == state:
if b.has_key(entry):
if b[entry] != state:
result_dict[entry] = b[entry]
else:
result_dict[entry] = '?'
return result_dict
def usage():
print '\nUsage: %s <first-kernel-config> <second-kernel-config>\n' % (sys.argv[0])
print 'Display diffs between two Linux kernel configs in an alternative format then `diff`'
print 'Options:'
print '-v\tShow entries that match in both configs. Default behavior shows only diffs.'
print '-h\tShow this help message\n'
if __name__ == '__main__':
verbose = False
try:
opts, args = getopt.getopt(sys.argv[1:], 'hv')
except getopt.GetoptError, err:
print str(err)
usage()
sys.exit(1)
for opt, arg in opts:
if opt == 'h':
usage()
sys.exit(0)
if opt == '-v':
verbose = True
if len(args) < 2:
usage()
sys.exit(1)
a_config = args[0]
b_config = args[1]
a = read_config(a_config)
b = read_config(b_config)
print a_config, 'has', len(a), 'entries'
print b_config, 'has', len(b), 'entries'
if verbose:
result_list = a_and_b(a, b, 'y')
print '\n=y both configs', len(result_list)
print '======================================'
for entry in result_list:
print 'y y', entry
print '======================================'
result_list = a_and_b(a, b, 'm')
print '\n=m both configs', len(result_list)
print '======================================'
for entry in result_list:
print 'm m', entry
print '======================================'
result_list = a_and_b(a, b, 'n')
print '\nNot set in both configs', len(result_list)
print '======================================'
for entry in result_list:
print 'n n', entry
print '======================================'
# just the diffs
result_dict = a_not_b(a, b, 'y')
print '\n=y in', a_config, 'and not in', b_config, len(result_dict)
print '======================================'
for key in sorted(result_dict.keys()):
print 'y', result_dict[key], key
print '======================================'
result_dict = a_not_b(b, a, 'y')
print '\n=y in', b_config, 'and not in', a_config, len(result_dict)
print '======================================'
for key in sorted(result_dict.keys()):
print result_dict[key], 'y', key
print '======================================'