]>
Commit | Line | Data |
---|---|---|
4234283c LG |
1 | ## @file\r |
2 | # This file is used to parse a xml file of .PKG file\r | |
3 | #\r | |
64285f15 | 4 | # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r |
4234283c | 5 | #\r |
2e351cbe | 6 | # SPDX-License-Identifier: BSD-2-Clause-Patent\r |
4234283c LG |
7 | #\r |
8 | \r | |
9 | '''\r | |
10 | GuidProtocolPpiXml\r | |
11 | '''\r | |
64285f15 YZ |
12 | from Library.StringUtils import ConvertNEToNOTEQ\r |
13 | from Library.StringUtils import ConvertNOTEQToNE\r | |
14 | from Library.StringUtils import GetStringOfList\r | |
4234283c LG |
15 | from Library.Xml.XmlRoutines import XmlElement\r |
16 | from Library.Xml.XmlRoutines import XmlAttribute\r | |
17 | from Library.Xml.XmlRoutines import XmlNode\r | |
18 | from Library.Xml.XmlRoutines import XmlList\r | |
19 | from Library.Xml.XmlRoutines import CreateXmlElement\r | |
20 | \r | |
21 | from Object.POM.CommonObject import GuidObject\r | |
22 | from Object.POM.CommonObject import ProtocolObject\r | |
23 | from Object.POM.CommonObject import PpiObject\r | |
24 | \r | |
25 | from Xml.CommonXml import CommonDefinesXml\r | |
26 | from Xml.CommonXml import HelpTextXml\r | |
27 | \r | |
28 | from Xml.XmlParserMisc import GetHelpTextList\r | |
29 | \r | |
30 | ##\r | |
31 | #GUID/Protocol/Ppi Common\r | |
32 | #\r | |
33 | class GuidProtocolPpiXml(object):\r | |
34 | def __init__(self, Mode):\r | |
35 | self.UiName = ''\r | |
36 | self.GuidTypes = ''\r | |
37 | self.Notify = ''\r | |
38 | self.CName = ''\r | |
39 | self.GuidValue = ''\r | |
40 | self.CommonDefines = CommonDefinesXml()\r | |
41 | self.HelpText = []\r | |
42 | #\r | |
f7496d71 | 43 | # Guid/Ppi/Library, internal used for indicate return object for\r |
4234283c LG |
44 | # FromXml\r |
45 | #\r | |
f7496d71 | 46 | self.Type = ''\r |
4234283c LG |
47 | #\r |
48 | # there are slightly different field between package and module\r | |
49 | #\r | |
50 | self.Mode = Mode\r | |
51 | self.GuidType = ''\r | |
52 | self.VariableName = ''\r | |
f7496d71 | 53 | \r |
4234283c LG |
54 | def FromXml(self, Item, Key):\r |
55 | self.UiName = XmlAttribute(XmlNode(Item, '%s' % Key), 'UiName')\r | |
56 | self.GuidType = XmlAttribute(XmlNode(Item, '%s' % Key), 'GuidType')\r | |
57 | self.Notify = XmlAttribute(XmlNode(Item, '%s' % Key), 'Notify')\r | |
58 | self.CName = XmlElement(Item, '%s/CName' % Key)\r | |
59 | self.GuidValue = XmlElement(Item, '%s/GuidValue' % Key)\r | |
60 | self.VariableName = XmlElement(Item, '%s/VariableName' % Key)\r | |
61 | self.CommonDefines.FromXml(XmlNode(Item, '%s' % Key), Key)\r | |
62 | for HelpTextItem in XmlList(Item, '%s/HelpText' % Key):\r | |
63 | HelpTextObj = HelpTextXml()\r | |
64 | HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key)\r | |
65 | self.HelpText.append(HelpTextObj)\r | |
f7496d71 LG |
66 | \r |
67 | if self.Type == 'Guid':\r | |
4234283c LG |
68 | GuidProtocolPpi = GuidObject()\r |
69 | elif self.Type == 'Protocol':\r | |
70 | GuidProtocolPpi = ProtocolObject()\r | |
71 | else:\r | |
72 | GuidProtocolPpi = PpiObject()\r | |
73 | GuidProtocolPpi.SetHelpTextList(GetHelpTextList(self.HelpText))\r | |
74 | \r | |
75 | return GuidProtocolPpi\r | |
76 | \r | |
77 | def ToXml(self, GuidProtocolPpi, Key):\r | |
78 | if self.GuidValue:\r | |
79 | pass\r | |
80 | AttributeList = \\r | |
81 | [['Usage', GetStringOfList(GuidProtocolPpi.GetUsage())], \\r | |
82 | ['UiName', GuidProtocolPpi.GetName()], \\r | |
83 | ['GuidType', GetStringOfList(GuidProtocolPpi.GetGuidTypeList())], \\r | |
84 | ['Notify', str(GuidProtocolPpi.GetNotify()).lower()], \\r | |
85 | ['SupArchList', GetStringOfList(GuidProtocolPpi.GetSupArchList())], \\r | |
86 | ['SupModList', GetStringOfList(GuidProtocolPpi.GetSupModuleList())], \\r | |
87 | ['FeatureFlag', ConvertNEToNOTEQ(GuidProtocolPpi.GetFeatureFlag())]\r | |
88 | ]\r | |
f7496d71 | 89 | NodeList = [['CName', GuidProtocolPpi.GetCName()],\r |
4234283c LG |
90 | ['GuidValue', GuidProtocolPpi.GetGuid()],\r |
91 | ['VariableName', GuidProtocolPpi.VariableName]\r | |
92 | ]\r | |
93 | for Item in GuidProtocolPpi.GetHelpTextList():\r | |
94 | Tmp = HelpTextXml()\r | |
95 | NodeList.append(Tmp.ToXml(Item))\r | |
96 | Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)\r | |
f7496d71 | 97 | \r |
4234283c LG |
98 | return Root\r |
99 | \r | |
100 | def __str__(self):\r | |
101 | Str = \\r | |
102 | "UiName = %s Notify = %s GuidTypes = %s CName = %s GuidValue = %s %s" \\r | |
103 | % (self.UiName, self.Notify, self.GuidTypes, self.CName, \\r | |
104 | self.GuidValue, self.CommonDefines)\r | |
105 | for Item in self.HelpText:\r | |
106 | Str = Str + "\n\t" + str(Item)\r | |
107 | return Str\r | |
108 | ##\r | |
109 | #GUID Xml\r | |
110 | #\r | |
111 | class GuidXml(GuidProtocolPpiXml):\r | |
112 | def __init__(self, Mode):\r | |
113 | GuidProtocolPpiXml.__init__(self, Mode)\r | |
114 | self.Type = 'Guid'\r | |
f7496d71 LG |
115 | \r |
116 | def FromXml(self, Item, Key):\r | |
4234283c LG |
117 | GuidProtocolPpi = GuidProtocolPpiXml.FromXml(self, Item, Key)\r |
118 | \r | |
119 | if self.Mode == 'Package':\r | |
f7496d71 | 120 | \r |
4234283c LG |
121 | GuidProtocolPpi.SetSupArchList(self.CommonDefines.SupArchList)\r |
122 | GuidProtocolPpi.SetSupModuleList(self.CommonDefines.SupModList)\r | |
123 | GuidProtocolPpi.SetCName(self.CName)\r | |
124 | GuidProtocolPpi.SetGuid(self.GuidValue)\r | |
125 | else:\r | |
126 | GuidProtocolPpi.SetUsage(self.CommonDefines.Usage)\r | |
127 | if self.GuidType:\r | |
128 | GuidProtocolPpi.SetGuidTypeList([self.GuidType])\r | |
129 | GuidProtocolPpi.SetSupArchList(self.CommonDefines.SupArchList)\r | |
130 | GuidProtocolPpi.SetFeatureFlag(ConvertNOTEQToNE(self.CommonDefines.FeatureFlag))\r | |
131 | GuidProtocolPpi.SetCName(self.CName)\r | |
132 | GuidProtocolPpi.SetVariableName(self.VariableName)\r | |
133 | return GuidProtocolPpi\r | |
134 | \r | |
135 | def ToXml(self, GuidProtocolPpi, Key):\r | |
f7496d71 | 136 | if self.Mode == 'Package':\r |
4234283c LG |
137 | AttributeList = \\r |
138 | [['GuidType', \\r | |
139 | GetStringOfList(GuidProtocolPpi.GetGuidTypeList())], \\r | |
140 | ['SupArchList', \\r | |
141 | GetStringOfList(GuidProtocolPpi.GetSupArchList())], \\r | |
142 | ['SupModList', \\r | |
f7496d71 | 143 | GetStringOfList(GuidProtocolPpi.GetSupModuleList())],\r |
4234283c | 144 | ]\r |
f7496d71 | 145 | NodeList = [['CName', GuidProtocolPpi.GetCName()],\r |
4234283c LG |
146 | ['GuidValue', GuidProtocolPpi.GetGuid()],\r |
147 | ]\r | |
148 | else:\r | |
149 | AttributeList = \\r | |
150 | [['Usage', GetStringOfList(GuidProtocolPpi.GetUsage())], \\r | |
151 | ['GuidType', GetStringOfList(GuidProtocolPpi.GetGuidTypeList())],\\r | |
152 | ['SupArchList', \\r | |
153 | GetStringOfList(GuidProtocolPpi.GetSupArchList())], \\r | |
154 | ['FeatureFlag', ConvertNEToNOTEQ(GuidProtocolPpi.GetFeatureFlag())]\r | |
155 | ]\r | |
f7496d71 | 156 | NodeList = [['CName', GuidProtocolPpi.GetCName()],\r |
4234283c LG |
157 | ['VariableName', GuidProtocolPpi.GetVariableName()]\r |
158 | ]\r | |
159 | \r | |
160 | for Item in GuidProtocolPpi.GetHelpTextList():\r | |
161 | Tmp = HelpTextXml()\r | |
162 | NodeList.append(Tmp.ToXml(Item))\r | |
163 | Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)\r | |
f7496d71 | 164 | \r |
4234283c LG |
165 | return Root\r |
166 | ##\r | |
167 | #Protocol Xml\r | |
168 | #\r | |
169 | class ProtocolXml(GuidProtocolPpiXml):\r | |
170 | def __init__(self, Mode):\r | |
171 | GuidProtocolPpiXml.__init__(self, Mode)\r | |
172 | self.Type = 'Protocol'\r | |
f7496d71 | 173 | \r |
4234283c LG |
174 | def FromXml(self, Item, Key):\r |
175 | GuidProtocolPpi = GuidProtocolPpiXml.FromXml(self, Item, Key)\r | |
176 | if self.Mode == 'Package':\r | |
f7496d71 | 177 | GuidProtocolPpi.SetFeatureFlag(self.CommonDefines.FeatureFlag)\r |
4234283c LG |
178 | GuidProtocolPpi.SetSupArchList(self.CommonDefines.SupArchList)\r |
179 | GuidProtocolPpi.SetSupModuleList(self.CommonDefines.SupModList)\r | |
180 | GuidProtocolPpi.SetCName(self.CName)\r | |
181 | GuidProtocolPpi.SetGuid(self.GuidValue)\r | |
182 | else:\r | |
183 | GuidProtocolPpi.SetUsage(self.CommonDefines.Usage)\r | |
184 | if self.Notify.upper() == "TRUE":\r | |
185 | GuidProtocolPpi.SetNotify(True)\r | |
186 | elif self.Notify.upper() == "FALSE":\r | |
187 | GuidProtocolPpi.SetNotify(False)\r | |
188 | else:\r | |
189 | GuidProtocolPpi.SetNotify('')\r | |
190 | GuidProtocolPpi.SetSupArchList(self.CommonDefines.SupArchList)\r | |
191 | GuidProtocolPpi.SetFeatureFlag(ConvertNOTEQToNE(self.CommonDefines.FeatureFlag))\r | |
192 | GuidProtocolPpi.SetCName(self.CName)\r | |
f7496d71 | 193 | \r |
4234283c LG |
194 | return GuidProtocolPpi\r |
195 | \r | |
196 | def ToXml(self, GuidProtocolPpi, Key):\r | |
f7496d71 | 197 | if self.Mode == 'Package':\r |
4234283c LG |
198 | AttributeList = \\r |
199 | [['SupArchList', \\r | |
200 | GetStringOfList(GuidProtocolPpi.GetSupArchList())], \\r | |
201 | ['SupModList', \\r | |
202 | GetStringOfList(GuidProtocolPpi.GetSupModuleList())], \\r | |
203 | ['FeatureFlag', GuidProtocolPpi.GetFeatureFlag()]\r | |
204 | ]\r | |
f7496d71 | 205 | NodeList = [['CName', GuidProtocolPpi.GetCName()],\r |
4234283c LG |
206 | ['GuidValue', GuidProtocolPpi.GetGuid()],\r |
207 | ]\r | |
208 | else:\r | |
209 | AttributeList = \\r | |
210 | [['Usage', GetStringOfList(GuidProtocolPpi.GetUsage())], \\r | |
211 | ['Notify', str(GuidProtocolPpi.GetNotify()).lower()], \\r | |
212 | ['SupArchList', \\r | |
213 | GetStringOfList(GuidProtocolPpi.GetSupArchList())], \\r | |
214 | ['FeatureFlag', ConvertNEToNOTEQ(GuidProtocolPpi.GetFeatureFlag())]\r | |
215 | ]\r | |
f7496d71 | 216 | NodeList = [['CName', GuidProtocolPpi.GetCName()],\r |
4234283c | 217 | ]\r |
f7496d71 | 218 | \r |
4234283c LG |
219 | for Item in GuidProtocolPpi.GetHelpTextList():\r |
220 | Tmp = HelpTextXml()\r | |
221 | NodeList.append(Tmp.ToXml(Item))\r | |
222 | Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)\r | |
f7496d71 | 223 | \r |
4234283c LG |
224 | return Root\r |
225 | ##\r | |
226 | #Ppi Xml\r | |
227 | #\r | |
228 | class PpiXml(GuidProtocolPpiXml):\r | |
229 | def __init__(self, Mode):\r | |
230 | GuidProtocolPpiXml.__init__(self, Mode)\r | |
231 | self.Type = 'Ppi'\r | |
f7496d71 | 232 | \r |
4234283c LG |
233 | def FromXml(self, Item, Key):\r |
234 | GuidProtocolPpi = GuidProtocolPpiXml.FromXml(self, Item, Key)\r | |
235 | if self.Mode == 'Package':\r | |
236 | GuidProtocolPpi.SetSupArchList(self.CommonDefines.SupArchList)\r | |
237 | GuidProtocolPpi.SetSupModuleList(self.CommonDefines.SupModList)\r | |
238 | GuidProtocolPpi.SetCName(self.CName)\r | |
239 | GuidProtocolPpi.SetGuid(self.GuidValue)\r | |
240 | else:\r | |
241 | GuidProtocolPpi.SetUsage(self.CommonDefines.Usage)\r | |
242 | if self.Notify.upper() == "TRUE":\r | |
243 | GuidProtocolPpi.SetNotify(True)\r | |
244 | elif self.Notify.upper() == "FALSE":\r | |
245 | GuidProtocolPpi.SetNotify(False)\r | |
246 | else:\r | |
247 | GuidProtocolPpi.SetNotify('')\r | |
248 | GuidProtocolPpi.SetSupArchList(self.CommonDefines.SupArchList)\r | |
249 | GuidProtocolPpi.SetFeatureFlag(ConvertNOTEQToNE(self.CommonDefines.FeatureFlag))\r | |
250 | GuidProtocolPpi.SetCName(self.CName)\r | |
f7496d71 | 251 | \r |
4234283c LG |
252 | return GuidProtocolPpi\r |
253 | \r | |
254 | def ToXml(self, GuidProtocolPpi, Key):\r | |
255 | if self.Mode == 'Package':\r | |
256 | AttributeList = \\r | |
257 | [['SupArchList', \\r | |
f7496d71 | 258 | GetStringOfList(GuidProtocolPpi.GetSupArchList())],\r |
4234283c | 259 | ]\r |
f7496d71 | 260 | NodeList = [['CName', GuidProtocolPpi.GetCName()],\r |
4234283c LG |
261 | ['GuidValue', GuidProtocolPpi.GetGuid()],\r |
262 | ]\r | |
263 | else:\r | |
264 | AttributeList = \\r | |
265 | [['Usage', GetStringOfList(GuidProtocolPpi.GetUsage())], \\r | |
266 | ['Notify', str(GuidProtocolPpi.GetNotify()).lower()], \\r | |
267 | ['SupArchList', \\r | |
268 | GetStringOfList(GuidProtocolPpi.GetSupArchList())], \\r | |
269 | ['FeatureFlag', ConvertNEToNOTEQ(GuidProtocolPpi.GetFeatureFlag())]\r | |
270 | ]\r | |
f7496d71 | 271 | NodeList = [['CName', GuidProtocolPpi.GetCName()],\r |
4234283c | 272 | ]\r |
f7496d71 | 273 | \r |
4234283c LG |
274 | for Item in GuidProtocolPpi.GetHelpTextList():\r |
275 | Tmp = HelpTextXml()\r | |
276 | NodeList.append(Tmp.ToXml(Item))\r | |
277 | Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)\r | |
278 | return Root\r |