[U-Boot] [RFC PATCH 1/2] kconfig: make multiconfig.py compatible with Python 2.4

Masahiro Yamada yamada.m at jp.panasonic.com
Mon Aug 4 12:10:45 CEST 2014


The statements "with ... as ..." and "exception ... as ..."
are available in Python 2.6 or lator. Do not use them.
Tested on Python 2.4.6.

Signed-off-by: Masahiro Yamada <yamada.m at jp.panasonic.com>
---

 scripts/multiconfig.py | 73 +++++++++++++++++++++++---------------------------
 1 file changed, 34 insertions(+), 39 deletions(-)

diff --git a/scripts/multiconfig.py b/scripts/multiconfig.py
index 749abcb..de5ec51 100755
--- a/scripts/multiconfig.py
+++ b/scripts/multiconfig.py
@@ -165,7 +165,7 @@ def mkdirs(*dirs):
     for d in dirs:
         try:
             os.makedirs(d)
-        except OSError as exception:
+        except OSError, exception:
             # Ignore 'File exists' error
             if exception.errno != errno.EEXIST:
                 raise
@@ -175,7 +175,7 @@ def rmfiles(*files):
     for f in files:
         try:
             os.remove(f)
-        except OSError as exception:
+        except OSError, exception:
             # Ignore 'No such file or directory' error
             if exception.errno != errno.ENOENT:
                 raise
@@ -187,7 +187,7 @@ def rmdirs(*dirs):
     for d in dirs:
         try:
             os.rmdir(d)
-        except OSError as exception:
+        except OSError, exception:
             # Ignore 'No such file or directory'
             # and 'Directory not empty' error
             if exception.errno != errno.ENOENT and \
@@ -253,15 +253,14 @@ def get_enabled_subimages(ignore_error=False):
                                                         for img in SUB_IMAGES ]
     try:
         f = open(KCONFIG_CONFIG)
-    except IOError as exception:
+    except IOError, exception:
         if not ignore_error or exception.errno != errno.ENOENT:
             raise
         return enabled
-    with f:
-        for line in f:
-            for img, pattern in match_patterns:
-                if line == pattern:
-                    enabled += (img,)
+    for line in f:
+        for img, pattern in match_patterns:
+            if line == pattern:
+                enabled += (img,)
     return enabled
 
 def do_silentoldconfig(cmd):
@@ -307,8 +306,7 @@ def do_tmp_defconfig(output_lines, img):
     TMP_DIRS = ('arch', 'configs')
     defconfig_path = os.path.join('configs', TMP_DEFCONFIG)
     mkdirs(*TMP_DIRS)
-    with open(defconfig_path, 'w') as f:
-        f.write(''.join(output_lines[img]))
+    open(defconfig_path, 'w').write(''.join(output_lines[img]))
     cleanup = lambda: (rmfiles(defconfig_path), rmdirs(*TMP_DIRS))
     run_make_config(TMP_DEFCONFIG, img, cleanup)
     cleanup()
@@ -321,15 +319,14 @@ def do_board_defconfig(cmd):
     """
     defconfig_path = os.path.join(srctree, 'configs', cmd)
     output_lines = dict([ (img, []) for img in IMAGES ])
-    with open(defconfig_path) as f:
-        for line in f:
-            m = PATTERN_SYMBOL.match(line)
-            if m:
-                for idx, img in enumerate(IMAGES):
-                    if m.group(idx + 1):
-                        output_lines[img].append(m.group(4) + '\n')
-                continue
-            output_lines[''].append(line)
+    for line in open(defconfig_path):
+        m = PATTERN_SYMBOL.match(line)
+        if m:
+            for idx, img in enumerate(IMAGES):
+                if m.group(idx + 1):
+                    output_lines[img].append(m.group(4) + '\n')
+            continue
+        output_lines[''].append(line)
     do_tmp_defconfig(output_lines, '')
     for img in get_enabled_subimages():
         do_tmp_defconfig(output_lines, img)
@@ -356,29 +353,27 @@ def do_savedefconfig(cmd):
     run_make_config(cmd, '')
     output_lines = []
     prefix = {}
-    with open(DEFCONFIG) as f:
-        for line in f:
-            output_lines.append(line)
-            prefix[line] = '+'
+    for line in open(DEFCONFIG):
+        output_lines.append(line)
+        prefix[line] = '+'
     for img in subimages:
         run_make_config(cmd, img)
         unmatched_lines = []
-        with open(DEFCONFIG) as f:
-            for line in f:
-                if line in output_lines:
-                    index = output_lines.index(line)
-                    output_lines[index:index] = unmatched_lines
-                    unmatched_lines = []
-                    prefix[line] += SYMBOL_MAP[img]
-                else:
-                    ummatched_lines.append(line)
-                    prefix[line] = SYMBOL_MAP[img]
-    with open(DEFCONFIG, 'w') as f:
-        for line in output_lines:
-            if prefix[line] == '+':
-                f.write(line)
+        for line in open(DEFCONFIG):
+            if line in output_lines:
+                index = output_lines.index(line)
+                output_lines[index:index] = unmatched_lines
+                unmatched_lines = []
+                prefix[line] += SYMBOL_MAP[img]
             else:
-                f.write(prefix[line] + ':' + line)
+                ummatched_lines.append(line)
+                prefix[line] = SYMBOL_MAP[img]
+    f = open(DEFCONFIG, 'w')
+    for line in output_lines:
+        if prefix[line] == '+':
+            f.write(line)
+        else:
+            f.write(prefix[line] + ':' + line)
 
 def do_others(cmd):
     """Run the make command other than 'silentoldconfig', 'defconfig',
-- 
1.9.1



More information about the U-Boot mailing list