Skip to content

Commit

Permalink
sbeCompression: add a python3 compatible fallback
Browse files Browse the repository at this point in the history
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'

Change-Id: Iea3109cb51266161629d6e09e79af63af0bbd08c
Signed-off-by: Marty E. Plummer <hanetzer@startmail.com>
Signed-off-by: vinaybs6 <vinaybs6@in.ibm.com>
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/89370
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Reviewed-by: Srikantha S. Meesala <srikantha@in.ibm.com>
Reviewed-by: RAJA DAS <rajadas2@in.ibm.com>
  • Loading branch information
hanetzer authored and RAJA DAS committed Jan 10, 2020
1 parent 629327d commit 1ccc5ef
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/boot/sbeCompression.py
Expand Up @@ -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 = []
Expand Down

0 comments on commit 1ccc5ef

Please sign in to comment.