3 # compare: a tool to compare kernel config files
5 # Marc E. Fiuczynski <mef@cs.princeton.edu>
6 # Copyright (C) 2006 The Trustees of Princeton University
8 # $Id: kread.py,v 1.3 2006/12/01 02:43:01 mef Exp $
11 import sys, re, os, stat
12 import cStringIO, cPickle
19 def _config(parts,fb):
21 currentconfig = parts[1]
31 if len(line)==0: break
32 if not line[0].isspace(): break
33 if len(line)>1: newline = line.lstrip()
35 helptxt = helptxt+newline
37 configs[currentconfig]=helptxt
40 def _source(parts,fb):
41 filename = "".join(parts[1:])
42 if filename[0]=='"' or filename[0]=='\'':
44 if filename[-1]=='"' or filename[-1]=='\'':
45 filename=filename[:-1]
52 keywords = {"config":_config,
57 def process(filename):
58 files.append((filename,os.stat(filename)[stat.ST_MTIME]))
71 func = keywords.get(parts[0],_noop)
81 ARCH=os.getenv("ARCH","i386")
84 f = open(".kread.db","r")
85 meta = cPickle.load(f)
90 for file, mtime in files:
91 cur_mtime = os.stat(file)[stat.ST_MTIME]
92 if mtime <> cur_mtime:
99 if reprocess or force:
100 meta = (configs, files)
101 process("arch/%s/Kconfig" % ARCH)
103 f = open(".kread.db.tmp","w")
104 cPickle.dump(meta,f,True)
106 os.rename(".kread.db.tmp", ".kread.db")
111 if option[:len("CONFIG_")] == "CONFIG_":
112 option=option[len("CONFIG_"):]
113 helptxt = configs.get(option,"")
117 if __name__ == '__main__':
118 if len(sys.argv) == 1:
119 print """USAGE\n%s configoptionname""" % os.path.basename(sys.argv[0])
121 if sys.argv[1] == "-f" and len(sys.argv)>=2:
125 options = sys.argv[1:]
129 for option in options:
130 helptxt = gethelp(option)
131 print "CONFIG_%s:\n%s" % (option,helptxt)