]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Common/Dictionary.py
2 # Define a dictionary structure
4 # Copyright (c) 2007, 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.
18 from DataType
import *
20 ## Convert a text file to a dictionary
22 # Convert a text file to a dictionary of (name:value) pairs.
24 # @retval 0 Convert successful
25 # @retval 1 Open file failed
27 def ConvertTextFileToDictionary(FileName
, Dictionary
, CommentCharacter
, KeySplitCharacter
, ValueSplitFlag
, ValueSplitCharacter
):
29 F
= open(FileName
,'r')
32 if Line
.startswith(CommentCharacter
):
34 LineList
= Line
.split(KeySplitCharacter
,1)
35 if len(LineList
) >= 2:
36 Key
= LineList
[0].split()
37 if len(Key
) == 1 and Key
[0][0] != CommentCharacter
and Key
[0] not in Keys
:
39 Dictionary
[Key
[0]] = LineList
[1].replace('\\','/').split(ValueSplitCharacter
)
41 Dictionary
[Key
[0]] = LineList
[1].strip().replace('\\','/')
46 EdkLogger
.info('Open file failed')
49 ## Print the dictionary
51 # Print all items of dictionary one by one
53 # @param Dict: The dictionary to be printed
60 print Key
+ ' = ' + str(Dict
[Key
])
62 ## Print the dictionary
64 # Print the items of dictionary which matched with input key
66 # @param list: The dictionary to be printed
67 # @param key: The key of the item to be printed
69 def printList(Key
, List
):
70 if type(List
) == type([]):
72 if Key
.find(TAB_SPLIT
) != -1: