]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/UPT/Xml/XmlParserMisc.py
BaseTools: Clear build versions to sync with buildtools/BaseTools
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Xml / XmlParserMisc.py
CommitLineData
4234283c
LG
1## @file\r
2# This file is used to parse a xml file of .PKG file\r
3#\r
4# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
5#\r
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
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
16XmlParserMisc\r
17'''\r
18from Object.POM.CommonObject import TextObject\r
19from Logger.StringTable import ERR_XML_PARSER_REQUIRED_ITEM_MISSING\r
20from Logger.ToolError import PARSER_ERROR\r
21import Logger.Log as Logger\r
22\r
23## ConvertVariableName()\r
24# Convert VariableName to be L"string", \r
25# input of UCS-2 format Hex Array or L"string" (C style.) could be converted successfully,\r
26# others will not.\r
27#\r
28# @param VariableName: string need to be converted\r
29# @retval: the L quoted string converted if success, else None will be returned\r
30#\r
31def ConvertVariableName(VariableName):\r
32 VariableName = VariableName.strip()\r
33 #\r
34 # check for L quoted string \r
35 #\r
36 if VariableName.startswith('L"') and VariableName.endswith('"'):\r
37 return VariableName\r
38 \r
39 #\r
40 # check for Hex Array, it should be little endian even number of hex numbers\r
41 #\r
42 ValueList = VariableName.split(' ')\r
43 if len(ValueList)%2 == 1:\r
44 return None\r
45\r
46 TransferedStr = ''\r
47\r
48 Index = 0\r
49\r
50 while Index < len(ValueList):\r
51 FirstByte = int(ValueList[Index], 16)\r
52 SecondByte = int(ValueList[Index + 1], 16)\r
53 if SecondByte != 0:\r
54 return None\r
55 \r
56 if FirstByte not in xrange(0x20, 0x7F):\r
57 return None\r
58 TransferedStr += ('%c')%FirstByte\r
59 Index = Index + 2\r
60\r
61 return 'L"' + TransferedStr + '"'\r
62\r
63## IsRequiredItemListNull\r
64#\r
65# Check if a required XML section item/attribue is NULL\r
66# \r
67# @param ItemList: The list of items to be checked\r
68# @param XmlTreeLevel: The error message tree level\r
69# \r
70def IsRequiredItemListNull(ItemDict, XmlTreeLevel):\r
71 for Key in ItemDict:\r
72 if not ItemDict[Key]:\r
73 Msg = "->".join(Node for Node in XmlTreeLevel)\r
74 ErrorMsg = ERR_XML_PARSER_REQUIRED_ITEM_MISSING % (Key, Msg)\r
75 Logger.Error('\nUPT', PARSER_ERROR, ErrorMsg, RaiseError=True)\r
76\r
77 \r
78## Get help text \r
79#\r
80# @param HelpText\r
81#\r
82def GetHelpTextList(HelpText):\r
83 HelpTextList = []\r
84 for HelT in HelpText:\r
85 HelpTextObj = TextObject()\r
86 HelpTextObj.SetLang(HelT.Lang)\r
87 HelpTextObj.SetString(HelT.HelpText)\r
88 HelpTextList.append(HelpTextObj)\r
89 return HelpTextList\r