Skip to content

Instantly share code, notes, and snippets.

@MartijnBraam
Created January 17, 2018 13:29
Show Gist options
  • Save MartijnBraam/301374564e97d3e453838ce8c4aec33d to your computer and use it in GitHub Desktop.
Save MartijnBraam/301374564e97d3e453838ce8c4aec33d to your computer and use it in GitHub Desktop.
Tool to diff kernel configs
def parse_config(raw):
result = {}
for line in raw.splitlines():
if line.startswith("#"):
continue
if line.strip() == "":
continue
key, value = line.split("=", maxsplit=1)
result[key] = value
return result
def diff_configs(a, b):
result = []
config_a = parse_config(a)
config_b = parse_config(b)
for key, value in config_b.items():
if key not in config_a:
result.append("{}={}".format(key, value))
return result
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description="defconfig diff utility")
parser.add_argument('config_a', type=open)
parser.add_argument('config_b', type=open)
parser.add_argument('--missing', help="List parameters from B that aren't set in A")
args = parser.parse_args()
with args.config_a:
a = args.config_a.read()
with args.config_b:
b = args.config_b.read()
diff = diff_configs(a, b)
for line in diff:
print(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment