def __init__(self, RawData): _DecBase.__init__(self, RawData) self.ItemObject = DecDefineObject(RawData.Filename) self._LocalMacro = self._RawData.Macros self._DefSecNum = 0 # # Each field has a function to validate # self.DefineValidation = { DT.TAB_DEC_DEFINES_DEC_SPECIFICATION : self._SetDecSpecification, DT.TAB_DEC_DEFINES_PACKAGE_NAME : self._SetPackageName, DT.TAB_DEC_DEFINES_PACKAGE_GUID : self._SetPackageGuid, DT.TAB_DEC_DEFINES_PACKAGE_VERSION : self._SetPackageVersion, }
class _DecDefine(_DecBase): def __init__(self, RawData): _DecBase.__init__(self, RawData) self.ItemObject = DecDefineObject(RawData.Filename) self._LocalMacro = self._RawData.Macros self._DefSecNum = 0 # # Each field has a function to validate # self.DefineValidation = { DT.TAB_DEC_DEFINES_DEC_SPECIFICATION : self._SetDecSpecification, DT.TAB_DEC_DEFINES_PACKAGE_NAME : self._SetPackageName, DT.TAB_DEC_DEFINES_PACKAGE_GUID : self._SetPackageGuid, DT.TAB_DEC_DEFINES_PACKAGE_VERSION : self._SetPackageVersion, } def BlockStart(self): self._DefSecNum += 1 if self._DefSecNum > 1: self._LoggerError(ST.ERR_DECPARSE_DEFINE_MULTISEC) ## CheckRequiredFields # # Check required fields: DEC_SPECIFICATION, PACKAGE_NAME # PACKAGE_GUID, PACKAGE_VERSION # def CheckRequiredFields(self): Ret = False if self.ItemObject.GetPackageSpecification() == '': Logger.Error(TOOL_NAME, FILE_PARSE_FAILURE, File=self._RawData.Filename, ExtraData=ST.ERR_DECPARSE_DEFINE_REQUIRED % DT.TAB_DEC_DEFINES_DEC_SPECIFICATION) elif self.ItemObject.GetPackageName() == '': Logger.Error(TOOL_NAME, FILE_PARSE_FAILURE, File=self._RawData.Filename, ExtraData=ST.ERR_DECPARSE_DEFINE_REQUIRED % DT.TAB_DEC_DEFINES_PACKAGE_NAME) elif self.ItemObject.GetPackageGuid() == '': Logger.Error(TOOL_NAME, FILE_PARSE_FAILURE, File=self._RawData.Filename, ExtraData=ST.ERR_DECPARSE_DEFINE_REQUIRED % DT.TAB_DEC_DEFINES_PACKAGE_GUID) elif self.ItemObject.GetPackageVersion() == '': Logger.Error(TOOL_NAME, FILE_PARSE_FAILURE, File=self._RawData.Filename, ExtraData=ST.ERR_DECPARSE_DEFINE_REQUIRED % DT.TAB_DEC_DEFINES_PACKAGE_VERSION) else: Ret = True return Ret def _ParseItem(self): Line = self._RawData.CurrentLine TokenList = GetSplitValueList(Line, DT.TAB_EQUAL_SPLIT, 1) if TokenList[0] == DT.TAB_DEC_DEFINES_PKG_UNI_FILE: pass elif len(TokenList) < 2: self._LoggerError(ST.ERR_DECPARSE_DEFINE_FORMAT) elif TokenList[0] not in self.DefineValidation: self._LoggerError(ST.ERR_DECPARSE_DEFINE_UNKNOWKEY % TokenList[0]) else: self.DefineValidation[TokenList[0]](TokenList[1]) DefineItem = DecDefineItemObject() if TokenList[0] != DT.TAB_DEC_DEFINES_PKG_UNI_FILE: DefineItem.Key = TokenList[0] DefineItem.Value = TokenList[1] self.ItemObject.AddItem(DefineItem, self._RawData.CurrentScope) return DefineItem def _SetDecSpecification(self, Token): if self.ItemObject.GetPackageSpecification(): self._LoggerError(ST.ERR_DECPARSE_DEFINE_DEFINED % DT.TAB_DEC_DEFINES_DEC_SPECIFICATION) if not IsValidToken('0[xX][0-9a-fA-F]{8}', Token): self._LoggerError(ST.ERR_DECPARSE_DEFINE_SPEC) self.ItemObject.SetPackageSpecification(Token) def _SetPackageName(self, Token): if self.ItemObject.GetPackageName(): self._LoggerError(ST.ERR_DECPARSE_DEFINE_DEFINED % DT.TAB_DEC_DEFINES_PACKAGE_NAME) if not IsValidWord(Token): self._LoggerError(ST.ERR_DECPARSE_DEFINE_PKGNAME) self.ItemObject.SetPackageName(Token) def _SetPackageGuid(self, Token): if self.ItemObject.GetPackageGuid(): self._LoggerError(ST.ERR_DECPARSE_DEFINE_DEFINED % DT.TAB_DEC_DEFINES_PACKAGE_GUID) if not CheckGuidRegFormat(Token): self._LoggerError(ST.ERR_DECPARSE_DEFINE_PKGGUID) self.ItemObject.SetPackageGuid(Token) def _SetPackageVersion(self, Token): if self.ItemObject.GetPackageVersion(): self._LoggerError(ST.ERR_DECPARSE_DEFINE_DEFINED % DT.TAB_DEC_DEFINES_PACKAGE_VERSION) if not IsValidToken(VERSION_PATTERN, Token): self._LoggerError(ST.ERR_DECPARSE_DEFINE_PKGVERSION) else: if not DT.TAB_SPLIT in Token: Token = Token + '.0' self.ItemObject._PkgVersion = Token