Skip to contentSkip to conversation

Modification of the diffconfig script to support python 3.x and 2.7

PATCH In review Mike Pagano 2 participants 3 messages Jul 5, 2013 – Jul 8, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Modification of the diffconfig script to support python 3.x and 2.7

Modification of the diffconfig script to support both python 2.7 and 3.2. Added a small change to gracefully exit if the default config files are not present. (.config and .config.old)

Diffconfig is a utility script for comparing kernel configuration files.

---
 scripts/diffconfig | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)
scripts/diffconfig +19 -13
index b91f3e3..45a4ba4 100755
@@ -10,7 +10,7 @@
 import sys, os
 
 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.
 Using standard diff to compare .config files often includes extraneous and
@@ -33,7 +33,7 @@ Example usage:
  EXT2_FS  y -> n
  LOG_BUF_SHIFT  14 -> 16
  PRINTK_TIME  n -> y
-"""
+""")
     sys.exit(0)
 
 # returns a dictionary of name/value pairs for config items in the file
@@ -54,23 +54,26 @@ def print_config(op, config, value, new_value):
     if merge_style:
         if new_value:
             if new_value=="n":
-                print "# CONFIG_%s is not set" % config
+                print ("# CONFIG_%s is not set" % config)
             else:
-                print "CONFIG_%s=%s" % (config, new_value)
+                print ("CONFIG_%s=%s" % (config, new_value))
     else:
         if op=="-":
-            print "-%s %s" % (config, value)
+            print ("-%s %s" % (config, value))
         elif op=="+":
-            print "+%s %s" % (config, new_value)
+            print ("+%s %s" % (config, new_value))
         else:
-            print " %s %s -> %s" % (config, value, new_value)
+            print (" %s %s -> %s" % (config, value, new_value))
 
 def main():
     global merge_style
 
+    a = {}
+    b = {}
+
     # parse command line args
     if ("-h" in sys.argv or "--help" in sys.argv):
-	usage()
+        usage()
 
     merge_style = 0
     if "-m" in sys.argv:
@@ -79,13 +82,13 @@ def main():
 
     argc = len(sys.argv)
     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()
 
     if argc == 1:
         # if no filenames given, assume .config and .config.old
         build_dir=""
-        if os.environ.has_key("KBUILD_OUTPUT"):
+        if "KBUILD_OUTPUT" in os.environ:
             build_dir = os.environ["KBUILD_OUTPUT"]+"/"
 
         configa_filename = build_dir + ".config.old"
@@ -94,8 +97,11 @@ def main():
         configa_filename = sys.argv[1]
         configb_filename = sys.argv[2]
 
-    a = readconfig(file(configa_filename))
-    b = readconfig(file(configb_filename))
+    try:
+        a = readconfig(open(configa_filename))
+        b = readconfig(open(configb_filename))
+    except IOError:
+        usage()
 
     # print items in a but not b (accumulate, sort and print)
     old = []
@@ -121,7 +127,7 @@ def main():
 
     # now print items in b but not in a
     # (items from b that were in a were removed above)
-    new = b.keys()
+    new = list(b.keys())
     new.sort()
     for config in new:
         print_config("+", config, None, b[config])
Signature · 1 line
1.8.1.5
#1 lore raw

On Thu, 04 Jul 2013 20:19:03 -0400, Mike Pagano said:

I'm not a snake-language person, but...

Quoted 16 lines

Modification of the diffconfig script to support both python 2.7 and 3.2. Added a small change to gracefully exit if the default config files are not present. (.config and .config.old)

Diffconfig is a utility script for comparing kernel configuration files.

---
 scripts/diffconfig | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)
scripts/diffconfig +0 -0
index b91f3e3..45a4ba4 100755

scripts/diffconfig line 13

Quoted 5 lines
scripts/diffconfig +1 -1
@@ -10,7 +10,7 @@
 import sys, os
 
 def usage():
-    print """Usage: diffconfig [-h] [-m] [<config1> <config2>]
+    print ("""Usage: diffconfig [-h] [-m] [<config1> <config2>]

Is this hunk missing a ) at the end of the line?

#2 lore raw
Quoted 8 lines · On Mon, Jul 08, 2013 at 03:14:43PM -0400, [email protected] wrote:

On Thu, 04 Jul 2013 20:19:03 -0400, Mike Pagano said:

I'm not a snake-language person, but...

scripts/diffconfig line 13

Quoted 2 lines
scripts/diffconfig +1 -1
-    print """Usage: diffconfig [-h] [-m] [<config1> <config2>]
+    print ("""Usage: diffconfig [-h] [-m] [<config1> <config2>]

Is this hunk missing a ) at the end of the line?

No, there's a lot of lines in bewteen the first ( and the closing one which is added in the patch:

-"""
+""")

Signature · 6 lines
Mike Pagano
Gentoo Developer - Kernel Project
Gentoo Sources - Lead 
E-Mail     : [email protected]
GnuPG FP   : EEE2 601D 0763 B60F 848C  9E14 3C33 C650 B576 E4E3
Public Key : http://pgp.mit.edu:11371/pks/lookup?search=0xB576E4E3&op=index