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:
@ -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)
|
||||
|
@ -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.")
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
#
|
||||
|
@ -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
|
||||
|
@ -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!')
|
||||
|
Reference in New Issue
Block a user