Setting tag linux-2.6-22-50
[linux-2.6.git] / 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.6 2006/12/14 19:59:05 mef Exp $
9 #
10
11 import sys, re, os
12
13 def process(file):
14     ORDER = []
15     CONFIGS = {}
16     for line in file.readlines():
17         iline = line.lower()
18         iline = iline.strip()
19         if len(iline)==0: continue
20         firstchar = iline[0]
21
22         if firstchar == '#':
23             offset=iline.find(" is not set")
24             if offset <> -1:
25                 config = line[line.find("CONFIG"):offset].strip()
26                 if CONFIGS.has_key(config): print "duplicate entry %s" % config
27                 CONFIGS[config]="is not set"
28                 ORDER.append(config)
29             else:
30                 # skip over comments that do not contain the "is not set" string
31                 pass
32
33         else:
34             offset = iline.find('=')
35             if offset  <> -1:
36                 config = line[line.find("CONFIG"):offset].strip()
37                 if CONFIGS.has_key(config): print "duplicate entry %s" % config
38                 CONFIGS[config] = line[offset+1:].strip()
39                 ORDER.append(config)
40         
41     return (CONFIGS,ORDER)
42
43 showall=False
44 args = sys.argv[1:]
45
46 if len(args) <=1:
47     name = os.path.basename(sys.argv[0])
48     print "USAGE: %s [options] from.config to.config" % name
49     print """
50 Options
51     -a    Show all differences
52
53 State Legend
54     ADD     Added config (exists in to.config, but not in from.config)
55     REM     Removed config (exists in from.config, but not in to.config)
56     BLT     Builtin
57     MOD     Module
58     DIS     Disabled
59     """
60     sys.exit(0)
61
62 if args[0] == "-a":
63     showall = True
64     args = args[1:]
65
66 (old,oldorder)= process(open(args[0]))
67 (new,neworder)= process(open(args[1]))
68
69 newstate = {None:'REMOVED',"is not set":'DISABLE','y':'BUILTIN','m':'MODULE '}
70 keys = neworder
71 seen = {}
72 for key in keys:
73     o = old.get(key,None)
74     n = new[key]
75     if n==o and not showall: continue
76     try:
77        print "%6s -> %6s : %s" % (newstate.get(o,o),newstate.get(n,n),key)
78     except IOError, e:
79         #print e
80         sys.exit(0)
81
82     seen[key] = None
83
84 # not sure we care about what options have been removed
85 # from from.config file
86 oldstate = {None:'REMOVED',"is not set":'DISABLE','y':'BUILTIN','m':'MODULE '}
87 keys = oldorder
88 for key in keys:
89     if seen.has_key(key): continue
90     n = new.get(key,None)
91     o = old[key]
92     if n == o and not showall: continue
93     try:
94        print "%6s -> %6s : %s" % (oldstate.get(o,o),oldstate.get(n,n),key)
95     except IOError, e:
96         #print e
97         sys.exit(0)