From 72443dd25014a8b6209895640af36dec33da51e0 Mon Sep 17 00:00:00 2001 From: Gary Lin Date: Mon, 25 Jun 2018 18:31:26 +0800 Subject: 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 Cc: Liming Gao Signed-off-by: Gary Lin Reviewed-by: Yonghong Zhu --- BaseTools/Source/Python/Eot/CParser.py | 5 +- .../Source/Python/Eot/CodeFragmentCollector.py | 61 +++++++++++----------- BaseTools/Source/Python/Eot/InfParserLite.py | 7 +-- BaseTools/Source/Python/Eot/c.py | 3 +- 4 files changed, 40 insertions(+), 36 deletions(-) (limited to 'BaseTools/Source/Python/Eot') diff --git a/BaseTools/Source/Python/Eot/CParser.py b/BaseTools/Source/Python/Eot/CParser.py index ddc6cbd..d5fd3a3 100644 --- a/BaseTools/Source/Python/Eot/CParser.py +++ b/BaseTools/Source/Python/Eot/CParser.py @@ -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) diff --git a/BaseTools/Source/Python/Eot/CodeFragmentCollector.py b/BaseTools/Source/Python/Eot/CodeFragmentCollector.py index 87f1792..1e30e2c 100644 --- a/BaseTools/Source/Python/Eot/CodeFragmentCollector.py +++ b/BaseTools/Source/Python/Eot/CodeFragmentCollector.py @@ -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.") diff --git a/BaseTools/Source/Python/Eot/InfParserLite.py b/BaseTools/Source/Python/Eot/InfParserLite.py index 584a95d..24f0d50 100644 --- a/BaseTools/Source/Python/Eot/InfParserLite.py +++ b/BaseTools/Source/Python/Eot/InfParserLite.py @@ -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() \ No newline at end of file + Db.Close() diff --git a/BaseTools/Source/Python/Eot/c.py b/BaseTools/Source/Python/Eot/c.py index 8199ce5..c70f62f 100644 --- a/BaseTools/Source/Python/Eot/c.py +++ b/BaseTools/Source/Python/Eot/c.py @@ -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!') -- cgit v1.1