提交 c8272faf 编写于 作者: M Mike Pagano 提交者: Michal Marek

diffconfig: Update script to support python versions 2.5 through 3.3

Support past and active versions of python while maintaining backward
compatibility. Script has been tested on python versions up to and
including 3.3.X.
Signed-off-by: NMike Pagano <mpagano@gentoo.org>
Signed-off-by: NMichal Marek <mmarek@suse.cz>
上级 6bf2e84b
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
import sys, os import sys, os
def usage(): def usage():
print """Usage: diffconfig [-h] [-m] [<config1> <config2>] print("""Usage: diffconfig [-h] [-m] [<config1> <config2>]
Diffconfig is a simple utility for comparing two .config files. Diffconfig is a simple utility for comparing two .config files.
Using standard diff to compare .config files often includes extraneous and Using standard diff to compare .config files often includes extraneous and
...@@ -33,7 +33,7 @@ Example usage: ...@@ -33,7 +33,7 @@ Example usage:
EXT2_FS y -> n EXT2_FS y -> n
LOG_BUF_SHIFT 14 -> 16 LOG_BUF_SHIFT 14 -> 16
PRINTK_TIME n -> y PRINTK_TIME n -> y
""" """)
sys.exit(0) sys.exit(0)
# returns a dictionary of name/value pairs for config items in the file # returns a dictionary of name/value pairs for config items in the file
...@@ -54,23 +54,23 @@ def print_config(op, config, value, new_value): ...@@ -54,23 +54,23 @@ def print_config(op, config, value, new_value):
if merge_style: if merge_style:
if new_value: if new_value:
if new_value=="n": if new_value=="n":
print "# CONFIG_%s is not set" % config print("# CONFIG_%s is not set" % config)
else: else:
print "CONFIG_%s=%s" % (config, new_value) print("CONFIG_%s=%s" % (config, new_value))
else: else:
if op=="-": if op=="-":
print "-%s %s" % (config, value) print("-%s %s" % (config, value))
elif op=="+": elif op=="+":
print "+%s %s" % (config, new_value) print("+%s %s" % (config, new_value))
else: else:
print " %s %s -> %s" % (config, value, new_value) print(" %s %s -> %s" % (config, value, new_value))
def main(): def main():
global merge_style global merge_style
# parse command line args # parse command line args
if ("-h" in sys.argv or "--help" in sys.argv): if ("-h" in sys.argv or "--help" in sys.argv):
usage() usage()
merge_style = 0 merge_style = 0
if "-m" in sys.argv: if "-m" in sys.argv:
...@@ -79,15 +79,14 @@ def main(): ...@@ -79,15 +79,14 @@ def main():
argc = len(sys.argv) argc = len(sys.argv)
if not (argc==1 or argc == 3): if not (argc==1 or argc == 3):
print "Error: incorrect number of arguments or unrecognized option" print("Error: incorrect number of arguments or unrecognized option")
usage() usage()
if argc == 1: if argc == 1:
# if no filenames given, assume .config and .config.old # if no filenames given, assume .config and .config.old
build_dir="" build_dir=""
if os.environ.has_key("KBUILD_OUTPUT"): if "KBUILD_OUTPUT" in os.environ:
build_dir = os.environ["KBUILD_OUTPUT"]+"/" build_dir = os.environ["KBUILD_OUTPUT"]+"/"
configa_filename = build_dir + ".config.old" configa_filename = build_dir + ".config.old"
configb_filename = build_dir + ".config" configb_filename = build_dir + ".config"
else: else:
...@@ -95,8 +94,8 @@ def main(): ...@@ -95,8 +94,8 @@ def main():
configb_filename = sys.argv[2] configb_filename = sys.argv[2]
try: try:
a = readconfig(file(configa_filename)) a = readconfig(open(configa_filename))
b = readconfig(file(configb_filename)) b = readconfig(open(configb_filename))
except (IOError): except (IOError):
e = sys.exc_info()[1] e = sys.exc_info()[1]
print("I/O error[%s]: %s\n" % (e.args[0],e.args[1])) print("I/O error[%s]: %s\n" % (e.args[0],e.args[1]))
...@@ -126,8 +125,7 @@ def main(): ...@@ -126,8 +125,7 @@ def main():
# now print items in b but not in a # now print items in b but not in a
# (items from b that were in a were removed above) # (items from b that were in a were removed above)
new = b.keys() new = sorted(b.keys())
new.sort()
for config in new: for config in new:
print_config("+", config, None, b[config]) print_config("+", config, None, b[config])
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册