-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkread
executable file
·132 lines (115 loc) · 3.13 KB
/
kread
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/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: kread,v 1.1 2006/12/01 16:21:13 mef Exp $
#
import sys, re, os, stat
import cStringIO, cPickle
currentconfig = ""
files = []
configs = {}
meta = None
def _config(parts,fb):
global currentconfig
currentconfig = parts[1]
return None
def _help(parts,fb):
global currentconfig
helptxt = ""
lineno = 0
while True:
line = fb.readline()
lineno = lineno + 1
if len(line)==0: break
if not line[0].isspace(): break
if len(line)>1: newline = line.lstrip()
else: newline = line
helptxt = helptxt+newline
configs[currentconfig]=helptxt
return line
def _source(parts,fb):
filename = "".join(parts[1:])
if filename[0]=='"' or filename[0]=='\'':
filename=filename[1:]
if filename[-1]=='"' or filename[-1]=='\'':
filename=filename[:-1]
process(filename)
return None
def _noop(parts,fb):
return None
keywords = {"config":_config,
"help":_help,
"---help---":_help,
"source":_source}
def process(filename):
files.append((filename,os.stat(filename)[stat.ST_MTIME]))
fb = open(filename)
lineno = 0
line = fb.readline()
while True:
lineno = lineno + 1
if len(line)==0:break
line = line.strip()
parts = line.split()
if len(parts)==0:
line = fb.readline()
else:
func = keywords.get(parts[0],_noop)
line = func(parts,fb)
if line == None:
line = fb.readline()
fb.close()
def init(force):
global configs
global files
ARCH=os.getenv("ARCH","i386")
reprocess = True
try:
f = open(".kread.db","r")
meta = cPickle.load(f)
f.close()
configs, files = meta
reprocess = False
try:
for file, mtime in files:
cur_mtime = os.stat(file)[stat.ST_MTIME]
if mtime <> cur_mtime:
reprocess = True
break
except:
pass
except IOError, e:
pass
if reprocess or force:
meta = (configs, files)
process("arch/%s/Kconfig" % ARCH)
try:
f = open(".kread.db.tmp","w")
cPickle.dump(meta,f,True)
f.close()
os.rename(".kread.db.tmp", ".kread.db")
except IOError, e:
pass
def gethelp(option):
if option[:len("CONFIG_")] == "CONFIG_":
option=option[len("CONFIG_"):]
helptxt = configs.get(option,"")
return helptxt
if __name__ == '__main__':
if len(sys.argv) == 1:
print """USAGE\n%s configoptionname""" % os.path.basename(sys.argv[0])
else:
if sys.argv[1] == "-f" and len(sys.argv)>=2:
force = True
options=sys.argv[2:]
else:
options = sys.argv[1:]
force = False
init(force)
for option in options:
helptxt = gethelp(option)
print "CONFIG_%s:\n%s" % (option,helptxt)