2 # This file is used to parse a xml file of .PKG file
4 # Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
6 # This program and the accompanying materials are licensed and made available
7 # under the terms and conditions of the BSD License which accompanies this
8 # distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 from Object
.POM
.CommonObject
import TextObject
19 from Logger
.StringTable
import ERR_XML_PARSER_REQUIRED_ITEM_MISSING
20 from Logger
.ToolError
import PARSER_ERROR
21 import Logger
.Log
as Logger
23 ## ConvertVariableName()
24 # Convert VariableName to be L"string",
25 # input of UCS-2 format Hex Array or L"string" (C style.) could be converted successfully,
28 # @param VariableName: string need to be converted
29 # @retval: the L quoted string converted if success, else None will be returned
31 def ConvertVariableName(VariableName
):
32 VariableName
= VariableName
.strip()
34 # check for L quoted string
36 if VariableName
.startswith('L"') and VariableName
.endswith('"'):
40 # check for Hex Array, it should be little endian even number of hex numbers
42 ValueList
= VariableName
.split(' ')
43 if len(ValueList
)%2 == 1:
50 while Index
< len(ValueList
):
51 FirstByte
= int(ValueList
[Index
], 16)
52 SecondByte
= int(ValueList
[Index
+ 1], 16)
56 if FirstByte
not in xrange(0x20, 0x7F):
58 TransferedStr
+= ('%c')%FirstByte
61 return 'L"' + TransferedStr
+ '"'
63 ## IsRequiredItemListNull
65 # Check if a required XML section item/attribue is NULL
67 # @param ItemList: The list of items to be checked
68 # @param XmlTreeLevel: The error message tree level
70 def IsRequiredItemListNull(ItemDict
, XmlTreeLevel
):
73 Msg
= "->".join(Node
for Node
in XmlTreeLevel
)
74 ErrorMsg
= ERR_XML_PARSER_REQUIRED_ITEM_MISSING
% (Key
, Msg
)
75 Logger
.Error('\nUPT', PARSER_ERROR
, ErrorMsg
, RaiseError
=True)
81 def GetHelpTextList(HelpText
):
84 HelpTextObj
= TextObject()
85 HelpTextObj
.SetLang(HelT
.Lang
)
86 HelpTextObj
.SetString(HelT
.HelpText
)
87 HelpTextList
.append(HelpTextObj
)
94 def GetPromptList(Prompt
):
96 for SubPrompt
in Prompt
:
97 PromptObj
= TextObject()
98 PromptObj
.SetLang(SubPrompt
.Lang
)
99 PromptObj
.SetString(SubPrompt
.Prompt
)
100 PromptList
.append(PromptObj
)