]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Common/EdkLogger.py
BaseTools: Various typo
[mirror_edk2.git] / BaseTools / Source / Python / Common / EdkLogger.py
index f048b619e403170953d0cf9335cad8307d1a8320..77c0d2a28e4c7f3d489280678a4fad6ff0fb179f 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file implements the log mechanism for Python tools.\r
 #\r
-# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
 #\r
 \r
 ## Import modules\r
+from __future__ import absolute_import\r
 import Common.LongFilePathOs as os, sys, logging\r
 import traceback\r
-from  BuildToolError import *\r
+from  .BuildToolError import *\r
 \r
 ## Log level constants\r
 DEBUG_0 = 1\r
@@ -32,6 +33,7 @@ INFO    = 20
 WARN    = 30\r
 QUIET   = 40\r
 ERROR   = 50\r
+SILENT  = 99\r
 \r
 IsRaiseError = True\r
 \r
@@ -39,7 +41,9 @@ IsRaiseError = True
 _ToolName = os.path.basename(sys.argv[0])\r
 \r
 # For validation purpose\r
-_LogLevels = [DEBUG_0, DEBUG_1, DEBUG_2, DEBUG_3, DEBUG_4, DEBUG_5, DEBUG_6, DEBUG_7, DEBUG_8, DEBUG_9, VERBOSE, WARN, INFO, ERROR, QUIET]\r
+_LogLevels = [DEBUG_0, DEBUG_1, DEBUG_2, DEBUG_3, DEBUG_4, DEBUG_5,\r
+              DEBUG_6, DEBUG_7, DEBUG_8, DEBUG_9, VERBOSE, WARN, INFO,\r
+              ERROR, QUIET, SILENT]\r
 \r
 # For DEBUG level (All DEBUG_0~9 are applicable)\r
 _DebugLogger = logging.getLogger("tool_debug")\r
@@ -86,7 +90,7 @@ def debug(Level, Message, ExtraData=None):
         "msg"       : Message,\r
     }\r
 \r
-    if ExtraData != None:\r
+    if ExtraData is not None:\r
         LogText = _DebugMessageTemplate % TemplateDict + "\n    %s" % ExtraData\r
     else:\r
         LogText = _DebugMessageTemplate % TemplateDict\r
@@ -116,10 +120,10 @@ def warn(ToolName, Message, File=None, Line=None, ExtraData=None):
         return\r
 \r
     # if no tool name given, use caller's source file name as tool name\r
-    if ToolName == None or ToolName == "":\r
+    if ToolName is None or ToolName == "":\r
         ToolName = os.path.basename(traceback.extract_stack()[-2][0])\r
 \r
-    if Line == None:\r
+    if Line is None:\r
         Line = "..."\r
     else:\r
         Line = "%d" % Line\r
@@ -131,17 +135,17 @@ def warn(ToolName, Message, File=None, Line=None, ExtraData=None):
         "msg"       : Message,\r
     }\r
 \r
-    if File != None:\r
+    if File is not None:\r
         LogText = _WarningMessageTemplate % TemplateDict\r
     else:\r
         LogText = _WarningMessageTemplateWithoutFile % TemplateDict\r
 \r
-    if ExtraData != None:\r
+    if ExtraData is not None:\r
         LogText += "\n    %s" % ExtraData\r
 \r
     _InfoLogger.log(WARN, LogText)\r
 \r
-    # Raise an execption if indicated\r
+    # Raise an exception if indicated\r
     if _WarningAsError == True:\r
         raise FatalError(WARNING_AS_ERROR)\r
 \r
@@ -151,7 +155,7 @@ info    = _InfoLogger.info
 ## Log ERROR message\r
 #\r
 #   Once an error messages is logged, the tool's execution will be broken by raising\r
-# an execption. If you don't want to break the execution later, you can give\r
+# an exception. If you don't want to break the execution later, you can give\r
 # "RaiseError" with "False" value.\r
 #\r
 #   @param  ToolName    The name of the tool. If not given, the name of caller\r
@@ -161,22 +165,22 @@ info    = _InfoLogger.info
 #   @param  File        The name of file which caused the error.\r
 #   @param  Line        The line number in the "File" which caused the warning.\r
 #   @param  ExtraData   More information associated with "Message"\r
-#   @param  RaiseError  Raise an exception to break the tool's executuion if\r
+#   @param  RaiseError  Raise an exception to break the tool's execution if\r
 #                       it's True. This is the default behavior.\r
 #\r
 def error(ToolName, ErrorCode, Message=None, File=None, Line=None, ExtraData=None, RaiseError=IsRaiseError):\r
-    if Line == None:\r
+    if Line is None:\r
         Line = "..."\r
     else:\r
         Line = "%d" % Line\r
 \r
-    if Message == None:\r
+    if Message is None:\r
         if ErrorCode in gErrorMessage:\r
             Message = gErrorMessage[ErrorCode]\r
         else:\r
             Message = gErrorMessage[UNKNOWN_ERROR]\r
 \r
-    if ExtraData == None:\r
+    if ExtraData is None:\r
         ExtraData = ""\r
 \r
     TemplateDict = {\r
@@ -188,13 +192,14 @@ def error(ToolName, ErrorCode, Message=None, File=None, Line=None, ExtraData=Non
         "extra"     : ExtraData\r
     }\r
 \r
-    if File != None:\r
+    if File is not None:\r
         LogText =  _ErrorMessageTemplate % TemplateDict\r
     else:\r
         LogText = _ErrorMessageTemplateWithoutFile % TemplateDict\r
 \r
     _ErrorLogger.log(ERROR, LogText)\r
-    if RaiseError:\r
+\r
+    if RaiseError and IsRaiseError:\r
         raise FatalError(ErrorCode)\r
 \r
 # Log information which should be always put out\r
@@ -235,6 +240,10 @@ def SetLevel(Level):
     _InfoLogger.setLevel(Level)\r
     _ErrorLogger.setLevel(Level)\r
 \r
+def InitializeForUnitTest():\r
+    Initialize()\r
+    SetLevel(SILENT)\r
+\r
 ## Get current log level\r
 def GetLevel():\r
     return _InfoLogger.getEffectiveLevel()\r