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/Ecc/CParser.py | 5 +- .../Source/Python/Ecc/CodeFragmentCollector.py | 69 +++++++++++----------- BaseTools/Source/Python/Ecc/Configuration.py | 5 +- BaseTools/Source/Python/Ecc/Exception.py | 3 +- .../Python/Ecc/MetaFileWorkspace/MetaDataTable.py | 3 +- BaseTools/Source/Python/Ecc/Xml/XmlRoutines.py | 5 +- BaseTools/Source/Python/Ecc/c.py | 13 ++-- 7 files changed, 55 insertions(+), 48 deletions(-) (limited to 'BaseTools/Source/Python/Ecc') diff --git a/BaseTools/Source/Python/Ecc/CParser.py b/BaseTools/Source/Python/Ecc/CParser.py index ddc6cbd506..d5fd3a37a1 100644 --- a/BaseTools/Source/Python/Ecc/CParser.py +++ b/BaseTools/Source/Python/Ecc/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/Ecc/CodeFragmentCollector.py b/BaseTools/Source/Python/Ecc/CodeFragmentCollector.py index ffa51de7c1..2efae2c7c1 100644 --- a/BaseTools/Source/Python/Ecc/CodeFragmentCollector.py +++ b/BaseTools/Source/Python/Ecc/CodeFragmentCollector.py @@ -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.") diff --git a/BaseTools/Source/Python/Ecc/Configuration.py b/BaseTools/Source/Python/Ecc/Configuration.py index 217b60f4f3..4711bbd54f 100644 --- a/BaseTools/Source/Python/Ecc/Configuration.py +++ b/BaseTools/Source/Python/Ecc/Configuration.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 * @@ -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. diff --git a/BaseTools/Source/Python/Ecc/Exception.py b/BaseTools/Source/Python/Ecc/Exception.py index b0882afa62..bde41c3a4b 100644 --- a/BaseTools/Source/Python/Ecc/Exception.py +++ b/BaseTools/Source/Python/Ecc/Exception.py @@ -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) diff --git a/BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaDataTable.py b/BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaDataTable.py index fc65e9a2bd..a056c3759f 100644 --- a/BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaDataTable.py +++ b/BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaDataTable.py @@ -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 # diff --git a/BaseTools/Source/Python/Ecc/Xml/XmlRoutines.py b/BaseTools/Source/Python/Ecc/Xml/XmlRoutines.py index d5fb80fcf9..811106133c 100644 --- a/BaseTools/Source/Python/Ecc/Xml/XmlRoutines.py +++ b/BaseTools/Source/Python/Ecc/Xml/XmlRoutines.py @@ -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 diff --git a/BaseTools/Source/Python/Ecc/c.py b/BaseTools/Source/Python/Ecc/c.py index 99b22725e6..e2a5cc8487 100644 --- a/BaseTools/Source/Python/Ecc/c.py +++ b/BaseTools/Source/Python/Ecc/c.py @@ -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!') -- cgit v1.2.3