]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Common/Dictionary.py
2 # Define a dictionary structure
4 # Copyright (c) 2007 - 2014, 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 *
19 from Common
.LongFilePathSupport
import OpenLongFilePath
as open
21 ## Convert a text file to a dictionary
23 # Convert a text file to a dictionary of (name:value) pairs.
25 # @retval 0 Convert successful
26 # @retval 1 Open file failed
28 def ConvertTextFileToDictionary(FileName
, Dictionary
, CommentCharacter
, KeySplitCharacter
, ValueSplitFlag
, ValueSplitCharacter
):
30 F
= open(FileName
, 'r')
33 if Line
.startswith(CommentCharacter
):
35 LineList
= Line
.split(KeySplitCharacter
, 1)
36 if len(LineList
) >= 2:
37 Key
= LineList
[0].split()
38 if len(Key
) == 1 and Key
[0][0] != CommentCharacter
and Key
[0] not in Keys
:
40 Dictionary
[Key
[0]] = LineList
[1].replace('\\', '/').split(ValueSplitCharacter
)
42 Dictionary
[Key
[0]] = LineList
[1].strip().replace('\\', '/')
47 EdkLogger
.info('Open file failed')
50 ## Print the dictionary
52 # Print all items of dictionary one by one
54 # @param Dict: The dictionary to be printed
61 print Key
+ ' = ' + str(Dict
[Key
])
63 ## Print the dictionary
65 # Print the items of dictionary which matched with input key
67 # @param list: The dictionary to be printed
68 # @param key: The key of the item to be printed
70 def printList(Key
, List
):
71 if type(List
) == type([]):
73 if Key
.find(TAB_SPLIT
) != -1: