]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Common/Misc.py
Sync BaseTools Branch (version r2271) to EDKII main trunk.
[mirror_edk2.git] / BaseTools / Source / Python / Common / Misc.py
index e2dc5a5e52749abd6731adbec7de72a628be1b96..0540636988a674873d317d518e7bf9acda63ebfb 100644 (file)
@@ -1,7 +1,7 @@
 ## @file
 # Common routines used by all tools
 #
-# Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
 # This program and the accompanying materials
 # are licensed and made available under the terms and conditions of the BSD License
 # which accompanies this distribution.  The full text of the license may be found at
@@ -28,7 +28,7 @@ from UserList import UserList
 
 from Common import EdkLogger as EdkLogger
 from Common import GlobalData as GlobalData
-
+from DataType import *
 from BuildToolError import *
 
 ## Regular expression used to find out place holders in string template
@@ -252,7 +252,15 @@ def SaveFileOnChange(File, Content, IsBinaryFile=True):
         except:
             EdkLogger.error(None, FILE_OPEN_FAILURE, ExtraData=File)
 
-    CreateDirectory(os.path.dirname(File))
+    DirName = os.path.dirname(File)
+    if not CreateDirectory(DirName):
+        EdkLogger.error(None, FILE_CREATE_FAILURE, "Could not create directory %s" % DirName)
+    else:
+        if DirName == '':
+            DirName = os.getcwd()
+        if not os.access(DirName, os.W_OK):
+            EdkLogger.error(None, PERMISSION_FAILURE, "Do not have write permission on directory %s" % DirName)
+
     try:
         if GlobalData.gIsWindows:
             try:
@@ -267,8 +275,8 @@ def SaveFileOnChange(File, Content, IsBinaryFile=True):
             Fd = open(File, "wb")
             Fd.write(Content)
             Fd.close()
-    except:
-        EdkLogger.error(None, FILE_CREATE_FAILURE, ExtraData=File)
+    except IOError, X:
+        EdkLogger.error(None, FILE_CREATE_FAILURE, ExtraData='IOError %s'%X)
 
     return True
 
@@ -1166,6 +1174,93 @@ def ParseConsoleLog(Filename):
     Opr.close()
     Opw.close()
 
+## AnalyzePcdData
+#
+#  Analyze the pcd Value, Datum type and TokenNumber.
+#  Used to avoid split issue while the value string contain "|" character
+#
+#  @param[in] Setting:  A String contain value/datum type/token number information;
+#  
+#  @retval   ValueList: A List contain value, datum type and toke number. 
+#
+def AnalyzePcdData(Setting):   
+    ValueList = ['', '', '']    
+    
+    ValueRe  = re.compile(r'^\s*L?\".*\|.*\"')
+    PtrValue = ValueRe.findall(Setting)
+    
+    ValueUpdateFlag = False
+    
+    if len(PtrValue) >= 1:
+        Setting = re.sub(ValueRe, '', Setting)
+        ValueUpdateFlag = True   
+
+    TokenList = Setting.split(TAB_VALUE_SPLIT)
+    ValueList[0:len(TokenList)] = TokenList
+    
+    if ValueUpdateFlag:
+        ValueList[0] = PtrValue[0]
+        
+    return ValueList   
+## AnalyzeHiiPcdData
+#
+#  Analyze the pcd Value, variable name, variable Guid and variable offset.
+#  Used to avoid split issue while the value string contain "|" character
+#
+#  @param[in] Setting:  A String contain VariableName, VariableGuid, VariableOffset, DefaultValue information;
+#  
+#  @retval   ValueList: A List contaian VariableName, VariableGuid, VariableOffset, DefaultValue. 
+#
+def AnalyzeHiiPcdData(Setting):   
+    ValueList = ['', '', '', '']    
+    
+    ValueRe  = re.compile(r'^\s*L?\".*\|.*\"')
+    PtrValue = ValueRe.findall(Setting)
+    
+    ValueUpdateFlag = False
+    
+    if len(PtrValue) >= 1:
+        Setting = re.sub(ValueRe, '', Setting)
+        ValueUpdateFlag = True   
+
+    TokenList = Setting.split(TAB_VALUE_SPLIT)
+    ValueList[0:len(TokenList)] = TokenList
+    
+    if ValueUpdateFlag:
+        ValueList[0] = PtrValue[0]
+        
+    return ValueList     
+
+## AnalyzeVpdPcdData
+#
+#  Analyze the vpd pcd Value, Datum type and TokenNumber.
+#  Used to avoid split issue while the value string contain "|" character
+#
+#  @param[in] Setting:  A String contain value/datum type/token number information;
+#  
+#  @retval   ValueList: A List contain value, datum type and toke number. 
+#
+def AnalyzeVpdPcdData(Setting):   
+    ValueList = ['', '', '']    
+    
+    ValueRe  = re.compile(r'\s*L?\".*\|.*\"\s*$')
+    PtrValue = ValueRe.findall(Setting)
+    
+    ValueUpdateFlag = False
+    
+    if len(PtrValue) >= 1:
+        Setting = re.sub(ValueRe, '', Setting)
+        ValueUpdateFlag = True   
+
+    TokenList = Setting.split(TAB_VALUE_SPLIT)
+    ValueList[0:len(TokenList)] = TokenList
+    
+    if ValueUpdateFlag:
+        ValueList[2] = PtrValue[0]
+        
+    return ValueList     
+
 ## check format of PCD value against its the datum type
 #
 # For PCD value setting