Example #1
0
def ConvertTextFileToDictionary(FileName, Dictionary, CommentCharacter,
                                KeySplitCharacter, ValueSplitFlag,
                                ValueSplitCharacter):
    try:
        F = open(FileName, 'r')
        Keys = []
        for Line in F:
            if Line.startswith(CommentCharacter):
                continue
            LineList = Line.split(KeySplitCharacter, 1)
            if len(LineList) >= 2:
                Key = LineList[0].split()
            if len(Key) == 1 and Key[0][0] != CommentCharacter and Key[
                    0] not in Keys:
                if ValueSplitFlag:
                    Dictionary[Key[0]] = LineList[1].replace(
                        '\\', '/').split(ValueSplitCharacter)
                else:
                    Dictionary[Key[0]] = LineList[1].strip().replace('\\', '/')
                Keys += [Key[0]]
        F.close()
        return 0
    except:
        EdkLogger.info('Open file failed')
        return 1
Example #2
0
def GetTextFileInfo(FileName, TagTuple):
    ValueTuple = [""] * len(TagTuple)
    try:
        for Line in open(FileName):
            Line = Line.split("#", 1)[0]
            MatchEquation = mReEquation.match(Line)
            if MatchEquation:
                Tag = MatchEquation.group(1).upper()
                Value = MatchEquation.group(2)
                for Index in range(len(TagTuple)):
                    if TagTuple[Index] == Tag:
                        ValueTuple[Index] = Value
    except:
        EdkLogger.info("IO Error in reading file %s" % FileName)

    return ValueTuple
Example #3
0
def GetTextFileInfo(FileName, TagTuple):
    ValueTuple = [""] * len(TagTuple)
    try:
        for Line in open(FileName):
            Line = Line.split("#", 1)[0]
            MatchEquation = mReEquation.match(Line)
            if MatchEquation:
                Tag = MatchEquation.group(1).upper()
                Value = MatchEquation.group(2)
                for Index in range(len(TagTuple)):
                    if TagTuple[Index] == Tag:
                        ValueTuple[Index] = Value
    except:
        EdkLogger.info("IO Error in reading file %s" % FileName)
        
    return ValueTuple
def ConvertTextFileToDictionary(FileName, Dictionary, CommentCharacter, KeySplitCharacter, ValueSplitFlag, ValueSplitCharacter):
    try:
        F = open(FileName,'r')
        Keys = []
        for Line in F:
            if Line.startswith(CommentCharacter):
                continue
            LineList = Line.split(KeySplitCharacter,1)
            if len(LineList) >= 2:
                Key = LineList[0].split()
            if len(Key) == 1 and Key[0][0] != CommentCharacter and Key[0] not in Keys:
                if ValueSplitFlag:
                    Dictionary[Key[0]] = LineList[1].replace('\\','/').split(ValueSplitCharacter)
                else:
                    Dictionary[Key[0]] = LineList[1].strip().replace('\\','/')
                Keys += [Key[0]]
        F.close()
        return 0
    except:
        EdkLogger.info('Open file failed')
        return 1