]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/TargetTool/TargetTool.py
BaseTools: Replace StandardError with Expression
[mirror_edk2.git] / BaseTools / Source / Python / TargetTool / TargetTool.py
index 143b53ec35efb516647287608910a34de622c5c3..0d4a59198e7bd84a628093fd733894a37d453e4a 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Target Tool Parser\r
 #\r
-#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -12,6 +12,7 @@
 #  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 #\r
 \r
+from __future__ import print_function\r
 import Common.LongFilePathOs as os\r
 import sys\r
 import traceback\r
@@ -32,7 +33,7 @@ class TargetTool():
         self.Arg       = args[0]\r
         self.FileName  = os.path.normpath(os.path.join(self.WorkSpace, 'Conf', 'target.txt'))\r
         if os.path.isfile(self.FileName) == False:\r
-            print "%s does not exist." % self.FileName\r
+            print("%s does not exist." % self.FileName)\r
             sys.exit(1)\r
         self.TargetTxtDictionary = {\r
             TAB_TAT_DEFINES_ACTIVE_PLATFORM                            : None,\r
@@ -65,7 +66,7 @@ class TargetTool():
                 LineList = Line.split(KeySplitCharacter,1)\r
                 if len(LineList) >= 2:\r
                     Key = LineList[0].strip()\r
-                    if Key.startswith(CommentCharacter) == False and Key in self.TargetTxtDictionary.keys():\r
+                    if Key.startswith(CommentCharacter) == False and Key in self.TargetTxtDictionary:\r
                         if Key == TAB_TAT_DEFINES_ACTIVE_PLATFORM or Key == TAB_TAT_DEFINES_TOOL_CHAIN_CONF \\r
                           or Key == TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER \\r
                           or Key == TAB_TAT_DEFINES_ACTIVE_MODULE:\r
@@ -83,14 +84,14 @@ class TargetTool():
         errMsg  = ''\r
         for Key in self.TargetTxtDictionary:\r
             if type(self.TargetTxtDictionary[Key]) == type([]):\r
-                print "%-30s = %s" % (Key, ''.join(elem + ' ' for elem in self.TargetTxtDictionary[Key]))\r
+                print("%-30s = %s" % (Key, ''.join(elem + ' ' for elem in self.TargetTxtDictionary[Key])))\r
             elif self.TargetTxtDictionary[Key] is None:\r
                 errMsg += "  Missing %s configuration information, please use TargetTool to set value!" % Key + os.linesep \r
             else:\r
-                print "%-30s = %s" % (Key, self.TargetTxtDictionary[Key])\r
+                print("%-30s = %s" % (Key, self.TargetTxtDictionary[Key]))\r
         \r
         if errMsg != '':\r
-            print os.linesep + 'Warning:' + os.linesep + errMsg\r
+            print(os.linesep + 'Warning:' + os.linesep + errMsg)\r
             \r
     def RWFile(self, CommentCharacter, KeySplitCharacter, Num):\r
         try:\r
@@ -105,11 +106,11 @@ class TargetTool():
                     LineList = Line.split(KeySplitCharacter,1)\r
                     if len(LineList) >= 2:\r
                         Key = LineList[0].strip()\r
-                        if Key.startswith(CommentCharacter) == False and Key in self.TargetTxtDictionary.keys():\r
+                        if Key.startswith(CommentCharacter) == False and Key in self.TargetTxtDictionary:\r
                             if Key not in existKeys:\r
                                 existKeys.append(Key)\r
                             else:\r
-                                print "Warning: Found duplicate key item in original configuration files!"\r
+                                print("Warning: Found duplicate key item in original configuration files!")\r
                                 \r
                             if Num == 0:\r
                                 Line = "%-30s = \n" % Key\r
@@ -118,9 +119,9 @@ class TargetTool():
                                 if ret is not None:\r
                                     Line = ret\r
                             fw.write(Line)\r
-            for key in self.TargetTxtDictionary.keys():\r
+            for key in self.TargetTxtDictionary:\r
                 if key not in existKeys:\r
-                    print "Warning: %s does not exist in original configuration file" % key\r
+                    print("Warning: %s does not exist in original configuration file" % key)\r
                     Line = GetConfigureKeyValue(self, key)\r
                     if Line is None:\r
                         Line = "%-30s = " % key\r
@@ -223,25 +224,25 @@ if __name__ == '__main__':
     EdkLogger.Initialize()\r
     EdkLogger.SetLevel(EdkLogger.QUIET)\r
     if os.getenv('WORKSPACE') is None:\r
-        print "ERROR: WORKSPACE should be specified or edksetup script should be executed before run TargetTool"\r
+        print("ERROR: WORKSPACE should be specified or edksetup script should be executed before run TargetTool")\r
         sys.exit(1)\r
         \r
     (opt, args) = MyOptionParser()\r
     if len(args) != 1 or (args[0].lower() != 'print' and args[0].lower() != 'clean' and args[0].lower() != 'set'):\r
-        print "The number of args isn't 1 or the value of args is invalid."\r
+        print("The number of args isn't 1 or the value of args is invalid.")\r
         sys.exit(1)\r
     if opt.NUM is not None and opt.NUM < 1:\r
-        print "The MAX_CONCURRENT_THREAD_NUMBER must be larger than 0."\r
+        print("The MAX_CONCURRENT_THREAD_NUMBER must be larger than 0.")\r
         sys.exit(1)\r
     if opt.TARGET is not None and len(opt.TARGET) > 1:\r
         for elem in opt.TARGET:\r
             if elem == '0':\r
-                print "0 will clear the TARGET setting in target.txt and can't combine with other value."\r
+                print("0 will clear the TARGET setting in target.txt and can't combine with other value.")\r
                 sys.exit(1)\r
     if opt.TARGET_ARCH is not None and len(opt.TARGET_ARCH) > 1:\r
         for elem in opt.TARGET_ARCH:\r
             if elem == '0':\r
-                print "0 will clear the TARGET_ARCH setting in target.txt and can't combine with other value."\r
+                print("0 will clear the TARGET_ARCH setting in target.txt and can't combine with other value.")\r
                 sys.exit(1)\r
 \r
     try:\r
@@ -253,7 +254,7 @@ if __name__ == '__main__':
             FileHandle.RWFile('#', '=', 0)\r
         else:\r
             FileHandle.RWFile('#', '=', 1)\r
-    except Exception, e:\r
+    except Exception as e:\r
         last_type, last_value, last_tb = sys.exc_info()\r
         traceback.print_exception(last_type, last_value, last_tb)\r
 \r