A tool to compare kernel config files.
authorMarc Fiuczynski <mef@cs.princeton.edu>
Thu, 30 Nov 2006 16:41:09 +0000 (16:41 +0000)
committerMarc Fiuczynski <mef@cs.princeton.edu>
Thu, 30 Nov 2006 16:41:09 +0000 (16:41 +0000)
configs/compare [new file with mode: 0755]
configs/kompare [new file with mode: 0755]

diff --git a/configs/compare b/configs/compare
new file mode 100755 (executable)
index 0000000..dd21f45
--- /dev/null
@@ -0,0 +1,91 @@
+#!/bin/env python
+#
+# compare: a tool to compare kernel config files
+#
+# Marc E. Fiuczynski <mef@cs.princeton.edu>
+# Copyright (C) 2006 The Trustees of Princeton University
+#
+# $Id:$
+#
+
+import sys, re, os
+
+def process(file):
+    ORDER = []
+    CONFIGS = {}
+    for line in file.readlines():
+        iline = line.lower()
+
+        offset=iline.find(" is not set")
+        if offset <> -1:
+            config = line[line.find("CONFIG"):offset].strip()
+            if CONFIGS.has_key(config): print "duplicate entry %s" % config
+            CONFIGS[config]=0
+            ORDER.append(config)
+            continue
+
+        offset = iline.find("=y")
+        if offset  <> -1:
+            config = line[line.find("CONFIG"):offset].strip()
+            if CONFIGS.has_key(config): print "duplicate entry %s" % config
+            CONFIGS[config]=1
+            ORDER.append(config)
+            continue
+
+        offset = iline.find("=m")
+        if iline.find("=m") <> -1:
+            config = line[line.find("CONFIG"):offset].strip()
+            if CONFIGS.has_key(config): print "duplicate entry %s" % config
+            CONFIGS[config]=2
+            ORDER.append(config)
+            continue
+
+    return (CONFIGS,ORDER)
+
+
+showall=False
+args = sys.argv[1:]
+
+if len(args) <=1:
+    name = os.path.basename(sys.argv[0])
+    print "USAGE: %s [options] from.config to.config" % name
+    print """
+Options
+    -a    Show all differences
+
+State Legend
+    A     Added config (exists in to.config, but not in from.config)
+    R     Removed config (exists in from.config, but not in to.config)
+    B     Builtin
+    M     Module
+    D     Disabled
+    """
+    sys.exit(0)
+
+if args[0] == "-a":
+    showall = True
+    args = args[1:]
+
+(old,oldorder)= process(open(args[0]))
+(new,neworder)= process(open(args[1]))
+
+oldstate = {-1:'A',0:'D',1:'B',2:'M'}
+newstate = {-1:'R',0:'D',1:'B',2:'M'}
+
+keys = neworder
+for key in keys:
+    o = old.get(key,-1)
+    n = new[key]
+    if n==o and not showall: continue
+    print "%c -> %c : %s" % (newstate[o],newstate[n],key)
+
+# not sure we care about what options have been removed
+# from from.config file
+sys.exit(0)
+keys = oldorder
+for key in keys:
+    n = new.get(key,-1)
+    o = old[key]
+    if n == -1 and not showall:
+        print "%c -> %c : %s" % (oldstate[o],oldstate[n],key)
+
diff --git a/configs/kompare b/configs/kompare
new file mode 100755 (executable)
index 0000000..273f198
--- /dev/null
@@ -0,0 +1,91 @@
+#!/bin/env python
+#
+# compare: a tool to compare kernel config files
+#
+# Marc E. Fiuczynski <mef@cs.princeton.edu>
+# Copyright (C) 2006 The Trustees of Princeton University
+#
+# $Id: compare,v 1.1 2006/11/30 16:39:29 mef Exp $
+#
+
+import sys, re, os
+
+def process(file):
+    ORDER = []
+    CONFIGS = {}
+    for line in file.readlines():
+        iline = line.lower()
+
+        offset=iline.find(" is not set")
+        if offset <> -1:
+            config = line[line.find("CONFIG"):offset].strip()
+            if CONFIGS.has_key(config): print "duplicate entry %s" % config
+            CONFIGS[config]=0
+            ORDER.append(config)
+            continue
+
+        offset = iline.find("=y")
+        if offset  <> -1:
+            config = line[line.find("CONFIG"):offset].strip()
+            if CONFIGS.has_key(config): print "duplicate entry %s" % config
+            CONFIGS[config]=1
+            ORDER.append(config)
+            continue
+
+        offset = iline.find("=m")
+        if iline.find("=m") <> -1:
+            config = line[line.find("CONFIG"):offset].strip()
+            if CONFIGS.has_key(config): print "duplicate entry %s" % config
+            CONFIGS[config]=2
+            ORDER.append(config)
+            continue
+
+    return (CONFIGS,ORDER)
+
+
+showall=False
+args = sys.argv[1:]
+
+if len(args) <=1:
+    name = os.path.basename(sys.argv[0])
+    print "USAGE: %s [options] from.config to.config" % name
+    print """
+Options
+    -a    Show all differences
+
+State Legend
+    A     Added config (exists in to.config, but not in from.config)
+    R     Removed config (exists in from.config, but not in to.config)
+    B     Builtin
+    M     Module
+    D     Disabled
+    """
+    sys.exit(0)
+
+if args[0] == "-a":
+    showall = True
+    args = args[1:]
+
+(old,oldorder)= process(open(args[0]))
+(new,neworder)= process(open(args[1]))
+
+oldstate = {-1:'A',0:'D',1:'B',2:'M'}
+newstate = {-1:'R',0:'D',1:'B',2:'M'}
+
+keys = neworder
+for key in keys:
+    o = old.get(key,-1)
+    n = new[key]
+    if n==o and not showall: continue
+    print "%c -> %c : %s" % (newstate[o],newstate[n],key)
+
+# not sure we care about what options have been removed
+# from from.config file
+sys.exit(0)
+keys = oldorder
+for key in keys:
+    n = new.get(key,-1)
+    o = old[key]
+    if n == -1 and not showall:
+        print "%c -> %c : %s" % (oldstate[o],oldstate[n],key)
+