def CheckDpDepexForReplace(self, OrigDpGuid, OrigDpVersion, NewDpPkgList): Replaceable = True DependModuleList = [] WsModuleList = self.WsModuleList # # remove modules that included in current DP # List of item (FilePath) DpModuleList = self.IpiDb.GetDpModuleList(OrigDpGuid, OrigDpVersion) for Module in DpModuleList: if Module in WsModuleList: WsModuleList.remove(Module) else: Logger.Warn("UPT\n", ST.ERR_MODULE_NOT_INSTALLED % Module) OtherPkgList = NewDpPkgList # # get packages in current Dp and find the install path # List of item (PkgGuid, PkgVersion, InstallPath) DpPackageList = self.IpiDb.GetPackageListFromDp( OrigDpGuid, OrigDpVersion) DpPackagePathList = [] WorkSP = GlobalData.gWORKSPACE for (PkgName, PkgGuid, PkgVersion, DecFile) in self.WsPkgList: if PkgName: pass DecPath = dirname(DecFile) if DecPath.find(WorkSP) > -1: InstallPath = GetRelativePath(DecPath, WorkSP) DecFileRelaPath = GetRelativePath(DecFile, WorkSP) else: InstallPath = DecPath DecFileRelaPath = DecFile if (PkgGuid, PkgVersion, InstallPath) in DpPackageList: DpPackagePathList.append(DecFileRelaPath) DpPackageList.remove((PkgGuid, PkgVersion, InstallPath)) else: OtherPkgList.append((PkgGuid, PkgVersion)) # # the left items in DpPackageList are the packages that installed but not found anymore # for (PkgGuid, PkgVersion, InstallPath) in DpPackageList: Logger.Warn( "UPT", ST.WARN_INSTALLED_PACKAGE_NOT_FOUND % (PkgGuid, PkgVersion, InstallPath)) # # check modules to see if it can be satisfied by package not belong to removed DP # for Module in WsModuleList: if (not VerifyReplaceModuleDep(Module, DpPackagePathList, OtherPkgList)): Replaceable = False DependModuleList.append(Module) return (Replaceable, DependModuleList)
def CheckConflictOption(Opt): if (Opt.PackFileToCreate or Opt.PackFileToInstall or Opt.PackFileToRemove or Opt.PackFileToReplace) \ and Opt.InventoryWs: Logger.Error("UPT", OPTION_CONFLICT, ExtraData=ST.ERR_L_OA_EXCLUSIVE) elif Opt.PackFileToReplace and (Opt.PackFileToCreate or Opt.PackFileToInstall or Opt.PackFileToRemove): Logger.Error("UPT", OPTION_CONFLICT, ExtraData=ST.ERR_U_ICR_EXCLUSIVE) elif (Opt.PackFileToCreate and Opt.PackFileToInstall and Opt.PackFileToRemove): Logger.Error("UPT", OPTION_CONFLICT, ExtraData=ST.ERR_REQUIRE_I_C_R_OPTION) elif Opt.PackFileToCreate and Opt.PackFileToInstall: Logger.Error("UPT", OPTION_CONFLICT, ExtraData=ST.ERR_I_C_EXCLUSIVE) elif Opt.PackFileToInstall and Opt.PackFileToRemove: Logger.Error("UPT", OPTION_CONFLICT, ExtraData=ST.ERR_I_R_EXCLUSIVE) elif Opt.PackFileToCreate and Opt.PackFileToRemove: Logger.Error("UPT", OPTION_CONFLICT, ExtraData=ST.ERR_C_R_EXCLUSIVE) elif Opt.TestDistFiles and (Opt.PackFileToCreate or Opt.PackFileToInstall \ or Opt.PackFileToRemove or Opt.PackFileToReplace): Logger.Error("UPT", OPTION_CONFLICT, ExtraData=ST.ERR_C_R_EXCLUSIVE) if Opt.CustomPath and Opt.UseGuidedPkgPath: Logger.Warn("UPT", ST.WARN_CUSTOMPATH_OVERRIDE_USEGUIDEDPATH) Opt.UseGuidedPkgPath = False
def Extract(self, Which, ToDest): Which = os.path.normpath(Which) if Which not in self._Files: Logger.Error("PackagingTool", FILE_NOT_FOUND, ExtraData="[%s] in %s" % (Which, self._FileName)) try: FileContent = self._ZipFile.read(self._Files[Which]) except BaseException as Xstr: Logger.Error("PackagingTool", FILE_DECOMPRESS_FAILURE, ExtraData="[%s] in %s (%s)" % (Which, \ self._FileName, \ str(Xstr))) try: CreateDirectory(os.path.dirname(ToDest)) if os.path.exists(ToDest) and not os.access(ToDest, os.W_OK): Logger.Warn("PackagingTool", \ ST.WRN_FILE_NOT_OVERWRITTEN % ToDest) return else: ToFile = __FileHookOpen__(ToDest, 'wb') except BaseException as Xstr: Logger.Error("PackagingTool", FILE_OPEN_FAILURE, ExtraData="%s (%s)" % (ToDest, str(Xstr))) try: ToFile.write(FileContent) ToFile.close() except BaseException as Xstr: Logger.Error("PackagingTool", FILE_WRITE_FAILURE, ExtraData="%s (%s)" % (ToDest, str(Xstr)))
def CheckDpDepex(Dep, Guid, Version, WorkspaceDir): (Removable, DependModuleList) = Dep.CheckDpDepexForRemove(Guid, Version) if not Removable: Logger.Info(ST.MSG_CONFIRM_REMOVE) Logger.Info(ST.MSG_USER_DELETE_OP) Input = stdin.readline() Input = Input.replace('\r', '').replace('\n', '') if Input.upper() != 'Y': Logger.Error("RmPkg", UNKNOWN_ERROR, ST.ERR_USER_INTERRUPT) return 1 else: # # report list of modules that are not valid due to force # remove, # also generate a log file for reference # Logger.Info(ST.MSG_INVALID_MODULE_INTRODUCED) LogFilePath = os.path.normpath( os.path.join(WorkspaceDir, GlobalData.gINVALID_MODULE_FILE)) Logger.Info(ST.MSG_CHECK_LOG_FILE % LogFilePath) try: LogFile = open(LogFilePath, 'w') try: for ModulePath in DependModuleList: LogFile.write("%s\n" % ModulePath) Logger.Info(ModulePath) except IOError: Logger.Warn("\nRmPkg", ST.ERR_FILE_WRITE_FAILURE, File=LogFilePath) except IOError: Logger.Warn("\nRmPkg", ST.ERR_FILE_OPEN_FAILURE, File=LogFilePath) finally: LogFile.close()
def SetLogLevel(Opt): if Opt.opt_verbose: Logger.SetLevel(Logger.VERBOSE) elif Opt.opt_quiet: Logger.SetLevel(Logger.QUIET + 1) elif Opt.debug_level is not None: if Opt.debug_level < 0 or Opt.debug_level > 9: Logger.Warn("UPT", ST.ERR_DEBUG_LEVEL) Logger.SetLevel(Logger.INFO) else: Logger.SetLevel(Opt.debug_level + 1) elif Opt.opt_slient: Logger.SetLevel(Logger.SILENT) else: Logger.SetLevel(Logger.INFO)
def VerifyRemoveModuleDep(Path, DpPackagePathList): try: for Item in GetPackagePath(Path): if Item in DpPackagePathList: DecPath = os.path.normpath( os.path.join(GlobalData.gWORKSPACE, Item)) Logger.Info(ST.MSG_MODULE_DEPEND_ON % (Path, DecPath)) return False else: return True except FatalError as ErrCode: if ErrCode.message == EDK1_INF_ERROR: Logger.Warn("UPT", ST.WRN_EDK1_INF_FOUND % Path) return True else: return True
def VerifyReplaceModuleDep(Path, DpPackagePathList, OtherPkgList): try: for Item in GetPackagePath(Path): if Item in DpPackagePathList: DecPath = os.path.normpath( os.path.join(GlobalData.gWORKSPACE, Item)) Name, Guid, Version = GetPkgInfoFromDec(DecPath) if (Guid, Version) not in OtherPkgList: Logger.Info(ST.MSG_MODULE_DEPEND_ON % (Path, DecPath)) return False else: return True except FatalError as ErrCode: if ErrCode.message == EDK1_INF_ERROR: Logger.Warn("UPT", ST.WRN_EDK1_INF_FOUND % Path) return True else: return True
def GetInstalledDpInfo(DistributionFile, Dep, DataBase, WorkspaceDir): (Guid, Version, NewDpFileName) = DataBase.GetDpByName(os.path.split(DistributionFile)[1]) if not Guid: Logger.Error("RmPkg", UNKNOWN_ERROR, ST.ERR_PACKAGE_NOT_INSTALLED % DistributionFile) # # Check Dp existing # if not Dep.CheckDpExists(Guid, Version): Logger.Error("RmPkg", UNKNOWN_ERROR, ST.ERR_DISTRIBUTION_NOT_INSTALLED) # # Check for Distribution files existence in /conf/upt, if not exist, # Warn user and go on. # StoredDistFile = os.path.normpath( os.path.join(WorkspaceDir, GlobalData.gUPT_DIR, NewDpFileName)) if not os.path.isfile(StoredDistFile): Logger.Warn("RmPkg", ST.WRN_DIST_NOT_FOUND % StoredDistFile) StoredDistFile = None return StoredDistFile, Guid, Version
def ValidateCopyright(Result, ErrType, FileName, LineNo, ErrMsg): if not Result: Logger.Warn("\nUPT", ErrType, FileName, LineNo, ErrMsg)
def GetDistributionPackage(self, WorkspaceDir, PackageList, ModuleList): # Backup WorkspaceDir Root = WorkspaceDir # # Get Packages # if PackageList: for PackageFile in PackageList: PackageFileFullPath = mws.join(Root, PackageFile) WorkspaceDir = mws.getWs(Root, PackageFile) DecObj = DecPomAlignment(PackageFileFullPath, WorkspaceDir, CheckMulDec=True) PackageObj = DecObj # # Parser inf file one bye one # ModuleInfFileList = PackageObj.GetModuleFileList() for File in ModuleInfFileList: WsRelPath = os.path.join(PackageObj.GetPackagePath(), File) WsRelPath = os.path.normpath(WsRelPath) if ModuleList and WsRelPath in ModuleList: Logger.Error("UPT", OPTION_VALUE_INVALID, ST.ERR_NOT_STANDALONE_MODULE_ERROR%\ (WsRelPath, PackageFile)) Filename = os.path.normpath\ (os.path.join(PackageObj.GetRelaPath(), File)) os.path.splitext(Filename) # # Call INF parser to generate Inf Object. # Actually, this call is not directly call, but wrapped by # Inf class in InfPomAlignment. # try: ModuleObj = InfPomAlignment( Filename, WorkspaceDir, PackageObj.GetPackagePath()) # # Add module to package # ModuleDict = PackageObj.GetModuleDict() ModuleDict[(ModuleObj.GetGuid(), \ ModuleObj.GetVersion(), \ ModuleObj.GetName(), \ ModuleObj.GetCombinePath())] = ModuleObj PackageObj.SetModuleDict(ModuleDict) except FatalError as ErrCode: if ErrCode.message == EDK1_INF_ERROR: Logger.Warn("UPT", ST.WRN_EDK1_INF_FOUND % Filename) else: raise self.PackageSurfaceArea\ [(PackageObj.GetGuid(), PackageObj.GetVersion(), \ PackageObj.GetCombinePath())] = PackageObj # # Get Modules # if ModuleList: for ModuleFile in ModuleList: ModuleFileFullPath = mws.join(Root, ModuleFile) WorkspaceDir = mws.getWs(Root, ModuleFile) try: ModuleObj = InfPomAlignment(ModuleFileFullPath, WorkspaceDir) ModuleKey = (ModuleObj.GetGuid(), ModuleObj.GetVersion(), ModuleObj.GetName(), ModuleObj.GetCombinePath()) self.ModuleSurfaceArea[ModuleKey] = ModuleObj except FatalError as ErrCode: if ErrCode.message == EDK1_INF_ERROR: Logger.Error("UPT", EDK1_INF_ERROR, ST.WRN_EDK1_INF_FOUND % ModuleFileFullPath, ExtraData=ST.ERR_NOT_SUPPORTED_SA_MODULE) else: raise # Recover WorkspaceDir WorkspaceDir = Root
def _ExtractEventHobBootMod(self, FileLinesList): SpecialSectionStart = False CheckLocation = False GFindSpecialCommentRe = \ re.compile(r"""#(?:\s*)\[(.*?)\](?:.*)""", re.DOTALL) GFindNewSectionRe2 = \ re.compile(r"""#?(\s*)\[(.*?)\](.*)""", re.DOTALL) LineNum = 0 Element = [] for Line in FileLinesList: Line = Line.strip() LineNum += 1 MatchObject = GFindSpecialCommentRe.search(Line) if MatchObject: SpecialSectionStart = True Element = [] if MatchObject.group(1).upper().startswith("EVENT"): List = self.EventList elif MatchObject.group(1).upper().startswith("HOB"): List = self.HobList elif MatchObject.group(1).upper().startswith("BOOTMODE"): List = self.BootModeList else: SpecialSectionStart = False CheckLocation = False if SpecialSectionStart: Element.append([Line, LineNum]) List.append(Element) else: # # if currently in special section, try to detect end of current section # MatchObject = GFindNewSectionRe2.search(Line) if SpecialSectionStart: if MatchObject: SpecialSectionStart = False CheckLocation = False Element = [] elif not Line: SpecialSectionStart = False CheckLocation = True Element = [] else: if not Line.startswith(DT.TAB_COMMENT_SPLIT): Logger.Warn("Parser", ST.WARN_SPECIAL_SECTION_LOCATION_WRONG, File=self.FullPath, Line=LineNum) SpecialSectionStart = False CheckLocation = False Element = [] else: Element.append([Line, LineNum]) else: if CheckLocation: if MatchObject: CheckLocation = False elif Line: Logger.Warn("Parser", ST.WARN_SPECIAL_SECTION_LOCATION_WRONG, File=self.FullPath, Line=LineNum) CheckLocation = False if len(self.BootModeList) >= 1: self.InfSpecialCommentParser(self.BootModeList, self.InfSpecialCommentSection, self.FileName, DT.TYPE_BOOTMODE_SECTION) if len(self.EventList) >= 1: self.InfSpecialCommentParser(self.EventList, self.InfSpecialCommentSection, self.FileName, DT.TYPE_EVENT_SECTION) if len(self.HobList) >= 1: self.InfSpecialCommentParser(self.HobList, self.InfSpecialCommentSection, self.FileName, DT.TYPE_HOB_SECTION)