From 1ccc5efffc9ca96f24acb98887cdd4759d9e541f Mon Sep 17 00:00:00 2001 From: "Marty E. Plummer" Date: Fri, 10 May 2019 03:42:13 -0500 Subject: sbeCompression: add a python3 compatible fallback 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 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' Change-Id: Iea3109cb51266161629d6e09e79af63af0bbd08c Signed-off-by: Marty E. Plummer Signed-off-by: vinaybs6 Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/89370 Tested-by: Jenkins Server Tested-by: FSP CI Jenkins Reviewed-by: Srikantha S. Meesala Reviewed-by: RAJA DAS --- src/boot/sbeCompression.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/boot') diff --git a/src/boot/sbeCompression.py b/src/boot/sbeCompression.py index 74988e26..82ec90ca 100755 --- a/src/boot/sbeCompression.py +++ b/src/boot/sbeCompression.py @@ -68,7 +68,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 = [] -- cgit v1.2.1