]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/PatchPcdValue/PatchPcdValue.py
BaseTools: Remove equality operator with None
[mirror_edk2.git] / BaseTools / Source / Python / PatchPcdValue / PatchPcdValue.py
index 01b87012cd24a3d6a446cca973cf3a80db5bc6d9..0c8009cb0b44840305a50f57494da1d0963f067d 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Patch value into the binary file.\r
 #\r
-# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2010 - 2014, 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
@@ -14,7 +14,8 @@
 ##\r
 # Import Modules\r
 #\r
-import os\r
+import Common.LongFilePathOs as os\r
+from Common.LongFilePathSupport import OpenLongFilePath as open\r
 import sys\r
 import re\r
 \r
@@ -47,7 +48,7 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0):
     #\r
     # Length of Binary File\r
     #\r
-    FileHandle = open (FileName, 'rb')\r
+    FileHandle = open(FileName, 'rb')\r
     FileHandle.seek (0, 2)\r
     FileLength = FileHandle.tell()\r
     FileHandle.close()\r
@@ -74,7 +75,7 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0):
             return OPTION_MISSING, "PcdMaxSize is not specified for VOID* type PCD."\r
         ValueLength = int(MaxSize)\r
     else:\r
-        return PARAMETER_INVALID,  "PCD type %s is not valid." %(CommandOptions.PcdTypeName)\r
+        return PARAMETER_INVALID, "PCD type %s is not valid." % (CommandOptions.PcdTypeName)\r
     #\r
     # Check PcdValue is in the input binary file.\r
     #\r
@@ -83,7 +84,7 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0):
     #\r
     # Read binary file into array\r
     #\r
-    FileHandle = open (FileName, 'rb')\r
+    FileHandle = open(FileName, 'rb')\r
     ByteArray = array.array('B')\r
     ByteArray.fromfile(FileHandle, FileLength)\r
     FileHandle.close()\r
@@ -116,7 +117,7 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0):
             if ValueNumber != 0:\r
                 ValueNumber = 1\r
         except:\r
-            return PARAMETER_INVALID, "PCD Value %s is not valid dec or hex string." %(ValueString)\r
+            return PARAMETER_INVALID, "PCD Value %s is not valid dec or hex string." % (ValueString)\r
         #\r
         # Set PCD value into binary data\r
         #\r
@@ -131,7 +132,7 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0):
             else:\r
                 ValueNumber = int (ValueString)\r
         except:\r
-            return PARAMETER_INVALID, "PCD Value %s is not valid dec or hex string." %(ValueString)\r
+            return PARAMETER_INVALID, "PCD Value %s is not valid dec or hex string." % (ValueString)\r
         #\r
         # Set PCD value into binary data\r
         #\r
@@ -160,10 +161,11 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0):
             #\r
             # Patch {0x1, 0x2, ...} byte by byte\r
             #\r
-            ValueList = ValueString[1 : len(ValueString) - 1].split(', ')\r
+            ValueList = ValueString[1 : len(ValueString) - 1].split(',')\r
             Index = 0\r
             try:\r
                 for ByteString in ValueList:\r
+                    ByteString = ByteString.strip()\r
                     if ByteString.upper().startswith('0X'):\r
                         ByteValue = int(ByteString, 16)\r
                     else:\r
@@ -173,7 +175,7 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0):
                     if Index >= ValueLength:\r
                         break\r
             except:\r
-                return PARAMETER_INVALID, "PCD Value %s is not valid dec or hex string array." %(ValueString)\r
+                return PARAMETER_INVALID, "PCD Value %s is not valid dec or hex string array." % (ValueString)\r
         else:\r
             #\r
             # Patch ascii string \r
@@ -196,10 +198,10 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0):
     if ByteList != OrigByteList:\r
         ByteArray = array.array('B')\r
         ByteArray.fromlist(ByteList)\r
-        FileHandle = open (FileName, 'wb')\r
+        FileHandle = open(FileName, 'wb')\r
         ByteArray.tofile(FileHandle)\r
         FileHandle.close()\r
-    return 0, "Patch Value into File %s successfully." %(FileName)\r
+    return 0, "Patch Value into File %s successfully." % (FileName)\r
 \r
 ## Parse command line options\r
 #\r
@@ -265,13 +267,13 @@ def Main():
         if not os.path.exists (InputFile):\r
             EdkLogger.error("PatchPcdValue", FILE_NOT_FOUND, ExtraData=InputFile)\r
             return 1\r
-        if CommandOptions.PcdOffset == None or CommandOptions.PcdValue == None or CommandOptions.PcdTypeName == None:\r
+        if CommandOptions.PcdOffset is None or CommandOptions.PcdValue is None or CommandOptions.PcdTypeName is None:\r
             EdkLogger.error("PatchPcdValue", OPTION_MISSING, ExtraData="PcdOffset or PcdValue of PcdTypeName is not specified.")\r
             return 1\r
         if CommandOptions.PcdTypeName.upper() not in ["BOOLEAN", "UINT8", "UINT16", "UINT32", "UINT64", "VOID*"]:\r
-            EdkLogger.error("PatchPcdValue", PARAMETER_INVALID, ExtraData="PCD type %s is not valid." %(CommandOptions.PcdTypeName))\r
+            EdkLogger.error("PatchPcdValue", PARAMETER_INVALID, ExtraData="PCD type %s is not valid." % (CommandOptions.PcdTypeName))\r
             return 1\r
-        if CommandOptions.PcdTypeName.upper() == "VOID*" and CommandOptions.PcdMaxSize == None:\r
+        if CommandOptions.PcdTypeName.upper() == "VOID*" and CommandOptions.PcdMaxSize is None:\r
             EdkLogger.error("PatchPcdValue", OPTION_MISSING, ExtraData="PcdMaxSize is not specified for VOID* type PCD.")\r
             return 1\r
         #\r