Skip to content

Instantly share code, notes, and snippets.

@zielmicha
Created September 15, 2015 16:54
Show Gist options
  • Save zielmicha/2df881e8290e760d5ed5 to your computer and use it in GitHub Desktop.
Save zielmicha/2df881e8290e760d5ed5 to your computer and use it in GitHub Desktop.
Compares two config generated by Kconfig (for Linux kernel or buildbot, for example)
from __future__ import print_function
import sys
def load(s):
d = {}
for line in open(s):
line = line.strip()
if line.startswith('# ') and line.endswith(' is not set'):
key = line.split()[1]
d[key] = False
elif not line.startswith('#') and line:
key, value = line.split('=', 1)
d[key] = value
return d
A = load(sys.argv[1])
B = load(sys.argv[2])
for k, v in B.items():
A.setdefault(k, None)
def humanize(v):
if v is None:
return 'not present'
elif v is False:
return 'not set'
else:
return v
for k in A:
a, b = A[k], B.get(k, None)
if a != b:
print('key', k)
print(' ', sys.argv[1] + ':', humanize(a))
print(' ', sys.argv[2] + ':', humanize(b))
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment