Esempio n. 1
0
def GenPackageUNIEncodeFile(PackageObject,
                            UniFileHeader='',
                            Encoding=TAB_ENCODING_UTF16LE):
    GenUNIFlag = False
    OnlyLANGUAGE_EN_X = True
    BinaryAbstract = []
    BinaryDescription = []
    #
    # If more than one language code is used for any element that would be present in the PACKAGE_UNI_FILE,
    # then the PACKAGE_UNI_FILE must be created.
    #
    for (Key, Value
         ) in PackageObject.GetAbstract() + PackageObject.GetDescription():
        if Key == TAB_LANGUAGE_EN_X:
            GenUNIFlag = True
        else:
            OnlyLANGUAGE_EN_X = False

    for UserExtension in PackageObject.GetUserExtensionList():
        if UserExtension.GetUserID() == TAB_BINARY_HEADER_USERID \
        and UserExtension.GetIdentifier() == TAB_BINARY_HEADER_IDENTIFIER:
            for (Key, Value) in UserExtension.GetBinaryAbstract():
                if Key == TAB_LANGUAGE_EN_X:
                    GenUNIFlag = True
                else:
                    OnlyLANGUAGE_EN_X = False
                BinaryAbstract.append((Key, Value))

            for (Key, Value) in UserExtension.GetBinaryDescription():
                if Key == TAB_LANGUAGE_EN_X:
                    GenUNIFlag = True
                else:
                    OnlyLANGUAGE_EN_X = False
                BinaryDescription.append((Key, Value))

    for Pcd in PackageObject.GetPcdList():
        for TxtObj in Pcd.GetPromptList() + Pcd.GetHelpTextList():
            if TxtObj.GetLang() == TAB_LANGUAGE_EN_X:
                GenUNIFlag = True
            else:
                OnlyLANGUAGE_EN_X = False

        for PcdError in Pcd.GetPcdErrorsList():
            if PcdError.GetErrorNumber().startswith(
                    '0x') or PcdError.GetErrorNumber().startswith('0X'):
                for (Key, Value) in PcdError.GetErrorMessageList():
                    if Key == TAB_LANGUAGE_EN_X:
                        GenUNIFlag = True
                    else:
                        OnlyLANGUAGE_EN_X = False
    if not GenUNIFlag:
        return
    elif OnlyLANGUAGE_EN_X:
        return
    else:
        PackageObject.UNIFlag = True

    if not os.path.exists(os.path.dirname(PackageObject.GetFullPath())):
        os.makedirs(os.path.dirname(PackageObject.GetFullPath()))

    ContainerFile = GetUniFileName(
        os.path.dirname(PackageObject.GetFullPath()),
        PackageObject.GetBaseName())

    Content = UniFileHeader + '\r\n'
    Content += '\r\n'

    Content += FormatUniEntry('#string ' + TAB_DEC_PACKAGE_ABSTRACT,
                              PackageObject.GetAbstract(),
                              ContainerFile) + '\r\n'

    Content += FormatUniEntry('#string ' + TAB_DEC_PACKAGE_DESCRIPTION, PackageObject.GetDescription(), ContainerFile) \
    + '\r\n'

    Content += FormatUniEntry('#string ' + TAB_DEC_BINARY_ABSTRACT,
                              BinaryAbstract, ContainerFile) + '\r\n'

    Content += FormatUniEntry('#string ' + TAB_DEC_BINARY_DESCRIPTION,
                              BinaryDescription, ContainerFile) + '\r\n'

    PromptGenList = []
    HelpTextGenList = []
    for Pcd in PackageObject.GetPcdList():
        # Generate Prompt for each Pcd
        PcdPromptStrName = '#string ' + 'STR_' + Pcd.GetTokenSpaceGuidCName(
        ) + '_' + Pcd.GetCName() + '_PROMPT '
        TokenValueList = []
        for TxtObj in Pcd.GetPromptList():
            Lang = TxtObj.GetLang()
            PromptStr = TxtObj.GetString()
            #
            # Avoid generating the same PROMPT entry more than one time.
            #
            if (PcdPromptStrName, Lang) not in PromptGenList:
                TokenValueList.append((Lang, PromptStr))
                PromptGenList.append((PcdPromptStrName, Lang))
        PromptString = FormatUniEntry(PcdPromptStrName, TokenValueList,
                                      ContainerFile) + '\r\n'
        if PromptString not in Content:
            Content += PromptString

        # Generate Help String for each Pcd
        PcdHelpStrName = '#string ' + 'STR_' + Pcd.GetTokenSpaceGuidCName(
        ) + '_' + Pcd.GetCName() + '_HELP '
        TokenValueList = []
        for TxtObj in Pcd.GetHelpTextList():
            Lang = TxtObj.GetLang()
            HelpStr = TxtObj.GetString()
            #
            # Avoid generating the same HELP entry more than one time.
            #
            if (PcdHelpStrName, Lang) not in HelpTextGenList:
                TokenValueList.append((Lang, HelpStr))
                HelpTextGenList.append((PcdHelpStrName, Lang))
        HelpTextString = FormatUniEntry(PcdHelpStrName, TokenValueList,
                                        ContainerFile) + '\r\n'
        if HelpTextString not in Content:
            Content += HelpTextString

        # Generate PcdError for each Pcd if ErrorNo exist.
        for PcdError in Pcd.GetPcdErrorsList():
            ErrorNo = PcdError.GetErrorNumber()
            if ErrorNo.startswith(TAB_HEX_START) or ErrorNo.startswith(
                    TAB_CAPHEX_START):
                PcdErrStrName = '#string ' + TAB_STR_TOKENCNAME + TAB_UNDERLINE_SPLIT + Pcd.GetTokenSpaceGuidCName() \
                    + TAB_UNDERLINE_SPLIT + TAB_STR_TOKENERR \
                    + TAB_UNDERLINE_SPLIT + ErrorNo[2:]
                PcdErrString = FormatUniEntry(PcdErrStrName,
                                              PcdError.GetErrorMessageList(),
                                              ContainerFile) + '\r\n'
                if PcdErrString not in Content:
                    Content += PcdErrString

    File = codecs.open(ContainerFile, 'w', Encoding)
    File.write(u'\uFEFF' + Content)
    File.stream.close()
    Md5Signature = md5(__FileHookOpen__(str(ContainerFile), 'rb').read())
    Md5Sum = Md5Signature.hexdigest()
    if (ContainerFile, Md5Sum) not in PackageObject.FileList:
        PackageObject.FileList.append((ContainerFile, Md5Sum))

    return ContainerFile
Esempio n. 2
0
def GenModuleUNIEncodeFile(ModuleObject, UniFileHeader='', Encoding=DT.TAB_ENCODING_UTF16LE):
    GenUNIFlag = False
    OnlyLANGUAGE_EN_X = True
    BinaryAbstract = []
    BinaryDescription = []
    #
    # If more than one language code is used for any element that would be present in the MODULE_UNI_FILE,
    # then the MODULE_UNI_FILE must be created.
    #
    for (Key, Value) in ModuleObject.GetAbstract() + ModuleObject.GetDescription():
        if Key == DT.TAB_LANGUAGE_EN_X:
            GenUNIFlag = True
        else:
            OnlyLANGUAGE_EN_X = False

    for UserExtension in ModuleObject.GetUserExtensionList():
        if UserExtension.GetUserID() == DT.TAB_BINARY_HEADER_USERID \
        and UserExtension.GetIdentifier() == DT.TAB_BINARY_HEADER_IDENTIFIER:
            for (Key, Value) in UserExtension.GetBinaryAbstract():
                if Key == DT.TAB_LANGUAGE_EN_X:
                    GenUNIFlag = True
                else:
                    OnlyLANGUAGE_EN_X = False
                BinaryAbstract.append((Key, Value))
            for (Key, Value) in UserExtension.GetBinaryDescription():
                if Key == DT.TAB_LANGUAGE_EN_X:
                    GenUNIFlag = True
                else:
                    OnlyLANGUAGE_EN_X = False
                BinaryDescription.append((Key, Value))


    if not GenUNIFlag:
        return
    elif OnlyLANGUAGE_EN_X:
        return
    else:
        ModuleObject.UNIFlag = True
    ContainerFile = GetUniFileName(os.path.dirname(ModuleObject.GetFullPath()), ModuleObject.GetBaseName())

    if not os.path.exists(os.path.dirname(ModuleObject.GetFullPath())):
        os.makedirs(os.path.dirname(ModuleObject.GetFullPath()))

    Content = UniFileHeader + '\n'
    Content += '\n'

    Content += FormatUniEntry('#string ' + DT.TAB_INF_ABSTRACT, ModuleObject.GetAbstract(), ContainerFile) + '\n'

    Content += FormatUniEntry('#string ' + DT.TAB_INF_DESCRIPTION, ModuleObject.GetDescription(), ContainerFile) \
            + '\n'

    BinaryAbstractString = FormatUniEntry('#string ' + DT.TAB_INF_BINARY_ABSTRACT, BinaryAbstract, ContainerFile)
    if BinaryAbstractString:
        Content += BinaryAbstractString + '\n'

    BinaryDescriptionString = FormatUniEntry('#string ' + DT.TAB_INF_BINARY_DESCRIPTION, BinaryDescription, \
                                             ContainerFile)
    if BinaryDescriptionString:
        Content += BinaryDescriptionString + '\n'

    if not os.path.exists(ContainerFile):
        File = codecs.open(ContainerFile, 'wb', Encoding)
        File.write(u'\uFEFF' + Content)
        File.stream.close()
    Md5Sigature = md5(__FileHookOpen__(str(ContainerFile), 'rb').read())
    Md5Sum = Md5Sigature.hexdigest()
    if (ContainerFile, Md5Sum) not in ModuleObject.FileList:
        ModuleObject.FileList.append((ContainerFile, Md5Sum))

    return ContainerFile