]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/InfSectionParser.py
BaseTools: Various typo
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / InfSectionParser.py
index 7f782365480e7d1e4d5bada4adc805ed3833113f..388b6780dfc02318eaa3e6338cacc0dabe3c4ec4 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Parser a Inf file and Get specify section data.\r
 #\r
-# Copyright (c) 2007 - 2012, 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
 import Common.EdkLogger as EdkLogger\r
 from Common.BuildToolError import *\r
 from Common.DataType import *\r
\r
+\r
 \r
 class InfSectionParser():\r
     def __init__(self, FilePath):\r
         self._FilePath = FilePath\r
         self._FileSectionDataList = []\r
         self._ParserInf()\r
-    \r
+\r
     def _ParserInf(self):\r
-        Filename = self._FilePath\r
         FileLinesList = []\r
         UserExtFind = False\r
         FindEnd = True\r
         FileLastLine = False\r
         SectionLine = ''\r
         SectionData = []\r
-        \r
+\r
         try:\r
-            FileLinesList = open(Filename, "r", 0).readlines()\r
+            FileLinesList = open(self._FilePath, "r").readlines()\r
         except BaseException:\r
-            EdkLogger.error("build", AUTOGEN_ERROR, 'File %s is opened failed.' % Filename)\r
-        \r
+            EdkLogger.error("build", AUTOGEN_ERROR, 'File %s is opened failed.' % self._FilePath)\r
+\r
         for Index in range(0, len(FileLinesList)):\r
             line = str(FileLinesList[Index]).strip()\r
             if Index + 1 == len(FileLinesList):\r
@@ -49,29 +48,47 @@ class InfSectionParser():
             if UserExtFind and FindEnd == False:\r
                 if line:\r
                     SectionData.append(line)\r
-            if line.lower().startswith(TAB_SECTION_START) and line.lower().endswith(TAB_SECTION_END):\r
+            if line.startswith(TAB_SECTION_START) and line.endswith(TAB_SECTION_END):\r
                 SectionLine = line\r
                 UserExtFind = True\r
                 FindEnd = False\r
-            \r
+\r
             if (NextLine != '' and NextLine[0] == TAB_SECTION_START and \\r
                 NextLine[-1] == TAB_SECTION_END) or FileLastLine:\r
                 UserExtFind = False\r
                 FindEnd = True\r
                 self._FileSectionDataList.append({SectionLine: SectionData[:]})\r
-                SectionData = []\r
+                del SectionData[:]\r
                 SectionLine = ''\r
-    \r
 \r
-    # Get depex expresion\r
+    # Get user extension TianoCore data\r
+    #\r
+    # @return: a list include some dictionary that key is section and value is a list contain all data.\r
+    def GetUserExtensionTianoCore(self):\r
+        UserExtensionTianoCore = []\r
+        if not self._FileSectionDataList:\r
+            return UserExtensionTianoCore\r
+        for SectionDataDict in self._FileSectionDataList:\r
+            for key in SectionDataDict:\r
+                if key.lower().startswith("[userextensions") and key.lower().find('.tianocore.') > -1:\r
+                    SectionLine = key.lstrip(TAB_SECTION_START).rstrip(TAB_SECTION_END)\r
+                    SubSectionList = [SectionLine]\r
+                    if str(SectionLine).find(TAB_COMMA_SPLIT) > -1:\r
+                        SubSectionList = str(SectionLine).split(TAB_COMMA_SPLIT)\r
+                    for SubSection in SubSectionList:\r
+                        if SubSection.lower().find('.tianocore.') > -1:\r
+                            UserExtensionTianoCore.append({SubSection: SectionDataDict[key]})\r
+        return UserExtensionTianoCore\r
+\r
+    # Get depex expression\r
     #\r
     # @return: a list include some dictionary that key is section and value is a list contain all data.\r
     def GetDepexExpresionList(self):\r
-        DepexExpresionList = []\r
+        DepexExpressionList = []\r
         if not self._FileSectionDataList:\r
-            return DepexExpresionList\r
+            return DepexExpressionList\r
         for SectionDataDict in self._FileSectionDataList:\r
-            for key in SectionDataDict.keys():\r
+            for key in SectionDataDict:\r
                 if key.lower() == "[depex]" or key.lower().startswith("[depex."):\r
                     SectionLine = key.lstrip(TAB_SECTION_START).rstrip(TAB_SECTION_END)\r
                     SubSectionList = [SectionLine]\r
@@ -88,8 +105,8 @@ class InfSectionParser():
                             SubKey = (SectionList[1], SectionList[2])\r
                         else:\r
                             EdkLogger.error("build", AUTOGEN_ERROR, 'Section %s is invalid.' % key)\r
-                        DepexExpresionList.append({SubKey: SectionDataDict[key]})\r
-        return DepexExpresionList\r
+                        DepexExpressionList.append({SubKey: SectionDataDict[key]})\r
+        return DepexExpressionList\r
 \r
 \r
 \r