BaseTools: Refactor python print statements

Refactor print statements to be compatible with python 3.
Based on "futurize -f libfuturize.fixes.fix_print_with_import"

Contributed-under: TianoCore Contribution Agreement 1.1
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
Gary Lin
2018-06-25 18:31:26 +08:00
committed by Yonghong Zhu
parent 5b0671c1e5
commit 72443dd250
46 changed files with 354 additions and 308 deletions

View File

@@ -15,6 +15,7 @@
## Import Modules
#
from __future__ import print_function
import Common.LongFilePathOs as os
import re
import os.path as path
@@ -688,7 +689,7 @@ class WorkspaceAutoGen(AutoGen):
os.makedirs(self.BuildDir)
with open(os.path.join(self.BuildDir, 'AutoGen'), 'w+') as file:
for f in AllWorkSpaceMetaFiles:
print >> file, f
print(f, file=file)
return True
def _GenPkgLevelHash(self, Pkg):
@@ -4362,7 +4363,7 @@ class ModuleAutoGen(AutoGen):
os.remove (self.GetTimeStampPath())
with open(self.GetTimeStampPath(), 'w+') as file:
for f in FileSet:
print >> file, f
print(f, file=file)
Module = property(_GetModule)
Name = property(_GetBaseName)

View File

@@ -14,6 +14,7 @@
##
# Import Modules
#
from __future__ import print_function
import Common.LongFilePathOs as os
import re
import copy
@@ -597,19 +598,19 @@ if __name__ == '__main__':
EdkLogger.Initialize()
if len(sys.argv) > 1:
Br = BuildRule(sys.argv[1])
print str(Br[".c", SUP_MODULE_DXE_DRIVER, "IA32", "MSFT"][1])
print
print str(Br[".c", SUP_MODULE_DXE_DRIVER, "IA32", "INTEL"][1])
print
print str(Br[".c", SUP_MODULE_DXE_DRIVER, "IA32", "GCC"][1])
print
print str(Br[".ac", "ACPI_TABLE", "IA32", "MSFT"][1])
print
print str(Br[".h", "ACPI_TABLE", "IA32", "INTEL"][1])
print
print str(Br[".ac", "ACPI_TABLE", "IA32", "MSFT"][1])
print
print str(Br[".s", SUP_MODULE_SEC, "IPF", "COMMON"][1])
print
print str(Br[".s", SUP_MODULE_SEC][1])
print(str(Br[".c", SUP_MODULE_DXE_DRIVER, "IA32", "MSFT"][1]))
print()
print(str(Br[".c", SUP_MODULE_DXE_DRIVER, "IA32", "INTEL"][1]))
print()
print(str(Br[".c", SUP_MODULE_DXE_DRIVER, "IA32", "GCC"][1]))
print()
print(str(Br[".ac", "ACPI_TABLE", "IA32", "MSFT"][1]))
print()
print(str(Br[".h", "ACPI_TABLE", "IA32", "INTEL"][1]))
print()
print(str(Br[".ac", "ACPI_TABLE", "IA32", "MSFT"][1]))
print()
print(str(Br[".s", SUP_MODULE_SEC, "IPF", "COMMON"][1]))
print()
print(str(Br[".s", SUP_MODULE_SEC][1]))

View File

@@ -16,6 +16,7 @@
##
# Import Modules
#
from __future__ import print_function
import Common.LongFilePathOs as os, codecs, re
import distutils.util
import Common.EdkLogger as EdkLogger
@@ -684,12 +685,12 @@ class UniFileClassObject(object):
# Show the instance itself
#
def ShowMe(self):
print self.LanguageDef
print(self.LanguageDef)
#print self.OrderedStringList
for Item in self.OrderedStringList:
print Item
print(Item)
for Member in self.OrderedStringList[Item]:
print str(Member)
print(str(Member))
# This acts like the main() function for the script, unless it is 'import'ed into another
# script.

View File

@@ -20,6 +20,7 @@
##
# Import Modules
#
from __future__ import print_function
import Common.LongFilePathOs as os
import sys
import encodings.ascii
@@ -132,7 +133,7 @@ def MyOptionParser():
#
def StartBpdg(InputFileName, MapFileName, VpdFileName, Force):
if os.path.exists(VpdFileName) and not Force:
print "\nFile %s already exist, Overwrite(Yes/No)?[Y]: " % VpdFileName
print("\nFile %s already exist, Overwrite(Yes/No)?[Y]: " % VpdFileName)
choice = sys.stdin.readline()
if choice.strip().lower() not in ['y', 'yes', '']:
return

View File

@@ -12,6 +12,7 @@
## Import Modules
#
from __future__ import print_function
from Common.GlobalData import *
from CommonDataClass.Exceptions import BadExpression
from CommonDataClass.Exceptions import WrnExpression
@@ -1028,10 +1029,10 @@ if __name__ == '__main__':
if input in 'qQ':
break
try:
print ValueExpression(input)(True)
print ValueExpression(input)(False)
print(ValueExpression(input)(True))
print(ValueExpression(input)(False))
except WrnExpression as Ex:
print Ex.result
print str(Ex)
print(Ex.result)
print(str(Ex))
except Exception as Ex:
print str(Ex)
print(str(Ex))

View File

@@ -12,6 +12,7 @@
# # Import Modules
#
from __future__ import print_function
from Common.GlobalData import *
from CommonDataClass.Exceptions import BadExpression
from CommonDataClass.Exceptions import WrnExpression
@@ -85,11 +86,11 @@ class RangeContainer(object):
self.__clean__()
def dump(self):
print "----------------------"
print("----------------------")
rangelist = ""
for object in self.rangelist:
rangelist = rangelist + "[%d , %d]" % (object.start, object.end)
print rangelist
print(rangelist)
class XOROperatorObject(object):

