[OpenPower-Firmware] [RFC PATCH 5/6] sbeCompression: add a python3 compatible fallback

Marty E. Plummer hanetzer at startmail.com
Fri May 10 19:35:08 AEST 2019


In python3.x dict.items() does (more or less) what dict.iteritems() did
in python2.x, but dict.iteritems() was removed in python3.x entirely.
Further, dict.items() in python2.7 is less efficient than dict.iteritems(),
so we attempt to use dict.iteritems(), and if that throws an AttributeError,
(which would happen on python3.x), fall back to dict.items().

Without this change, building with python3.x (python3.5 tested) as
/usr/bin/python will result in the following error:

Traceback (most recent call last):
  File "sbe/src/boot/sbeCompress
ion.py", line 198, in <module>
    main( sys.argv )
  File "sbe/src/boot/sbeCompression.py", line 181, in main
    compress(imagePath + "/" + image + ".base", imagePath + "/" + image + ".base.compressed")
  File "sbe/src/boot/sbeCompression.py", line 72, in compress
    sortedList =  sorted(instDict.iteritems(), key=operator.itemgetter(1), reverse = True)
AttributeError: 'dict' object has no attribute 'iteritems'

Signed-off-by: Marty E. Plummer <hanetzer at startmail.com>
---
 src/boot/sbeCompression.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/boot/sbeCompression.py b/src/boot/sbeCompression.py
index b6da858c..24708534 100755
--- a/src/boot/sbeCompression.py
+++ b/src/boot/sbeCompression.py
@@ -69,7 +69,10 @@ def compress(inputFile, compressedFile):
           iCount = 1
           instDict[fourByt] = iCount
 
-    sortedList =  sorted(instDict.iteritems(), key=operator.itemgetter(1), reverse = True)
+    try:
+        sortedList =  sorted(instDict.iteritems(), key=operator.itemgetter(1), reverse = True)
+    except AttributeError:
+        sortedList =  sorted(instDict.items(), key=operator.itemgetter(1), reverse = True)
 
     sortedList[256:] = []
     instList = []
-- 
2.21.0



More information about the OpenPower-Firmware mailing list