]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Trim/Trim.py
BaseTools: Various typo
[mirror_edk2.git] / BaseTools / Source / Python / Trim / Trim.py
index b46d507b4e55e503712ecf0a205cb3d940f206b4..825ed3e5d507a3ffdc598e0a1aa57a4957f86a4e 100644 (file)
@@ -31,7 +31,7 @@ from Common.LongFilePathSupport import OpenLongFilePath as open
 # Version and Copyright\r
 __version_number__ = ("0.10" + " " + gBUILD_VERSION)\r
 __version__ = "%prog Version " + __version_number__\r
-__copyright__ = "Copyright (c) 2007-2017, Intel Corporation. All rights reserved."\r
+__copyright__ = "Copyright (c) 2007-2018, Intel Corporation. All rights reserved."\r
 \r
 ## Regular expression for matching Line Control directive like "#line xxx"\r
 gLineControlDirective = re.compile('^\s*#(?:line)?\s+([0-9]+)\s+"*([^"]*)"')\r
@@ -168,7 +168,7 @@ def TrimPreprocessedFile(Source, Target, ConvertHex, TrimLong):
                 InjectedFile = MatchList[1]\r
                 InjectedFile = os.path.normpath(InjectedFile)\r
                 InjectedFile = os.path.normcase(InjectedFile)\r
-                # The first injetcted file must be the preprocessed file itself\r
+                # The first injected file must be the preprocessed file itself\r
                 if PreprocessedFile == "":\r
                     PreprocessedFile = InjectedFile\r
             LineControlDirectiveFound = True\r
@@ -205,7 +205,7 @@ def TrimPreprocessedFile(Source, Target, ConvertHex, TrimLong):
             else:\r
                 if LineNumber > (len(NewLines) + 1):\r
                     for LineIndex in range(len(NewLines), LineNumber-1):\r
-                        NewLines.append(os.linesep)\r
+                        NewLines.append(TAB_LINE_BREAK)\r
                 NewLines.append(Line)\r
             LineNumber = None\r
             EdkLogger.verbose("Now we have lines: %d" % len(NewLines))\r
@@ -245,7 +245,7 @@ def TrimPreprocessedFile(Source, Target, ConvertHex, TrimLong):
 \r
     # save to file\r
     try:\r
-        f = open (Target, 'wb')\r
+        f = open (Target, 'w')\r
     except:\r
         EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Target)\r
     f.writelines(NewLines)\r
@@ -261,7 +261,7 @@ def TrimPreprocessedFile(Source, Target, ConvertHex, TrimLong):
 #\r
 def TrimPreprocessedVfr(Source, Target):\r
     CreateDirectory(os.path.dirname(Target))\r
-    \r
+\r
     try:\r
         f = open (Source, 'r')\r
     except:\r
@@ -338,7 +338,7 @@ def DoInclude(Source, Indent='', IncludePathList=[], LocalSearchPath=None):
             SearchPathList = [LocalSearchPath] + IncludePathList\r
         else:\r
             SearchPathList = IncludePathList\r
-  \r
+\r
         for IncludePath in SearchPathList:\r
             IncludeFile = os.path.join(IncludePath, Source)\r
             if os.path.isfile(IncludeFile):\r
@@ -349,7 +349,7 @@ def DoInclude(Source, Indent='', IncludePathList=[], LocalSearchPath=None):
     except:\r
         EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Source)\r
 \r
-    \r
+\r
     # avoid A "include" B and B "include" A\r
     IncludeFile = os.path.abspath(os.path.normpath(IncludeFile))\r
     if IncludeFile in gIncludedAslFile:\r
@@ -357,7 +357,7 @@ def DoInclude(Source, Indent='', IncludePathList=[], LocalSearchPath=None):
                        ExtraData= "%s -> %s" % (" -> ".join(gIncludedAslFile), IncludeFile))\r
         return []\r
     gIncludedAslFile.append(IncludeFile)\r
-    \r
+\r
     for Line in F:\r
         LocalSearchPath = None\r
         Result = gAslIncludePattern.findall(Line)\r