View File

@@ -14,6 +14,7 @@
##
# Import Modules
#
from __future__ import print_function
import Common.LongFilePathOs as os
import EdkLogger
import DataType
@@ -158,6 +159,6 @@ def TargetTxtDict(ConfDir):
if __name__ == '__main__':
pass
Target = TargetTxtDict(os.getenv("WORKSPACE"))
print Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER]
print Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TARGET]
print Target.TargetTxtDictionary
print(Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER])
print(Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TARGET])
print(Target.TargetTxtDictionary)

View File

@@ -15,6 +15,7 @@
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
from __future__ import print_function
import Common.LongFilePathOs as os
import re
import Common.EdkLogger as EdkLogger
@@ -248,7 +249,7 @@ def CallExtenalBPDGTool(ToolPath, VpdFileName):
except Exception as X:
EdkLogger.error("BPDG", BuildToolError.COMMAND_FAILURE, ExtraData=str(X))
(out, error) = PopenObject.communicate()
print out
print(out)
while PopenObject.returncode is None :
PopenObject.wait()

View File

@@ -1,5 +1,6 @@
# $ANTLR 3.0.1 C.g 2010-02-23 09:58:53
from __future__ import print_function
from antlr3 import *
from antlr3.compat import set, frozenset
@@ -102,8 +103,8 @@ class CParser(Parser):
self.postfix_expression_stack = []
def printTokenInfo(self, line, offset, tokenText):
print str(line)+ ',' + str(offset) + ':' + str(tokenText)
print(str(line)+ ',' + str(offset) + ':' + str(tokenText))
def StorePredicateExpression(self, StartLine, StartOffset, EndLine, EndOffset, Text):
PredExp = CodeFragment.PredicateExpression(Text, (StartLine, StartOffset), (EndLine, EndOffset))
FileProfile.PredicateExpressionList.append(PredExp)

View File

@@ -16,6 +16,7 @@
# Import Modules
#
from __future__ import print_function
import re
import Common.LongFilePathOs as os
import sys
@@ -533,58 +534,58 @@ class CodeFragmentCollector:
def PrintFragments(self):
print '################# ' + self.FileName + '#####################'
print('################# ' + self.FileName + '#####################')
print '/****************************************/'
print '/*************** COMMENTS ***************/'
print '/****************************************/'
print('/****************************************/')
print('/*************** COMMENTS ***************/')
print('/****************************************/')
for comment in FileProfile.CommentList:
print str(comment.StartPos) + comment.Content
print(str(comment.StartPos) + comment.Content)
print '/****************************************/'
print '/********* PREPROCESS DIRECTIVES ********/'
print '/****************************************/'
print('/****************************************/')
print('/********* PREPROCESS DIRECTIVES ********/')
print('/****************************************/')
for pp in FileProfile.PPDirectiveList:
print str(pp.StartPos) + pp.Content
print(str(pp.StartPos) + pp.Content)
print '/****************************************/'
print '/********* VARIABLE DECLARATIONS ********/'
print '/****************************************/'
print('/****************************************/')
print('/********* VARIABLE DECLARATIONS ********/')
print('/****************************************/')
for var in FileProfile.VariableDeclarationList:
print str(var.StartPos) + var.Modifier + ' '+ var.Declarator
print(str(var.StartPos) + var.Modifier + ' '+ var.Declarator)
print '/****************************************/'
print '/********* FUNCTION DEFINITIONS *********/'
print '/****************************************/'
print('/****************************************/')
print('/********* FUNCTION DEFINITIONS *********/')
print('/****************************************/')
for func in FileProfile.FunctionDefinitionList:
print str(func.StartPos) + func.Modifier + ' '+ func.Declarator + ' ' + str(func.NamePos)
print(str(func.StartPos) + func.Modifier + ' '+ func.Declarator + ' ' + str(func.NamePos))
print '/****************************************/'
print '/************ ENUMERATIONS **************/'
print '/****************************************/'
print('/****************************************/')
print('/************ ENUMERATIONS **************/')
print('/****************************************/')
for enum in FileProfile.EnumerationDefinitionList:
print str(enum.StartPos) + enum.Content
print(str(enum.StartPos) + enum.Content)
print '/****************************************/'
print '/*********** STRUCTS/UNIONS *************/'
print '/****************************************/'
print('/****************************************/')
print('/*********** STRUCTS/UNIONS *************/')
print('/****************************************/')
for su in FileProfile.StructUnionDefinitionList:
print str(su.StartPos) + su.Content
print(str(su.StartPos) + su.Content)
print '/****************************************/'
print '/********* PREDICATE EXPRESSIONS ********/'
print '/****************************************/'
print('/****************************************/')
print('/********* PREDICATE EXPRESSIONS ********/')
print('/****************************************/')
for predexp in FileProfile.PredicateExpressionList:
print str(predexp.StartPos) + predexp.Content
print(str(predexp.StartPos) + predexp.Content)
print '/****************************************/'
print '/************** TYPEDEFS ****************/'
print '/****************************************/'
print('/****************************************/')
print('/************** TYPEDEFS ****************/')
print('/****************************************/')
for typedef in FileProfile.TypedefDefinitionList:
print str(typedef.StartPos) + typedef.ToType
print(str(typedef.StartPos) + typedef.ToType)
if __name__ == "__main__":
collector = CodeFragmentCollector(sys.argv[1])
collector.PreprocessFile()
print "For Test."
print("For Test.")

View File

