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