@@ -367,7 +367,7 @@ def DoInclude(Source, Indent='', IncludePathList=[], LocalSearchPath=None):
                 NewFileContent.append("%s%s" % (Indent, Line))\r
                 continue\r
             #\r
-            # We should first search the local directory if current file are using pattern #include "XXX" \r
+            # We should first search the local directory if current file are using pattern #include "XXX"\r
             #\r
             if Result[0][2] == '"':\r
                 LocalSearchPath = os.path.dirname(IncludeFile)\r
@@ -388,20 +388,20 @@ def DoInclude(Source, Indent='', IncludePathList=[], LocalSearchPath=None):
 #\r
 # @param  Source          File to be trimmed\r
 # @param  Target          File to store the trimmed content\r
-# @param  IncludePathFile The file to log the external include path \r
+# @param  IncludePathFile The file to log the external include path\r
 #\r
 def TrimAslFile(Source, Target, IncludePathFile):\r
     CreateDirectory(os.path.dirname(Target))\r
-    \r
+\r
     SourceDir = os.path.dirname(Source)\r
     if SourceDir == '':\r
         SourceDir = '.'\r
-    \r
+\r
     #\r
     # Add source directory as the first search directory\r
     #\r
     IncludePathList = [SourceDir]\r
-    \r
+\r
     #\r
     # If additional include path file is specified, append them all\r
     # to the search directory list.\r
@@ -458,7 +458,7 @@ def GenerateVfrBinSec(ModuleName, DebugDir, OutputFile):
         EdkLogger.error("Trim", FILE_OPEN_FAILURE, "File open failed for %s" %OutputFile, None)\r
 \r
     # Use a instance of BytesIO to cache data\r
-    fStringIO = BytesIO('')\r
+    fStringIO = BytesIO()\r
 \r
     for Item in VfrUniOffsetList:\r
         if (Item[0].find("Strings") != -1):\r
@@ -467,9 +467,8 @@ def GenerateVfrBinSec(ModuleName, DebugDir, OutputFile):
             # GUID + Offset\r
             # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }\r
             #\r
-            UniGuid = [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]\r
-            UniGuid = [chr(ItemGuid) for ItemGuid in UniGuid]\r
-            fStringIO.write(''.join(UniGuid))\r
+            UniGuid = b'\xe0\xc5\x13\x89\xf63\x86M\x9b\xf1C\xef\x89\xfc\x06f'\r
+            fStringIO.write(UniGuid)\r
             UniValue = pack ('Q', int (Item[1], 16))\r
             fStringIO.write (UniValue)\r
         else:\r
@@ -478,9 +477,8 @@ def GenerateVfrBinSec(ModuleName, DebugDir, OutputFile):
             # GUID + Offset\r
             # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };\r
             #\r
-            VfrGuid = [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]\r
-            VfrGuid = [chr(ItemGuid) for ItemGuid in VfrGuid]\r
-            fStringIO.write(''.join(VfrGuid))\r
+            VfrGuid = b'\xb4|\xbc\xd0Gj_I\xaa\x11q\x07F\xda\x06\xa2'\r
+            fStringIO.write(VfrGuid)\r
             type (Item[1])\r
             VfrValue = pack ('Q', int (Item[1], 16))\r
             fStringIO.write (VfrValue)\r
@@ -562,7 +560,7 @@ def TrimEdkSourceCode(Source, Target):
     CreateDirectory(os.path.dirname(Target))\r
 \r
     try:\r
-        f = open (Source, 'rb')\r
+        f = open (Source, 'r')\r
     except:\r
         EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Source)\r
     # read whole file\r
@@ -581,7 +579,7 @@ def TrimEdkSourceCode(Source, Target):
         return\r
 \r
     try:\r
-        f = open (Target, 'wb')\r
+        f = open (Target, 'w')\r
     except:\r
         EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Target)\r
     f.write(NewLines)\r
@@ -672,7 +670,7 @@ def Main():
             EdkLogger.SetLevel(CommandOptions.LogLevel)\r
     except FatalError as X:\r
         return 1\r
-    \r
+\r
     try:\r
         if CommandOptions.FileType == "Vfr":\r
             if CommandOptions.OutputFile is None:\r