2015-08-29 20:48:39 +00:00
|
|
|
#!/usr/bin/env python3
|
2008-05-01 07:54:28 +00:00
|
|
|
|
2010-04-27 08:43:41 +00:00
|
|
|
import optparse
|
|
|
|
import os.path
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
2008-05-01 07:54:28 +00:00
|
|
|
from debian_linux.kconfig import *
|
|
|
|
|
2012-01-11 17:00:17 +00:00
|
|
|
|
2010-04-27 08:43:41 +00:00
|
|
|
def merge(output, configs, overrides):
|
2008-05-01 07:54:28 +00:00
|
|
|
kconfig = KconfigFile()
|
2010-04-27 08:43:41 +00:00
|
|
|
for c in configs:
|
2015-08-30 20:34:13 +00:00
|
|
|
kconfig.read(open(c))
|
|
|
|
for key, value in overrides.items():
|
2010-04-27 08:43:41 +00:00
|
|
|
kconfig.set(key, value)
|
2015-08-30 20:34:13 +00:00
|
|
|
open(output, "w").write(str(kconfig))
|
2008-05-01 07:54:28 +00:00
|
|
|
|
2012-01-11 17:00:17 +00:00
|
|
|
|
2010-04-27 08:43:41 +00:00
|
|
|
def opt_callback_dict(option, opt, value, parser):
|
|
|
|
match = re.match('^\s*(\S+)=(\S+)\s*$', value)
|
|
|
|
if not match:
|
|
|
|
raise optparse.OptionValueError('not key=value')
|
|
|
|
dest = option.dest
|
|
|
|
data = getattr(parser.values, dest)
|
|
|
|
data[match.group(1)] = match.group(2)
|
|
|
|
|
2012-01-11 17:00:17 +00:00
|
|
|
|
2008-05-01 07:54:28 +00:00
|
|
|
if __name__ == '__main__':
|
2012-01-11 17:00:17 +00:00
|
|
|
parser = optparse.OptionParser(usage="%prog [OPTION]... FILE...")
|
2013-10-26 21:04:10 +00:00
|
|
|
parser.add_option(
|
|
|
|
'-o', '--override',
|
|
|
|
action='callback',
|
|
|
|
callback=opt_callback_dict,
|
|
|
|
default={},
|
|
|
|
dest='overrides',
|
|
|
|
help="Override option",
|
|
|
|
type='string')
|
2010-04-27 08:43:41 +00:00
|
|
|
options, args = parser.parse_args()
|
|
|
|
|
|
|
|
merge(args[0], args[1:], options.overrides)
|