It is ok to directly use below code without python version check?
+for loop in range(int(unit)):
+bytearray.append("0x%02X" % (value & 0xFF))
+value = value >> 8
Thanks,
Star
-Original Message-
From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of Chiu,
Chasel
Sent: Monday, June 24, 2019 10:35 PM
To: devel@edk2.groups.io
Cc: Ma, Maurice ; Desimone, Nathaniel L
; Zeng, Star
Subject: [edk2-devel] [PATCH] IntelFsp2Pkg: FSP Python scripts to support 3.x.
https://bugzilla.tianocore.org/show_bug.cgi?id=1930
Updated FSP Python scripts to support both 2.x and 3.x.
Test:
. Verified with Python 2.7.12 and 3.6.6.
. Verified tool result is the same before the change.
. Both py -2 and py -3 built binary can boot.
Cc: Maurice Ma
Cc: Nate DeSimone
Cc: Star Zeng
Signed-off-by: Chasel Chiu
---
IntelFsp2Pkg/Tools/GenCfgOpt.py | 70
++
IntelFsp2Pkg/Tools/PatchFv.py | 36 +++-
IntelFsp2Pkg/Tools/SplitFspBin.py | 74
+++---
3 files changed, 116 insertions(+), 64 deletions(-)
diff --git a/IntelFsp2Pkg/Tools/GenCfgOpt.py b/IntelFsp2Pkg/Tools/GenCfgOpt.py
index 450c4e3eb9..e0441966ac 100644
--- a/IntelFsp2Pkg/Tools/GenCfgOpt.py
+++ b/IntelFsp2Pkg/Tools/GenCfgOpt.py
@@ -1,6 +1,6 @@
## @ GenCfgOpt.py
#
-# Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) 2014 - 2019, Intel Corporation. All rights
+reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -10,6 +10,7 @@ import
re import sys import struct
from datetime import date
+from functools import reduce
# Generated file copyright header
@@ -90,11 +91,11 @@ class CLogicalExpression:
self.string = ''
def errExit(self, err = ''):
-print "ERROR: Express parsing for:"
-print " %s" % self.string
-print " %s^" % (' ' * self.index)
+print ("ERROR: Express parsing for:")
+print (" %s" % self.string)
+print (" %s^" % (' ' * self.index))
if err:
-print "INFO : %s" % err
+print ("INFO : %s" % err)
raise SystemExit
def getNonNumber (self, n1, n2):
@@ -338,15 +339,15 @@ EndList
else:
Error = 0
if self.Debug:
-print "INFO : Macro dictionary:"
+print ("INFO : Macro dictionary:")
for Each in self._MacroDict:
-print " $(%s) = [ %s ]" % (Each ,
self._MacroDict[Each])
+print (" $(%s) = [ %s ]" % (Each ,
self._MacroDict[Each]))
return Error
def EvaulateIfdef (self, Macro):
Result = Macro in self._MacroDict
if self.Debug:
-print "INFO : Eval Ifdef [%s] : %s" % (Macro, Result)
+print ("INFO : Eval Ifdef [%s] : %s" % (Macro, Result))
return Result
def ExpandMacros (self, Input):
@@ -359,7 +360,7 @@ EndList
Line = Line.replace(Each, self._MacroDict[Variable])
else:
if self.Debug:
- print "WARN : %s is not defined" % Each
+ print ("WARN : %s is not defined" % Each)
Line = Line.replace(Each, Each[2:-1])
return Line
@@ -372,7 +373,7 @@ EndList
Line = Line.replace(PcdName, self._PcdsDict[PcdName])
else:
if self.Debug:
- print "WARN : %s is not defined" % PcdName
+ print ("WARN : %s is not defined" % PcdName)
return Line
def EvaluateExpress (self, Expr):
@@ -381,7 +382,7 @@ EndList
LogExpr = CLogicalExpression()
Result = LogExpr.evaluateExpress (ExpExpr)
if self.Debug:
-print "INFO : Eval Express [%s] : %s" % (Expr, Result)
+print ("INFO : Eval Express [%s] : %s" % (Expr, Result))
return Result
def FormatListValue(self, ConfigDict):
@@ -406,9 +407,14 @@ EndList
bytearray = []
for each in dataarray:
value = each
-for loop in xrange(unit):
-bytearray.append("0x%02X" % (value & 0xFF))
-value = value >> 8
+if sys.version_info < (3,0):
+for loop in xrange(unit):
+bytearray.append("0x%02X" % (value & 0xFF))
+value = value >> 8
+else:
+for loop in range(int(unit)):
+bytearray.append("0x%02X" % (value & 0xFF))
+value = value >> 8
newvalue = '{' + ','.join(bytearray) + '}'
ConfigDict['value'] = newvalue
return ""
@@ -548,7 +554,7 @@ EndList
if Match: