updated to optionally display the text that describes a config option
[linux-2.6.git] / configs / kompare
1 #!/bin/env python
2 #
3 # compare: a tool to compare kernel config files
4 #
5 # Marc E. Fiuczynski <mef@cs.princeton.edu>
6 # Copyright (C) 2006 The Trustees of Princeton University
7 #
8 # $Id: kompare,v 1.2 2006/11/30 17:07:03 mef Exp $
9 #
10
11 import sys, re, os
12 import kread
13
14 def process(file):
15     ORDER = []
16     CONFIGS = {}
17     for line in file.readlines():
18         iline = line.lower()
19         iline = iline.strip()
20         if len(iline)==0: continue
21         firstchar = iline[0]
22
23         if firstchar == '#':
24             offset=iline.find(" is not set")
25             if offset <> -1:
26                 config = line[line.find("CONFIG"):offset].strip()
27                 if CONFIGS.has_key(config): print "duplicate entry %s" % config
28                 CONFIGS[config]="is not set"
29                 ORDER.append(config)
30             else:
31                 # skip over comments that do not contain the "is not set" string
32                 pass
33
34         else:
35             offset = iline.find('=')
36             if offset  <> -1:
37                 config = line[line.find("CONFIG"):offset].strip()
38                 if CONFIGS.has_key(config): print "duplicate entry %s" % config
39                 CONFIGS[config] = line[offset+1:].strip()
40                 ORDER.append(config)
41         
42     return (CONFIGS,ORDER)
43
44 showall=False
45 args = sys.argv[1:]
46
47 if len(args) <=1:
48     name = os.path.basename(sys.argv[0])
49     print "USAGE: %s [options] from.config to.config" % name
50     print """
51 Options
52     -a    Show all differences
53
54 State Legend
55     ADD     Added config (exists in to.config, but not in from.config)
56     REM     Removed config (exists in from.config, but not in to.config)
57     BLT     Builtin
58     MOD     Module
59     DIS     Disabled
60     """
61     sys.exit(0)
62
63 if args[0] == "-a":
64     showall = True
65     args = args[1:]
66
67 (old,oldorder)= process(open(args[0]))
68 (new,neworder)= process(open(args[1]))
69
70 newstate = {None:'REM',"is not set":'DIS','y':'BLT','m':'MOD'}
71 keys = neworder
72 for key in keys:
73     o = old.get(key,None)
74     n = new[key]
75     if n==o and not showall: continue
76     print "%6s -> %6s : %s" % (newstate.get(o,o),newstate.get(n,n),key)
77     if not showall: continue
78     helptxt=kread.gethelp(key)
79     if helptxt<>'':print helptxt
80
81 # not sure we care about what options have been removed
82 # from from.config file
83 sys.exit(0)
84 oldstate = {None:'A',"is not set":'D','y':'B','m':'M'}
85 keys = oldorder
86 for key in keys:
87     n = new.get(key,-1)
88     o = old[key]
89     if n == -1 and not showall:
90         print "%c -> %c : %s" % (oldstate[o],oldstate[n],key)
91
92