diff options
author | Mike Pagano <mpagano@gentoo.org> | 2013-08-20 14:41:12 -0400 |
---|---|---|
committer | Michal Marek <mmarek@suse.cz> | 2013-09-01 15:24:51 -0400 |
commit | c8272faf5e3f0f97f5cd15af69e3a515efbe212d (patch) | |
tree | 9224c33293e730162f8bd4b5d239ff48d95371cc /scripts | |
parent | 6bf2e84b8cebc4c53bf44343ed4e9b88aa73e34d (diff) |
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: Mike Pagano <mpagano@gentoo.org>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/diffconfig | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/scripts/diffconfig b/scripts/diffconfig index 0ee65839f7aa..6d672836e187 100755 --- a/scripts/diffconfig +++ b/scripts/diffconfig | |||
@@ -10,7 +10,7 @@ | |||
10 | import sys, os | 10 | import sys, os |
11 | 11 | ||
12 | def usage(): | 12 | def usage(): |
13 | print """Usage: diffconfig [-h] [-m] [<config1> <config2>] | 13 | print("""Usage: diffconfig [-h] [-m] [<config1> <config2>] |
14 | 14 | ||
15 | Diffconfig is a simple utility for comparing two .config files. | 15 | Diffconfig is a simple utility for comparing two .config files. |
16 | Using standard diff to compare .config files often includes extraneous and | 16 | Using standard diff to compare .config files often includes extraneous and |
@@ -33,7 +33,7 @@ Example usage: | |||
33 | EXT2_FS y -> n | 33 | EXT2_FS y -> n |
34 | LOG_BUF_SHIFT 14 -> 16 | 34 | LOG_BUF_SHIFT 14 -> 16 |
35 | PRINTK_TIME n -> y | 35 | PRINTK_TIME n -> y |
36 | """ | 36 | """) |
37 | sys.exit(0) | 37 | sys.exit(0) |
38 | 38 | ||
39 | # returns a dictionary of name/value pairs for config items in the file | 39 | # 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 | if merge_style: | 54 | if merge_style: |
55 | if new_value: | 55 | if new_value: |
56 | if new_value=="n": | 56 | if new_value=="n": |
57 | print "# CONFIG_%s is not set" % config | 57 | print("# CONFIG_%s is not set" % config) |
58 | else: | 58 | else: |
59 | print "CONFIG_%s=%s" % (config, new_value) | 59 | print("CONFIG_%s=%s" % (config, new_value)) |
60 | else: | 60 | else: |
61 | if op=="-": | 61 | if op=="-": |
62 | print "-%s %s" % (config, value) | 62 | print("-%s %s" % (config, value)) |
63 | elif op=="+": | 63 | elif op=="+": |
64 | print "+%s %s" % (config, new_value) | 64 | print("+%s %s" % (config, new_value)) |
65 | else: | 65 | else: |
66 | print " %s %s -> %s" % (config, value, new_value) | 66 | print(" %s %s -> %s" % (config, value, new_value)) |
67 | 67 | ||
68 | def main(): | 68 | def main(): |
69 | global merge_style | 69 | global merge_style |
70 | 70 | ||
71 | # parse command line args | 71 | # parse command line args |
72 | if ("-h" in sys.argv or "--help" in sys.argv): | 72 | if ("-h" in sys.argv or "--help" in sys.argv): |
73 | usage() | 73 | usage() |
74 | 74 | ||
75 | merge_style = 0 | 75 | merge_style = 0 |
76 | if "-m" in sys.argv: | 76 | if "-m" in sys.argv: |
@@ -79,15 +79,14 @@ def main(): | |||
79 | 79 | ||
80 | argc = len(sys.argv) | 80 | argc = len(sys.argv) |
81 | if not (argc==1 or argc == 3): | 81 | if not (argc==1 or argc == 3): |
82 | print "Error: incorrect number of arguments or unrecognized option" | 82 | print("Error: incorrect number of arguments or unrecognized option") |
83 | usage() | 83 | usage() |
84 | 84 | ||
85 | if argc == 1: | 85 | if argc == 1: |
86 | # if no filenames given, assume .config and .config.old | 86 | # if no filenames given, assume .config and .config.old |
87 | build_dir="" | 87 | build_dir="" |
88 | if os.environ.has_key("KBUILD_OUTPUT"): | 88 | if "KBUILD_OUTPUT" in os.environ: |
89 | build_dir = os.environ["KBUILD_OUTPUT"]+"/" | 89 | build_dir = os.environ["KBUILD_OUTPUT"]+"/" |
90 | |||
91 | configa_filename = build_dir + ".config.old" | 90 | configa_filename = build_dir + ".config.old" |
92 | configb_filename = build_dir + ".config" | 91 | configb_filename = build_dir + ".config" |
93 | else: | 92 | else: |
@@ -95,8 +94,8 @@ def main(): | |||
95 | configb_filename = sys.argv[2] | 94 | configb_filename = sys.argv[2] |
96 | 95 | ||
97 | try: | 96 | try: |
98 | a = readconfig(file(configa_filename)) | 97 | a = readconfig(open(configa_filename)) |
99 | b = readconfig(file(configb_filename)) | 98 | b = readconfig(open(configb_filename)) |
100 | except (IOError): | 99 | except (IOError): |
101 | e = sys.exc_info()[1] | 100 | e = sys.exc_info()[1] |
102 | print("I/O error[%s]: %s\n" % (e.args[0],e.args[1])) | 101 | print("I/O error[%s]: %s\n" % (e.args[0],e.args[1])) |
@@ -126,8 +125,7 @@ def main(): | |||
126 | 125 | ||
127 | # now print items in b but not in a | 126 | # now print items in b but not in a |
128 | # (items from b that were in a were removed above) | 127 | # (items from b that were in a were removed above) |
129 | new = b.keys() | 128 | new = sorted(b.keys()) |
130 | new.sort() | ||
131 | for config in new: | 129 | for config in new: |
132 | print_config("+", config, None, b[config]) | 130 | print_config("+", config, None, b[config]) |
133 | 131 | ||