@@ -14,6 +14,7 @@
##
# Import Modules
#
from __future__ import print_function
import Common.LongFilePathOs as os
import Common.EdkLogger as EdkLogger
from Common.DataType import *
@@ -419,9 +420,9 @@ class Configuration(object):
self.__dict__[_ConfigFileToInternalTranslation[List[0]]] = List[1]
def ShowMe(self):
print self.Filename
print(self.Filename)
for Key in self.__dict__.keys():
print Key, '=', self.__dict__[Key]
print(Key, '=', self.__dict__[Key])
#
# test that our dict and out class still match in contents.

View File

@@ -14,6 +14,7 @@
##
# Import Modules
#
from __future__ import print_function
from Xml.XmlRoutines import *
import Common.LongFilePathOs as os
@@ -84,4 +85,4 @@ class ExceptionCheck(object):
#
if __name__ == '__main__':
El = ExceptionCheck('C:\\Hess\\Project\\BuildTool\\src\\Ecc\\exception.xml')
print El.ExceptionList
print(El.ExceptionList)

View File

@@ -14,6 +14,7 @@
##
# Import Modules
#
from __future__ import print_function
import Common.LongFilePathOs as os
import Common.EdkLogger as EdkLogger
@@ -99,7 +100,7 @@ class Table(object):
try:
self.Cur.execute(SqlCommand)
except Exception as e:
print "An error occurred when Drop a table:", e.args[0]
print("An error occurred when Drop a table:", e.args[0])
## Get count
#

View File

@@ -15,6 +15,7 @@
##
# Import Modules
#
from __future__ import print_function
import xml.dom.minidom
from Common.LongFilePathSupport import OpenLongFilePath as open
@@ -215,7 +216,7 @@ def XmlParseFile(FileName):
XmlFile.close()
return Dom
except Exception as X:
print X
print(X)
return ""
# This acts like the main() function for the script, unless it is 'import'ed
@@ -225,5 +226,5 @@ if __name__ == '__main__':
A = CreateXmlElement('AAA', 'CCC', [['AAA', '111'], ['BBB', '222']], [['A', '1'], ['B', '2']])
B = CreateXmlElement('ZZZ', 'CCC', [['XXX', '111'], ['YYY', '222']], [['A', '1'], ['B', '2']])
C = CreateXmlList('DDD', 'EEE', [A, B], ['FFF', 'GGG'])
print C.toprettyxml(indent = " ")
print(C.toprettyxml(indent = " "))
pass

View File

@@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
from __future__ import print_function
import sys
import Common.LongFilePathOs as os
import re
@@ -2285,7 +2286,7 @@ def CheckDoxygenTripleForwardSlash(FullFileName):
for Result in ResultSet:
CommentSet.append(Result)
except:
print 'Unrecognized chars in comment of file %s', FullFileName
print('Unrecognized chars in comment of file %s', FullFileName)
for Result in CommentSet:
@@ -2438,7 +2439,7 @@ def CheckFuncHeaderDoxygenComments(FullFileName):
for Result in ResultSet:
CommentSet.append(Result)
except:
print 'Unrecognized chars in comment of file %s', FullFileName
print('Unrecognized chars in comment of file %s', FullFileName)
# Func Decl check
SqlStatement = """ select Modifier, Name, StartLine, ID, Value
@@ -2469,7 +2470,7 @@ def CheckFuncHeaderDoxygenComments(FullFileName):
for Result in ResultSet:
CommentSet.append(Result)
except:
print 'Unrecognized chars in comment of file %s', FullFileName
print('Unrecognized chars in comment of file %s', FullFileName)
SqlStatement = """ select Modifier, Header, StartLine, ID, Name
from Function
@@ -2634,9 +2635,9 @@ if __name__ == '__main__':
try:
test_file = sys.argv[1]
except IndexError as v:
print "Usage: %s filename" % sys.argv[0]
print("Usage: %s filename" % sys.argv[0])
sys.exit(1)
MsgList = CheckFuncHeaderDoxygenComments(test_file)
for Msg in MsgList:
print Msg
print 'Done!'
print(Msg)
print('Done!')

View File

@@ -1,5 +1,6 @@
# $ANTLR 3.0.1 C.g 2010-02-23 09:58:53
from __future__ import print_function
from antlr3 import *
from antlr3.compat import set, frozenset
@@ -102,8 +103,8 @@ class CParser(Parser):
self.postfix_expression_stack = []
def printTokenInfo(self, line, offset, tokenText):
print str(line)+ ',' + str(offset) + ':' + str(tokenText)
print(str(line)+ ',' + str(offset) + ':' + str(tokenText))
def StorePredicateExpression(self, StartLine, StartOffset, EndLine, EndOffset, Text):
PredExp = CodeFragment.PredicateExpression(Text, (StartLine, StartOffset), (EndLine, EndOffset))
FileProfile.PredicateExpressionList.append(PredExp)

View File

@@ -15,6 +15,7 @@
##
# Import Modules
#
from __future__ import print_function
import re
import Common.LongFilePathOs as os
import sys
@@ -379,49 +380,49 @@ class CodeFragmentCollector:
#
def PrintFragments(self):
print '################# ' + self.FileName + '#####################'
print('################# ' + self.FileName + '#####################')
print '/****************************************/'
print '/*************** ASSIGNMENTS ***************/'
print '/****************************************/'
print('/****************************************/')
print('/*************** ASSIGNMENTS ***************/')
print('/****************************************/')
for asign in FileProfile.AssignmentExpressionList:
print str(asign.StartPos) + asign.Name + asign.Operator + asign.Value
print(str(asign.StartPos) + asign.Name + asign.Operator + asign.Value)
print '/****************************************/'
print '/********* PREPROCESS DIRECTIVES ********/'
print '/****************************************/'
print('/****************************************/')
print('/********* PREPROCESS DIRECTIVES ********/')
print('/****************************************/')
for pp in FileProfile.PPDirectiveList:
print str(pp.StartPos) + pp.Content
print(str(pp.StartPos) + pp.Content)
print '/****************************************/'
print '/********* VARIABLE DECLARATIONS ********/'
print '/****************************************/'
print('/****************************************/')
print('/********* VARIABLE DECLARATIONS ********/')
print('/****************************************/')
for var in FileProfile.VariableDeclarationList:
print str(var.StartPos) + var.Modifier + ' '+ var.Declarator
print(str(var.StartPos) + var.Modifier + ' '+ var.Declarator)
print '/****************************************/'
print '/********* FUNCTION DEFINITIONS *********/'
print '/****************************************/'
print('/****************************************/')
print('/********* FUNCTION DEFINITIONS *********/')
print('/****************************************/')
for func in FileProfile.FunctionDefinitionList:
print str(func.StartPos) + func.Modifier + ' '+ func.Declarator + ' ' + str(func.NamePos)
print(str(func.StartPos) + func.Modifier + ' '+ func.Declarator + ' ' + str(func.NamePos))
print '/****************************************/'
print '/************ ENUMERATIONS **************/'
print '/****************************************/'
print('/****************************************/')
print('/************ ENUMERATIONS **************/')
print('/****************************************/')
for enum in FileProfile.EnumerationDefinitionList:
print str(enum.StartPos) + enum.Content
print(str(enum.StartPos) + enum.Content)
print '/****************************************/'
print '/*********** STRUCTS/UNIONS *************/'
print '/****************************************/'
print('/****************************************/')
print('/*********** STRUCTS/UNIONS *************/')
print('/****************************************/')
for su in FileProfile.StructUnionDefinitionList:
print str(su.StartPos) + su.Content
print(str(su.StartPos) + su.Content)
print '/****************************************/'
print '/************** TYPEDEFS ****************/'
print '/****************************************/'
print('/****************************************/')
print('/************** TYPEDEFS ****************/')
print('/****************************************/')
for typedef in FileProfile.TypedefDefinitionList:
print str(typedef.StartPos) + typedef.ToType
print(str(typedef.StartPos) + typedef.ToType)
##
#
@@ -430,4 +431,4 @@ class CodeFragmentCollector:
#
if __name__ == "__main__":
print "For Test."
print("For Test.")

View File

@@ -14,6 +14,7 @@
##
# Import Modules
#
from __future__ import print_function
import Common.LongFilePathOs as os
import Common.EdkLogger as EdkLogger
from Common.DataType import *
@@ -164,8 +165,8 @@ if __name__ == '__main__':
Db.InitDatabase()
P = EdkInfParser(os.path.normpath("C:\Framework\Edk\Sample\Platform\Nt32\Dxe\PlatformBds\PlatformBds.inf"), Db, '', '')
for Inf in P.Sources:
print Inf
print(Inf)
for Item in P.Macros:
print Item, P.Macros[Item]
print(Item, P.Macros[Item])
Db.Close()
Db.Close()

View File

@@ -15,6 +15,7 @@
##
# Import Modules
#
from __future__ import print_function
import sys
import Common.LongFilePathOs as os
import re
@@ -384,4 +385,4 @@ if __name__ == '__main__':
EdkLogger.SetLevel(EdkLogger.QUIET)
CollectSourceCodeDataIntoDB(sys.argv[1])
print 'Done!'
print('Done!')

View File

@@ -16,6 +16,7 @@
##
# Import Modules
#
from __future__ import print_function
import re
import Fd
@@ -4777,7 +4778,7 @@ if __name__ == "__main__":
try:
test_file = sys.argv[1]
except IndexError as v:
print "Usage: %s filename" % sys.argv[0]
print("Usage: %s filename" % sys.argv[0])
sys.exit(1)
parser = FdfParser(test_file)
@@ -4785,7 +4786,7 @@ if __name__ == "__main__":
parser.ParseFile()
parser.CycleReferenceCheck()
except Warning as X:
print str(X)
print(str(X))
else:
print "Success!"
print("Success!")

View File

@@ -15,6 +15,7 @@
##
# Import Modules
#
from __future__ import print_function
from optparse import OptionParser
import sys
import Common.LongFilePathOs as os
@@ -689,7 +690,7 @@ class GenFds :
ModuleDict = BuildDb.BuildObject[DscFile, TAB_COMMON, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag].Modules
for Key in ModuleDict:
ModuleObj = BuildDb.BuildObject[Key, TAB_COMMON, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
print ModuleObj.BaseName + ' ' + ModuleObj.ModuleType
print(ModuleObj.BaseName + ' ' + ModuleObj.ModuleType)
def GenerateGuidXRefFile(BuildDb, ArchList, FdfParserObj):
GuidXRefFileName = os.path.join(GenFdsGlobalVariable.FvDir, "Guid.xref")

View File

@@ -15,6 +15,7 @@
##
# Import Modules
#
from __future__ import print_function
import Common.LongFilePathOs as os
import sys
import subprocess
@@ -736,7 +737,7 @@ class GenFdsGlobalVariable:
GenFdsGlobalVariable.InfLogger (out)
GenFdsGlobalVariable.InfLogger (error)
if PopenObject.returncode != 0:
print "###", cmd
print("###", cmd)
EdkLogger.error("GenFds", COMMAND_FAILURE, errorMess)
def VerboseLogger (msg):

View File

@@ -17,6 +17,7 @@
#
#====================================== External Libraries ========================================
from __future__ import print_function
import optparse
import Common.LongFilePathOs as os
import re
@@ -216,7 +217,7 @@ if __name__ == '__main__':
(options, args) = parser.parse_args()
if options.mapfile is None or options.efifile is None:
print parser.get_usage()
print(parser.get_usage())
elif os.path.exists(options.mapfile) and os.path.exists(options.efifile):
list = parsePcdInfoFromMapFile(options.mapfile, options.efifile)
if list is not None:
@@ -225,6 +226,6 @@ if __name__ == '__main__':
else:
generatePcdTable(list, options.mapfile.replace('.map', '.BinaryPcdTable.txt'))
else:
print 'Fail to generate Patch PCD Table based on map file and efi file'
print('Fail to generate Patch PCD Table based on map file and efi file')
else:
print 'Fail to generate Patch PCD Table for fail to find map file or efi file!'
print('Fail to generate Patch PCD Table for fail to find map file or efi file!')

View File

@@ -19,6 +19,7 @@
'''
Pkcs7Sign
'''
from __future__ import print_function
import os
import sys
@@ -113,14 +114,14 @@ if __name__ == '__main__':
try:
Process = subprocess.Popen('%s version' % (OpenSslCommand), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
except:
print 'ERROR: Open SSL command not available. Please verify PATH or set OPENSSL_PATH'
print('ERROR: Open SSL command not available. Please verify PATH or set OPENSSL_PATH')
sys.exit(1)
Version = Process.communicate()
if Process.returncode <> 0:
print 'ERROR: Open SSL command not available. Please verify PATH or set OPENSSL_PATH'
print('ERROR: Open SSL command not available. Please verify PATH or set OPENSSL_PATH')
sys.exit(Process.returncode)
print Version[0]
print(Version[0])
#
# Read input file into a buffer and save input filename
@@ -134,7 +135,7 @@ if __name__ == '__main__':
#
OutputDir = os.path.dirname(args.OutputFile)
if not os.path.exists(OutputDir):
print 'ERROR: The output path does not exist: %s' % OutputDir
print('ERROR: The output path does not exist: %s' % OutputDir)
sys.exit(1)
args.OutputFileName = args.OutputFile
@@ -170,7 +171,7 @@ if __name__ == '__main__':
args.SignerPrivateCertFile = open(args.SignerPrivateCertFileName, 'rb')
args.SignerPrivateCertFile.close()
except:
print 'ERROR: test signer private cert file %s missing' % (args.SignerPrivateCertFileName)
print('ERROR: test signer private cert file %s missing' % (args.SignerPrivateCertFileName))
sys.exit(1)
#
@@ -196,7 +197,7 @@ if __name__ == '__main__':
args.OtherPublicCertFile = open(args.OtherPublicCertFileName, 'rb')
args.OtherPublicCertFile.close()
except:
print 'ERROR: test other public cert file %s missing' % (args.OtherPublicCertFileName)
print('ERROR: test other public cert file %s missing' % (args.OtherPublicCertFileName))
sys.exit(1)
format = "%dsQ" % len(args.InputFileBuffer)
@@ -242,11 +243,11 @@ if __name__ == '__main__':
args.TrustedPublicCertFile = open(args.TrustedPublicCertFileName, 'rb')
args.TrustedPublicCertFile.close()
except:
print 'ERROR: test trusted public cert file %s missing' % (args.TrustedPublicCertFileName)
print('ERROR: test trusted public cert file %s missing' % (args.TrustedPublicCertFileName))
sys.exit(1)
if not args.SignatureSizeStr:
print "ERROR: please use the option --signature-size to specify the size of the signature data!"
print("ERROR: please use the option --signature-size to specify the size of the signature data!")
sys.exit(1)
else:
if args.SignatureSizeStr.upper().startswith('0X'):
@@ -254,10 +255,10 @@ if __name__ == '__main__':
else:
SignatureSize = (long)(args.SignatureSizeStr)
if SignatureSize < 0:
print "ERROR: The value of option --signature-size can't be set to negative value!"
print("ERROR: The value of option --signature-size can't be set to negative value!")
sys.exit(1)
elif SignatureSize > len(args.InputFileBuffer):
print "ERROR: The value of option --signature-size is exceed the size of the input file !"
print("ERROR: The value of option --signature-size is exceed the size of the input file !")
sys.exit(1)
args.SignatureBuffer = args.InputFileBuffer[0:SignatureSize]
@@ -277,7 +278,7 @@ if __name__ == '__main__':
Process = subprocess.Popen('%s smime -verify -inform DER -content %s -CAfile %s' % (OpenSslCommand, args.OutputFileName, args.TrustedPublicCertFileName), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
Process.communicate(input=args.SignatureBuffer)[0]
if Process.returncode <> 0:
print 'ERROR: Verification failed'
print('ERROR: Verification failed')
os.remove (args.OutputFileName)
sys.exit(Process.returncode)

View File

@@ -22,6 +22,7 @@
'''
Rsa2048Sha256GenerateKeys
'''
from __future__ import print_function
import os
import sys
@@ -75,14 +76,14 @@ if __name__ == '__main__':
try:
Process = subprocess.Popen('%s version' % (OpenSslCommand), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
except:
print 'ERROR: Open SSL command not available. Please verify PATH or set OPENSSL_PATH'
print('ERROR: Open SSL command not available. Please verify PATH or set OPENSSL_PATH')
sys.exit(1)
Version = Process.communicate()
if Process.returncode <> 0:
print 'ERROR: Open SSL command not available. Please verify PATH or set OPENSSL_PATH'
print('ERROR: Open SSL command not available. Please verify PATH or set OPENSSL_PATH')
sys.exit(Process.returncode)
print Version[0]
print(Version[0])
args.PemFileName = []
@@ -103,7 +104,7 @@ if __name__ == '__main__':
Process = subprocess.Popen('%s genrsa -out %s 2048' % (OpenSslCommand, Item.name), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
Process.communicate()
if Process.returncode <> 0:
print 'ERROR: RSA 2048 key generation failed'
print('ERROR: RSA 2048 key generation failed')
sys.exit(Process.returncode)
#
@@ -125,7 +126,7 @@ if __name__ == '__main__':
Process = subprocess.Popen('%s rsa -in %s -modulus -noout' % (OpenSslCommand, Item), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
PublicKeyHexString = Process.communicate()[0].split('=')[1].strip()
if Process.returncode <> 0:
print 'ERROR: Unable to extract public key from private key'
print('ERROR: Unable to extract public key from private key')
sys.exit(Process.returncode)
PublicKey = ''
for Index in range (0, len(PublicKeyHexString), 2):
@@ -138,7 +139,7 @@ if __name__ == '__main__':
Process.stdin.write (PublicKey)
PublicKeyHash = PublicKeyHash + Process.communicate()[0]
if Process.returncode <> 0:
print 'ERROR: Unable to extract SHA 256 hash of public key'
print('ERROR: Unable to extract SHA 256 hash of public key')
sys.exit(Process.returncode)
#
@@ -171,4 +172,4 @@ if __name__ == '__main__':
# If verbose is enabled display the public key in C structure format
#
if args.Verbose:
print 'PublicKeySha256 = ' + PublicKeyHashC
print('PublicKeySha256 = ' + PublicKeyHashC)

View File

@@ -17,6 +17,7 @@
'''
Rsa2048Sha256Sign
'''
from __future__ import print_function
import os
import sys
@@ -96,14 +97,14 @@ if __name__ == '__main__':
try:
Process = subprocess.Popen('%s version' % (OpenSslCommand), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
except:
print 'ERROR: Open SSL command not available. Please verify PATH or set OPENSSL_PATH'
print('ERROR: Open SSL command not available. Please verify PATH or set OPENSSL_PATH')
sys.exit(1)
Version = Process.communicate()
if Process.returncode <> 0:
print 'ERROR: Open SSL command not available. Please verify PATH or set OPENSSL_PATH'
print('ERROR: Open SSL command not available. Please verify PATH or set OPENSSL_PATH')
sys.exit(Process.returncode)
print Version[0]
print(Version[0])
#
# Read input file into a buffer and save input filename
@@ -117,7 +118,7 @@ if __name__ == '__main__':
#
OutputDir = os.path.dirname(args.OutputFile)
if not os.path.exists(OutputDir):
print 'ERROR: The output path does not exist: %s' % OutputDir
print('ERROR: The output path does not exist: %s' % OutputDir)
sys.exit(1)
args.OutputFileName = args.OutputFile
@@ -144,7 +145,7 @@ if __name__ == '__main__':
args.PrivateKeyFile = open(args.PrivateKeyFileName, 'rb')
args.PrivateKeyFile.close()
except:
print 'ERROR: test signing private key file %s missing' % (args.PrivateKeyFileName)
print('ERROR: test signing private key file %s missing' % (args.PrivateKeyFileName))
sys.exit(1)
#
@@ -202,14 +203,14 @@ if __name__ == '__main__':
# Verify that the Hash Type matches the expected SHA256 type
#
if uuid.UUID(bytes_le = Header.HashType) <> EFI_HASH_ALGORITHM_SHA256_GUID:
print 'ERROR: unsupport hash GUID'
print('ERROR: unsupport hash GUID')
sys.exit(1)
#
# Verify the public key
#
if Header.PublicKey <> PublicKey:
print 'ERROR: Public key in input file does not match public key from private key file'
print('ERROR: Public key in input file does not match public key from private key file')
sys.exit(1)
FullInputFileBuffer = args.InputFileBuffer
@@ -228,7 +229,7 @@ if __name__ == '__main__':
Process = subprocess.Popen('%s dgst -sha256 -prverify "%s" -signature %s' % (OpenSslCommand, args.PrivateKeyFileName, args.OutputFileName), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
Process.communicate(input=FullInputFileBuffer)
if Process.returncode <> 0:
print 'ERROR: Verification failed'
print('ERROR: Verification failed')
os.remove (args.OutputFileName)
sys.exit(Process.returncode)

View File

@@ -12,6 +12,7 @@
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
from __future__ import print_function
import Common.LongFilePathOs as os
import sys
import traceback
@@ -32,7 +33,7 @@ class TargetTool():
self.Arg = args[0]
self.FileName = os.path.normpath(os.path.join(self.WorkSpace, 'Conf', 'target.txt'))
if os.path.isfile(self.FileName) == False:
print "%s does not exist." % self.FileName
print("%s does not exist." % self.FileName)
sys.exit(1)
self.TargetTxtDictionary = {
TAB_TAT_DEFINES_ACTIVE_PLATFORM : None,
@@ -83,14 +84,14 @@ class TargetTool():
errMsg = ''
for Key in self.TargetTxtDictionary:
if type(self.TargetTxtDictionary[Key]) == type([]):
print "%-30s = %s" % (Key, ''.join(elem + ' ' for elem in self.TargetTxtDictionary[Key]))
print("%-30s = %s" % (Key, ''.join(elem + ' ' for elem in self.TargetTxtDictionary[Key])))
elif self.TargetTxtDictionary[Key] is None:
errMsg += " Missing %s configuration information, please use TargetTool to set value!" % Key + os.linesep
else:
print "%-30s = %s" % (Key, self.TargetTxtDictionary[Key])
print("%-30s = %s" % (Key, self.TargetTxtDictionary[Key]))
if errMsg != '':
print os.linesep + 'Warning:' + os.linesep + errMsg
print(os.linesep + 'Warning:' + os.linesep + errMsg)
def RWFile(self, CommentCharacter, KeySplitCharacter, Num):
try:
@@ -109,7 +110,7 @@ class TargetTool():
if Key not in existKeys:
existKeys.append(Key)
else:
print "Warning: Found duplicate key item in original configuration files!"
print("Warning: Found duplicate key item in original configuration files!")
if Num == 0:
Line = "%-30s = \n" % Key
@@ -120,7 +121,7 @@ class TargetTool():
fw.write(Line)
for key in self.TargetTxtDictionary:
if key not in existKeys:
print "Warning: %s does not exist in original configuration file" % key
print("Warning: %s does not exist in original configuration file" % key)
Line = GetConfigureKeyValue(self, key)
if Line is None:
Line = "%-30s = " % key
@@ -223,25 +224,25 @@ if __name__ == '__main__':
EdkLogger.Initialize()
EdkLogger.SetLevel(EdkLogger.QUIET)
if os.getenv('WORKSPACE') is None:
print "ERROR: WORKSPACE should be specified or edksetup script should be executed before run TargetTool"
print("ERROR: WORKSPACE should be specified or edksetup script should be executed before run TargetTool")
sys.exit(1)
(opt, args) = MyOptionParser()
if len(args) != 1 or (args[0].lower() != 'print' and args[0].lower() != 'clean' and args[0].lower() != 'set'):
print "The number of args isn't 1 or the value of args is invalid."
print("The number of args isn't 1 or the value of args is invalid.")
sys.exit(1)
if opt.NUM is not None and opt.NUM < 1:
print "The MAX_CONCURRENT_THREAD_NUMBER must be larger than 0."
print("The MAX_CONCURRENT_THREAD_NUMBER must be larger than 0.")
sys.exit(1)
if opt.TARGET is not None and len(opt.TARGET) > 1:
for elem in opt.TARGET:
if elem == '0':
print "0 will clear the TARGET setting in target.txt and can't combine with other value."
print("0 will clear the TARGET setting in target.txt and can't combine with other value.")
sys.exit(1)
if opt.TARGET_ARCH is not None and len(opt.TARGET_ARCH) > 1:
for elem in opt.TARGET_ARCH:
if elem == '0':
print "0 will clear the TARGET_ARCH setting in target.txt and can't combine with other value."
print("0 will clear the TARGET_ARCH setting in target.txt and can't combine with other value.")
sys.exit(1)
try:

View File

@@ -14,6 +14,7 @@
'''
ExpressionValidate
'''
from __future__ import print_function
##
# Import Modules
@@ -566,7 +567,7 @@ def IsValidFeatureFlagExp(Token, Flag=False):
if __name__ == '__main__':
# print IsValidRangeExpr('LT 9')
print _LogicalExpressionParser('gCrownBayTokenSpaceGuid.PcdPciDevice1BridgeAddressLE0').IsValidLogicalExpression()
print(_LogicalExpressionParser('gCrownBayTokenSpaceGuid.PcdPciDevice1BridgeAddressLE0').IsValidLogicalExpression())

View File

@@ -14,6 +14,7 @@
"""
Collect all defined strings in multiple uni files
"""
from __future__ import print_function
##
# Import Modules
@@ -730,7 +731,7 @@ class UniFileClassObject(object):
EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID, ExtraData=File.Path)
NewLines.append(Line)
else:
print Line
print(Line)
EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID, ExtraData=File.Path)
if StrName and not StrName.split()[1].startswith(u'STR_'):
@@ -1022,12 +1023,12 @@ class UniFileClassObject(object):
# Show the instance itself
#
def ShowMe(self):
print self.LanguageDef
print(self.LanguageDef)
#print self.OrderedStringList
for Item in self.OrderedStringList:
print Item
print(Item)
for Member in self.OrderedStringList[Item]:
print str(Member)
print(str(Member))
#
# Read content from '!include' UNI file

View File

@@ -15,6 +15,7 @@
'''
DecPomAlignment
'''
from __future__ import print_function
##
# Import Modules
@@ -902,47 +903,47 @@ class DecPomAlignment(PackageObject):
# Print all members and their values of Package class
#
def ShowPackage(self):
print '\nName =', self.GetName()
print '\nBaseName =', self.GetBaseName()
print '\nVersion =', self.GetVersion()
print '\nGuid =', self.GetGuid()
print('\nName =', self.GetName())
print('\nBaseName =', self.GetBaseName())
print('\nVersion =', self.GetVersion())
print('\nGuid =', self.GetGuid())
print '\nStandardIncludes = %d ' \
% len(self.GetStandardIncludeFileList()),
print('\nStandardIncludes = %d ' \
% len(self.GetStandardIncludeFileList()), end=' ')
for Item in self.GetStandardIncludeFileList():
print Item.GetFilePath(), ' ', Item.GetSupArchList()
print '\nPackageIncludes = %d \n' \
% len(self.GetPackageIncludeFileList()),
print(Item.GetFilePath(), ' ', Item.GetSupArchList())
print('\nPackageIncludes = %d \n' \
% len(self.GetPackageIncludeFileList()), end=' ')
for Item in self.GetPackageIncludeFileList():
print Item.GetFilePath(), ' ', Item.GetSupArchList()
print(Item.GetFilePath(), ' ', Item.GetSupArchList())
print '\nGuids =', self.GetGuidList()
print('\nGuids =', self.GetGuidList())
for Item in self.GetGuidList():
print Item.GetCName(), Item.GetGuid(), Item.GetSupArchList()
print '\nProtocols =', self.GetProtocolList()
print(Item.GetCName(), Item.GetGuid(), Item.GetSupArchList())
print('\nProtocols =', self.GetProtocolList())
for Item in self.GetProtocolList():
print Item.GetCName(), Item.GetGuid(), Item.GetSupArchList()
print '\nPpis =', self.GetPpiList()
print(Item.GetCName(), Item.GetGuid(), Item.GetSupArchList())
print('\nPpis =', self.GetPpiList())
for Item in self.GetPpiList():
print Item.GetCName(), Item.GetGuid(), Item.GetSupArchList()
print '\nLibraryClasses =', self.GetLibraryClassList()
print(Item.GetCName(), Item.GetGuid(), Item.GetSupArchList())
print('\nLibraryClasses =', self.GetLibraryClassList())
for Item in self.GetLibraryClassList():
print Item.GetLibraryClass(), Item.GetRecommendedInstance(), \
Item.GetSupArchList()
print '\nPcds =', self.GetPcdList()
print(Item.GetLibraryClass(), Item.GetRecommendedInstance(), \
Item.GetSupArchList())
print('\nPcds =', self.GetPcdList())
for Item in self.GetPcdList():
print 'CName=', Item.GetCName(), 'TokenSpaceGuidCName=', \
print('CName=', Item.GetCName(), 'TokenSpaceGuidCName=', \
Item.GetTokenSpaceGuidCName(), \
'DefaultValue=', Item.GetDefaultValue(), \
'ValidUsage=', Item.GetValidUsage(), \
'SupArchList', Item.GetSupArchList(), \
'Token=', Item.GetToken(), 'DatumType=', Item.GetDatumType()
'Token=', Item.GetToken(), 'DatumType=', Item.GetDatumType())
for Item in self.GetMiscFileList():
print Item.GetName()
print(Item.GetName())
for FileObjectItem in Item.GetFileList():
print FileObjectItem.GetURI()
print '****************\n'
print(FileObjectItem.GetURI())
print('****************\n')
## GenPcdDeclaration
#

View File

@@ -11,6 +11,7 @@
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
from __future__ import print_function
import os
import unittest
@@ -66,7 +67,7 @@ def TestTemplate(TestString, TestFunc):
# Close file
f.close()
except:
print 'Can not create temporary file [%s]!' % Path
print('Can not create temporary file [%s]!' % Path)
exit(-1)
# Call test function to test
@@ -279,6 +280,6 @@ if __name__ == '__main__':
unittest.FunctionTestCase(TestDecPcd).runTest()
unittest.FunctionTestCase(TestDecUserExtension).runTest()
print 'All tests passed...'
print('All tests passed...')

View File

@@ -11,6 +11,7 @@
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
from __future__ import print_function
import os
#import Object.Parser.InfObject as InfObject
from Object.Parser.InfCommonObject import CurrentLine
@@ -271,7 +272,7 @@ def PrepareTest(String):
TempFile = open (FileName, "w")
TempFile.close()
except:
print "File Create Error"
print("File Create Error")
CurrentLine = CurrentLine()
CurrentLine.SetFileName("Test")
CurrentLine.SetLineString(Item[0])
@@ -376,11 +377,11 @@ if __name__ == '__main__':
try:
InfBinariesInstance.SetBinary(Ver = Ver, ArchList = ArchList)
except:
print "Test Failed!"
print("Test Failed!")
AllPassedFlag = False
if AllPassedFlag :
print 'All tests passed...'
print('All tests passed...')
else:
print 'Some unit test failed!'
print('Some unit test failed!')

View File

@@ -17,6 +17,7 @@
# This class is used to retrieve information stored in database and convert them
# into PlatformBuildClassObject form for easier use for AutoGen.
#
from __future__ import print_function
from Common.StringUtils import *
from Common.DataType import *
from Common.Misc import *
@@ -1373,7 +1374,7 @@ class DscBuildData(PlatformBuildClassObject):
for (skuname,StoreName,PcdGuid,PcdName,PcdValue) in Str_Pcd_Values:
str_pcd_obj = S_pcd_set.get((PcdName, PcdGuid))
if str_pcd_obj is None:
print PcdName, PcdGuid
print(PcdName, PcdGuid)
raise
if str_pcd_obj.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],
self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:
@@ -1808,7 +1809,7 @@ class DscBuildData(PlatformBuildClassObject):
EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %
(".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2]))
except:
print "error"
print("error")
try:
Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])
except Exception:

View File

@@ -15,6 +15,7 @@
##
# Import Modules
#
from __future__ import print_function
import Common.LongFilePathOs as os
import re
import time
@@ -1630,7 +1631,7 @@ class DscParser(MetaFileParser):
try:
self._ValueList[2] = '|'.join(ValList)
except Exception:
print ValList
print(ValList)
def __ProcessComponent(self):
self._ValueList[0] = ReplaceMacro(self._ValueList[0], self._Macros)

View File

@@ -16,6 +16,7 @@
##
# Import Modules
#
from __future__ import print_function
import Common.LongFilePathOs as os
import re
import StringIO
@@ -2195,7 +2196,7 @@ class Build():
toolsFile = os.path.join(FvDir, 'GuidedSectionTools.txt')
toolsFile = open(toolsFile, 'wt')
for guidedSectionTool in guidAttribs:
print >> toolsFile, ' '.join(guidedSectionTool)
print(' '.join(guidedSectionTool), file=toolsFile)
toolsFile.close()
## Returns the full path of the tool.