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
|
#!/usr/bin/python -tt
# skvidal @ fedoraproject.org gplv2 etc
# usage: inidiff old.ini new.ini
# it sorts the ini by section and options and then
# diffs them, printing the results
import sys
import ConfigParser
import difflib
if len(sys.argv) < 3 or len(sys.argv) > 3:
print 'Usage:\n inidiff old.ini new.ini'
sys.exit(1)
old = ConfigParser.ConfigParser()
new = ConfigParser.ConfigParser()
try:
old.read(sys.argv[1])
new.read(sys.argv[2])
except ConfigParser.Error, e:
print 'Error parsing ini file(s): %s' % e
sys.exit(1)
sortedold = {}
sortednew = {}
allsec = {}
for (f,l) in [(old,sortedold), (new, sortednew)]:
for sec in sorted(f.sections()):
thissec = []
thissec.append('[%s]\n' % sec)
for opt in sorted(f.options(sec)):
thissec.append('%s = %s\n' % (opt, f.get(sec, opt)))
thissec.append('\n')
l[sec]=thissec
allsec[sec] = 1
d = difflib.Differ()
for sec in sorted(allsec):
if sec not in sortednew:
for line in sortedold[sec]:
print '- ' + line,
elif sec not in sortedold:
for line in sortednew[sec]:
print '+ ' + line,
else:
res = [r for r in d.compare(sortedold[sec], sortednew[sec])]
anything = False
for line in res:
if line[0] in ('+','-', '?'):
anything = True
break
if anything:
print ''.join(res)
|