]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/AutoGen/InfSectionParser.py
2 # Parser a Inf file and Get specify section data.
4 # Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 import Common
.EdkLogger
as EdkLogger
18 from Common
.BuildToolError
import *
19 from Common
.DataType
import *
22 class InfSectionParser():
23 def __init__(self
, FilePath
):
24 self
._FilePath
= FilePath
25 self
._FileSectionDataList
= []
29 Filename
= self
._FilePath
38 FileLinesList
= open(Filename
, "r", 0).readlines()
40 EdkLogger
.error("build", AUTOGEN_ERROR
, 'File %s is opened failed.' % Filename
)
42 for Index
in range(0, len(FileLinesList
)):
43 line
= str(FileLinesList
[Index
]).strip()
44 if Index
+ 1 == len(FileLinesList
):
48 NextLine
= str(FileLinesList
[Index
+ 1]).strip()
49 if UserExtFind
and FindEnd
== False:
51 SectionData
.append(line
)
52 if line
.lower().startswith(TAB_SECTION_START
) and line
.lower().endswith(TAB_SECTION_END
):
57 if (NextLine
!= '' and NextLine
[0] == TAB_SECTION_START
and \
58 NextLine
[-1] == TAB_SECTION_END
) or FileLastLine
:
61 self
._FileSectionDataList
.append({SectionLine
: SectionData
[:]})
68 # @return: a list include some dictionary that key is section and value is a list contain all data.
69 def GetDepexExpresionList(self
):
70 DepexExpresionList
= []
71 if not self
._FileSectionDataList
:
72 return DepexExpresionList
73 for SectionDataDict
in self
._FileSectionDataList
:
74 for key
in SectionDataDict
.keys():
75 if key
.lower() == "[depex]" or key
.lower().startswith("[depex."):
76 SectionLine
= key
.lstrip(TAB_SECTION_START
).rstrip(TAB_SECTION_END
)
77 SubSectionList
= [SectionLine
]
78 if str(SectionLine
).find(TAB_COMMA_SPLIT
) > -1:
79 SubSectionList
= str(SectionLine
).split(TAB_COMMA_SPLIT
)
80 for SubSection
in SubSectionList
:
81 SectionList
= SubSection
.split(TAB_SPLIT
)
83 if len(SectionList
) == 1:
84 SubKey
= (TAB_ARCH_COMMON
, TAB_ARCH_COMMON
)
85 elif len(SectionList
) == 2:
86 SubKey
= (SectionList
[1], TAB_ARCH_COMMON
)
87 elif len(SectionList
) == 3:
88 SubKey
= (SectionList
[1], SectionList
[2])
90 EdkLogger
.error("build", AUTOGEN_ERROR
, 'Section %s is invalid.' % key
)
91 DepexExpresionList
.append({SubKey
: SectionDataDict
[key
]})
92 return DepexExpresionList