Skip to content

Instantly share code, notes, and snippets.

@tytydraco
Created June 21, 2020 17:41
Show Gist options
  • Save tytydraco/a151d2ec3bbc1b2835ceb0fe33ef8956 to your computer and use it in GitHub Desktop.
Save tytydraco/a151d2ec3bbc1b2835ceb0fe33ef8956 to your computer and use it in GitHub Desktop.
Script do get all changes that differ from the original base defconfig, ideally to apply the changes to another device config in the future.
import re, sys
if len(sys.argv) != 3:
print(f"""Usage: {sys.argv[0]} <base_defconfig> <custom_defconfig>
For best results, use savedefconfig generated configs.""")
exit(1)
cfg_base = sys.argv[1]
cfg_custom = sys.argv[2]
def cfg_purify(f):
lines = f.read().splitlines()
for i, e in enumerate(lines):
match = re.search('# ([^\s]+) is not set', e)
if match:
config = match.group(1)
lines[i] = f"{config}=n"
lines = [ x for x in lines if '#' not in x ]
return lines
def cfg_diff():
with open(cfg_base, 'r') as f:
base_lines = cfg_purify(f)
with open(cfg_custom, 'r') as f:
custom_lines = cfg_purify(f)
diff_lines = []
for line in custom_lines:
if line not in base_lines:
diff_lines.append(line)
for line in diff_lines:
print(line)
cfg_diff()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment