def testNormalCase1(self): HelpStr = 'Hello world' HelpTextObj = TextObject() HelpTextObj.SetLang(TAB_LANGUAGE_EN_US) HelpTextObj.SetString(HelpStr) HelpTextList = [HelpTextObj] Result = _GetHelpStr(HelpTextList) self.assertEqual(Result, HelpStr)
def GuidFactory(self, CName, FFE, Usage, GuidType, VariableName, HelpStr): Guid = GuidObject() Guid.SetCName(CName) Guid.SetFeatureFlag(FFE) Guid.SetGuidTypeList([GuidType]) Guid.SetUsage(Usage) Guid.SetVariableName(VariableName) HelpTextObj = TextObject() HelpTextObj.SetLang('') HelpTextObj.SetString(HelpStr) Guid.SetHelpTextList([HelpTextObj]) return Guid
def ObjectFactory(self, SupArchList, Type, Usage, Str): Object = HobObject() HelpStr = Str Object.SetHobType(Type) Object.SetUsage(Usage) Object.SetSupArchList(SupArchList) HelpTextObj = TextObject() HelpTextObj.SetLang('') HelpTextObj.SetString(HelpStr) Object.SetHelpTextList([HelpTextObj]) return Object
def FromXml(self, Item, Key): self.HeaderFile = XmlElement(Item, '%s/HeaderFile' % Key) for HelpTextItem in XmlList(Item, '%s/HelpText' % Key): HelpTextObj = HelpTextXml() HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key) self.HelpText.append(HelpTextObj) Include = IncludeObject() Include.SetFilePath(self.HeaderFile) HelpTxt = TextObject() HelpTxt.SetString(self.HelpText) Include.SetHelpText(HelpTxt) return Include
def FromXml(self, Item, Key): self.HeaderFile = XmlElement(Item, '%s/HeaderFile' % Key) self.CommonDefines.FromXml(XmlNode(Item, '%s/HeaderFile' % Key), 'HeaderFile') for HelpTextItem in XmlList(Item, '%s/HelpText' % Key): HelpTextObj = HelpTextXml() HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key) self.HelpText.append(HelpTextObj) Include = IncludeObject() Include.SetFilePath(self.HeaderFile) Include.SetSupArchList(self.CommonDefines.SupArchList) HelpTxt = TextObject() HelpTxt.SetString(self.HelpText) Include.SetHelpText(HelpTxt) return Include
def ObjectFactory(self, ItemType, TSCName, CName, DValue, FFE, Usage, Str): Object = PcdObject() HelpStr = Str Object.SetItemType(ItemType) Object.SetTokenSpaceGuidCName(TSCName) Object.SetCName(CName) Object.SetDefaultValue(DValue) Object.SetFeatureFlag(FFE) Object.SetValidUsage(Usage) HelpTextObj = TextObject() HelpTextObj.SetLang('') HelpTextObj.SetString(HelpStr) Object.SetHelpTextList([HelpTextObj]) return Object
def ObjectFactory(self, CName, FFE, Usage, Notify, HelpStr, IsProtocol): if IsProtocol: Object = ProtocolObject() else: Object = PpiObject() Object.SetCName(CName) Object.SetFeatureFlag(FFE) Object.SetUsage(Usage) Object.SetNotify(Notify) HelpTextObj = TextObject() HelpTextObj.SetLang('') HelpTextObj.SetString(HelpStr) Object.SetHelpTextList([HelpTextObj]) return Object
def GenPcdDeclaration(ContainerFile, PcdInfo, Language, MacroReplaceDict): HelpStr = '' PromptStr = '' TailHelpStr = '' TokenGuidCName, TokenName, Value, DatumType, Token, Type, \ GenericComment, TailComment, Arch = PcdInfo Pcd = PcdObject() Pcd.SetCName(TokenName) Pcd.SetToken(Token) Pcd.SetTokenSpaceGuidCName(TokenGuidCName) Pcd.SetDatumType(DatumType) Pcd.SetDefaultValue(Value) Pcd.SetValidUsage(Type) # # MaxDatumSize is required field for 'VOID*' PCD # if DatumType == TAB_PTR_TYPE_PCD: Pcd.SetMaxDatumSize(ITEM_UNDEFINED) SupArchList = [Arch] Pcd.SetSupArchList(SupArchList) if GenericComment: HelpStr, PcdErrList, PromptStr = ParseDecPcdGenericComment(GenericComment, ContainerFile, TokenGuidCName, TokenName, MacroReplaceDict) if PcdErrList: Pcd.SetPcdErrorsList(PcdErrList) if TailComment: SupModuleList, TailHelpStr = ParseDecPcdTailComment(TailComment, ContainerFile) if SupModuleList: Pcd.SetSupModuleList(SupModuleList) if HelpStr and (not HelpStr.endswith('\n')) and TailHelpStr: HelpStr += '\n' HelpStr += TailHelpStr if HelpStr: HelpTxtObj = TextObject() HelpTxtObj.SetLang(Language) HelpTxtObj.SetString(HelpStr) Pcd.SetHelpTextList([HelpTxtObj]) if PromptStr: TxtObj = TextObject() TxtObj.SetLang(Language) TxtObj.SetString(PromptStr) Pcd.SetPromptList([TxtObj]) return Pcd
def ParseGenericComment (GenericComment, ContainerFile=None, SkipTag=None): if ContainerFile: pass HelpTxt = None HelpStr = '' for Item in GenericComment: CommentLine = Item[0] Comment = CleanString2(CommentLine)[1] if SkipTag is not None and Comment.startswith(SkipTag): Comment = Comment.replace(SkipTag, '', 1) HelpStr += Comment + '\n' if HelpStr: HelpTxt = TextObject() if HelpStr.endswith('\n') and not HelpStr.endswith('\n\n') and HelpStr != '\n': HelpStr = HelpStr[:-1] HelpTxt.SetString(HelpStr) return HelpTxt
def testNormalCase4(self): ExpectedStr = 'Hello world1' HelpTextObj = TextObject() HelpTextObj.SetLang(TAB_LANGUAGE_ENG) HelpTextObj.SetString(ExpectedStr) HelpTextList = [HelpTextObj] HelpStr = 'Hello world' HelpTextObj = TextObject() HelpTextObj.SetLang('') HelpTextObj.SetString(HelpStr) HelpTextList.append(HelpTextObj) Result = _GetHelpStr(HelpTextList) self.assertEqual(Result, ExpectedStr)
def testNormalCase3(self): HelpStr = 'Hello world' HelpTextObj = TextObject() HelpTextObj.SetLang('') HelpTextObj.SetString(HelpStr) HelpTextList = [HelpTextObj] ExpectedStr = 'Hello world1' HelpTextObj = TextObject() HelpTextObj.SetLang('eng') HelpTextObj.SetString(ExpectedStr) HelpTextList.append(HelpTextObj) Result = _GetHelpStr(HelpTextList) self.assertEqual(Result, ExpectedStr)
def GenPcds(self, ContainerFile): Logger.Debug(2, "Generate %s ..." % TAB_PCDS) PcdObj = self.DecParser.GetPcdSectionObject() # # Get all Pcds # PcdDeclarations = [] IterList = [ (TAB_PCDS_FIXED_AT_BUILD_NULL, 'FixedPcd'), (TAB_PCDS_PATCHABLE_IN_MODULE_NULL, 'PatchPcd'), (TAB_PCDS_FEATURE_FLAG_NULL, 'FeaturePcd'), (TAB_PCDS_DYNAMIC_EX_NULL, 'PcdEx'), (TAB_PCDS_DYNAMIC_NULL, 'Pcd')] PromptStrList = [] HelpStrList = [] PcdErrStrList = [] # Initialize UniStrDict dictionary, top keys are language codes UniStrDict = {} StrList = [] Language = '' if self.UniFileClassObject: Language = TAB_LANGUAGE_EN_X else: Language = TAB_LANGUAGE_EN_US if self.UniFileClassObject: UniStrDict = self.UniFileClassObject.OrderedStringList for Lang in UniStrDict: for StringDefClassObject in UniStrDict[Lang]: StrList = StringDefClassObject.StringName.split('_') # StringName format is STR_<TOKENSPACECNAME>_<PCDCNAME>_PROMPT if len(StrList) == 4 and StrList[0] == TAB_STR_TOKENCNAME and StrList[3] == TAB_STR_TOKENPROMPT: PromptStrList.append((GetLanguageCode1766(Lang), StringDefClassObject.StringName, \ StringDefClassObject.StringValue)) # StringName format is STR_<TOKENSPACECNAME>_<PCDCNAME>_HELP if len(StrList) == 4 and StrList[0] == TAB_STR_TOKENCNAME and StrList[3] == TAB_STR_TOKENHELP: HelpStrList.append((GetLanguageCode1766(Lang), StringDefClassObject.StringName, \ StringDefClassObject.StringValue)) # StringName format is STR_<TOKENSPACECNAME>_ERR_## if len(StrList) == 4 and StrList[0] == TAB_STR_TOKENCNAME and StrList[2] == TAB_STR_TOKENERR: PcdErrStrList.append((GetLanguageCode1766(Lang), StringDefClassObject.StringName, \ StringDefClassObject.StringValue)) # # For each PCD type # for PcdType, Type in IterList: # # Go through all archs # # for Arch in self.SupArchList + [TAB_ARCH_COMMON]: # for Item in PcdObj.GetPcdsByType(PcdType.upper()): PcdDeclaration = GenPcdDeclaration( ContainerFile, (Item.TokenSpaceGuidCName, Item.TokenCName, Item.DefaultValue, Item.DatumType, Item.TokenValue, Type, Item.GetHeadComment(), Item.GetTailComment(), ''), Language, self.DecParser.GetDefineSectionMacro() ) PcdDeclaration.SetSupArchList(Item.GetArchListOfType(PcdType)) # # Get PCD error message from PCD error comment section in DEC file # for PcdErr in PcdDeclaration.GetPcdErrorsList(): if (PcdDeclaration.GetTokenSpaceGuidCName(), PcdErr.GetErrorNumber()) \ in self.DecParser.PcdErrorCommentDict: Key = (PcdDeclaration.GetTokenSpaceGuidCName(), PcdErr.GetErrorNumber()) PcdErr.SetErrorMessageList(PcdErr.GetErrorMessageList() + \ [(Language, self.DecParser.PcdErrorCommentDict[Key])]) for Index in range(0, len(PromptStrList)): StrNameList = PromptStrList[Index][1].split('_') if StrNameList[1].lower() == Item.TokenSpaceGuidCName.lower() and \ StrNameList[2].lower() == Item.TokenCName.lower(): TxtObj = TextObject() TxtObj.SetLang(PromptStrList[Index][0]) TxtObj.SetString(PromptStrList[Index][2]) for Prompt in PcdDeclaration.GetPromptList(): if Prompt.GetLang() == TxtObj.GetLang() and \ Prompt.GetString() == TxtObj.GetString(): break else: PcdDeclaration.SetPromptList(PcdDeclaration.GetPromptList() + [TxtObj]) for Index in range(0, len(HelpStrList)): StrNameList = HelpStrList[Index][1].split('_') if StrNameList[1].lower() == Item.TokenSpaceGuidCName.lower() and \ StrNameList[2].lower() == Item.TokenCName.lower(): TxtObj = TextObject() TxtObj.SetLang(HelpStrList[Index][0]) TxtObj.SetString(HelpStrList[Index][2]) for HelpStrObj in PcdDeclaration.GetHelpTextList(): if HelpStrObj.GetLang() == TxtObj.GetLang() and \ HelpStrObj.GetString() == TxtObj.GetString(): break else: PcdDeclaration.SetHelpTextList(PcdDeclaration.GetHelpTextList() + [TxtObj]) # # Get PCD error message from UNI file # for Index in range(0, len(PcdErrStrList)): StrNameList = PcdErrStrList[Index][1].split('_') if StrNameList[1].lower() == Item.TokenSpaceGuidCName.lower() and \ StrNameList[2].lower() == TAB_STR_TOKENERR.lower(): for PcdErr in PcdDeclaration.GetPcdErrorsList(): if PcdErr.GetErrorNumber().lower() == (TAB_HEX_START + StrNameList[3]).lower() and \ (PcdErrStrList[Index][0], PcdErrStrList[Index][2]) not in PcdErr.GetErrorMessageList(): PcdErr.SetErrorMessageList(PcdErr.GetErrorMessageList() + \ [(PcdErrStrList[Index][0], PcdErrStrList[Index][2])]) # # Check to prevent missing error message if a Pcd has the error code. # for PcdErr in PcdDeclaration.GetPcdErrorsList(): if PcdErr.GetErrorNumber().strip(): if not PcdErr.GetErrorMessageList(): Logger.Error('UPT', FORMAT_INVALID, ST.ERR_DECPARSE_PCD_UNMATCHED_ERRORCODE % PcdErr.GetErrorNumber(), ContainerFile, PcdErr.GetLineNum(), PcdErr.GetFileLine()) PcdDeclarations.append(PcdDeclaration) self.SetPcdList(self.GetPcdList() + PcdDeclarations) self.CheckPcdValue()
def testNormalCase5(self): ExpectedStr = 'Hello world1' HelpTextObj = TextObject() HelpTextObj.SetLang(TAB_LANGUAGE_EN_US) HelpTextObj.SetString(ExpectedStr) HelpTextList = [HelpTextObj] HelpStr = 'Hello unknown world' HelpTextObj = TextObject() HelpTextObj.SetLang('') HelpTextObj.SetString(HelpStr) HelpTextList.append(HelpTextObj) HelpStr = 'Hello mysterious world' HelpTextObj = TextObject() HelpTextObj.SetLang('') HelpTextObj.SetString(HelpStr) HelpTextList.append(HelpTextObj) Result = _GetHelpStr(HelpTextList) self.assertEqual(Result, ExpectedStr) HelpTextList.sort() self.assertEqual(Result, ExpectedStr) HelpTextList.sort(reverse=True) self.assertEqual(Result, ExpectedStr)
def GenDummyHelpTextObj(): HelpTxt = TextObject() HelpTxt.SetLang(TAB_LANGUAGE_EN_US) HelpTxt.SetString(' ') return HelpTxt