def Main(Options = None): if Options: pass try: DataBase = GlobalData.gDB InventoryDistInstalled(DataBase) ReturnCode = 0 except FatalError as XExcept: ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) except KeyboardInterrupt: ReturnCode = ABORT_ERROR if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) except: ReturnCode = CODE_ERROR Logger.Error("\nInventoryWs", CODE_ERROR, ST.ERR_UNKNOWN_FATAL_INVENTORYWS_ERR, ExtraData=ST.MSG_SEARCH_FOR_HELP % ST.MSG_EDKII_MAIL_ADDR, RaiseError=False ) Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) if ReturnCode == 0: Logger.Quiet(ST.MSG_FINISH) return ReturnCode
def Main(Options=None): try: DataBase = GlobalData.gDB if not Options.DistributionFile: Logger.Error("RmPkg", OPTION_MISSING, ExtraData=ST.ERR_SPECIFY_PACKAGE) WorkspaceDir = GlobalData.gWORKSPACE # # Prepare check dependency # Dep = DependencyRules(DataBase) # # Get the Dp information # StoredDistFile, Guid, Version = GetInstalledDpInfo( Options.DistributionFile, Dep, DataBase, WorkspaceDir) # # Check Dp depex # CheckDpDepex(Dep, Guid, Version, WorkspaceDir) # # remove distribution # RemoveDist(Guid, Version, StoredDistFile, DataBase, WorkspaceDir, Options.Yes) Logger.Quiet(ST.MSG_FINISH) ReturnCode = 0 except FatalError as XExcept: ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + \ format_exc()) except KeyboardInterrupt: ReturnCode = ABORT_ERROR if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + \ format_exc()) except: Logger.Error("\nRmPkg", CODE_ERROR, ST.ERR_UNKNOWN_FATAL_REMOVING_ERR, ExtraData=ST.MSG_SEARCH_FOR_HELP % ST.MSG_EDKII_MAIL_ADDR, RaiseError=False) Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + \ format_exc()) ReturnCode = CODE_ERROR return ReturnCode
def InstallDp(DistPkg, DpPkgFileName, ContentZipFile, Options, Dep, WorkspaceDir, DataBase): # # PackageList, ModuleList record the information for the meta-data # files that need to be generated later # PackageList = [] ModuleList = [] DistPkg.PackageSurfaceArea = GetPackageList(DistPkg, Dep, WorkspaceDir, Options, ContentZipFile, ModuleList, PackageList) DistPkg.ModuleSurfaceArea = GetModuleList(DistPkg, Dep, WorkspaceDir, ContentZipFile, ModuleList) GenToolMisc(DistPkg, WorkspaceDir, ContentZipFile) # # copy "Distribution File" to directory $(WORKSPACE)/conf/upt # DistFileName = os.path.split(DpPkgFileName)[1] NewDpPkgFileName = BackupDist(DpPkgFileName, DistPkg.Header.GetGuid(), DistPkg.Header.GetVersion(), WorkspaceDir) # # update database # Logger.Quiet(ST.MSG_UPDATE_PACKAGE_DATABASE) DataBase.AddDPObject(DistPkg, NewDpPkgFileName, DistFileName, DistPkg.Header.RePackage)
def UnZipDp(WorkspaceDir, DpPkgFileName, Index=1): ContentZipFile = None Logger.Quiet(ST.MSG_UZIP_PARSE_XML) DistFile = PackageFile(DpPkgFileName) DpDescFileName, ContentFileName = GetDPFile(DistFile.GetZipFile()) TempDir = os.path.normpath( os.path.join(WorkspaceDir, "Conf/.tmp%s" % str(Index))) GlobalData.gUNPACK_DIR.append(TempDir) DistPkgFile = DistFile.UnpackFile( DpDescFileName, os.path.normpath(os.path.join(TempDir, DpDescFileName))) if not DistPkgFile: Logger.Error("InstallPkg", FILE_NOT_FOUND, ST.ERR_FILE_BROKEN % DpDescFileName) # # Generate distpkg # DistPkgObj = DistributionPackageXml() DistPkg = DistPkgObj.FromXml(DistPkgFile) if DistPkg.Header.RePackage == '': DistPkg.Header.RePackage = False if DistPkg.Header.ReadOnly == '': DistPkg.Header.ReadOnly = False # # unzip contents.zip file # ContentFile = DistFile.UnpackFile( ContentFileName, os.path.normpath(os.path.join(TempDir, ContentFileName))) if not ContentFile: Logger.Error("InstallPkg", FILE_NOT_FOUND, ST.ERR_FILE_BROKEN % ContentFileName) # # Get file size # FileSize = os.path.getsize(ContentFile) if FileSize != 0: ContentZipFile = PackageFile(ContentFile) # # verify MD5 signature when existed # if DistPkg.Header.Signature != '': Md5Signature = md5(__FileHookOpen__(ContentFile, 'rb').read()) if DistPkg.Header.Signature != Md5Signature.hexdigest(): ContentZipFile.Close() Logger.Error("InstallPkg", FILE_CHECKSUM_FAILURE, ExtraData=ContentFile) return DistPkg, ContentZipFile, DpPkgFileName, DistFile
def RemoveDist(Guid, Version, StoredDistFile, DataBase, WorkspaceDir, ForceRemove): # # Get Current File List # NewFileList = GetCurrentFileList(DataBase, Guid, Version, WorkspaceDir) # # Remove all files # MissingFileList = [] for (Path, Md5Sum) in DataBase.GetDpFileList(Guid, Version): if os.path.isfile(Path): if Path in NewFileList: NewFileList.remove(Path) if not ForceRemove: # # check whether modified by users # Md5Signature = md5(open(str(Path), 'rb').read()) if Md5Sum != Md5Signature.hexdigest(): Logger.Info(ST.MSG_CONFIRM_REMOVE2 % Path) Input = stdin.readline() Input = Input.replace('\r', '').replace('\n', '') if Input.upper() != 'Y': continue RemovePath(Path) else: MissingFileList.append(Path) for Path in NewFileList: if os.path.isfile(Path): if (not ForceRemove) and ( not os.path.split(Path)[1].startswith('.')): Logger.Info(ST.MSG_CONFIRM_REMOVE3 % Path) Input = stdin.readline() Input = Input.replace('\r', '').replace('\n', '') if Input.upper() != 'Y': continue RemovePath(Path) # # Remove distribution files in /Conf/.upt # if StoredDistFile is not None: os.remove(StoredDistFile) # # update database # Logger.Quiet(ST.MSG_UPDATE_PACKAGE_DATABASE) DataBase.RemoveDpObj(Guid, Version)
def Main(Options=None): try: DataBase = GlobalData.gDB WorkspaceDir = GlobalData.gWORKSPACE if not Options.PackageFile: Logger.Error("InstallPkg", OPTION_MISSING, ExtraData=ST.ERR_SPECIFY_PACKAGE) # Get all Dist Info DistInfoList = [] DistPkgList = [] Index = 1 for ToBeInstalledDist in Options.PackageFile: # # unzip dist.pkg file # DistInfoList.append(UnZipDp(WorkspaceDir, ToBeInstalledDist, Index)) DistPkgList.append(DistInfoList[-1][0]) Index += 1 # # Add dist # GlobalData.gTO_BE_INSTALLED_DIST_LIST.append(DistInfoList[-1][0]) # Check for dependency Dep = DependencyRules(DataBase, DistPkgList) for ToBeInstalledDist in DistInfoList: CheckInstallDpx(Dep, ToBeInstalledDist[0], ToBeInstalledDist[2]) # # Install distribution # InstallDp(ToBeInstalledDist[0], ToBeInstalledDist[2], ToBeInstalledDist[1], Options, Dep, WorkspaceDir, DataBase) ReturnCode = 0 except FatalError as XExcept: ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) except KeyboardInterrupt: ReturnCode = ABORT_ERROR if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) except: ReturnCode = CODE_ERROR Logger.Error("\nInstallPkg", CODE_ERROR, ST.ERR_UNKNOWN_FATAL_INSTALL_ERR % Options.PackageFile, ExtraData=ST.MSG_SEARCH_FOR_HELP % ST.MSG_EDKII_MAIL_ADDR, RaiseError=False) Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) finally: Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_STARTED) for ToBeInstalledDist in DistInfoList: if ToBeInstalledDist[3]: ToBeInstalledDist[3].Close() if ToBeInstalledDist[1]: ToBeInstalledDist[1].Close() for TempDir in GlobalData.gUNPACK_DIR: rmtree(TempDir) GlobalData.gUNPACK_DIR = [] Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_DONE) if ReturnCode == 0: Logger.Quiet(ST.MSG_FINISH) return ReturnCode
def GetModuleList(DistPkg, Dep, WorkspaceDir, ContentZipFile, ModuleList): # # ModulePathList will keep track of the standalone module path that # we just installed. If a new module's path in that list # (only multiple INF in one directory will be so), we will # install them directly. If not, we will try to create a new directory # for it. # ModulePathList = [] # # Check module exist and install # Module = None NewDict = Sdict() for Guid, Version, Name, Path in DistPkg.ModuleSurfaceArea: ModulePath = Path Module = DistPkg.ModuleSurfaceArea[Guid, Version, Name, Path] Logger.Info(ST.MSG_INSTALL_MODULE % Module.GetName()) if Dep.CheckModuleExists(Guid, Version, Name, Path): Logger.Quiet(ST.WRN_MODULE_EXISTED % Path) # # here check for the multiple inf share the same module path cases: # they should be installed into the same directory # ModuleFullPath = \ os.path.normpath(os.path.join(WorkspaceDir, ModulePath)) if ModuleFullPath not in ModulePathList: NewModulePath = InstallNewModule(WorkspaceDir, ModulePath, ModulePathList) NewModuleFullPath = os.path.normpath( os.path.join(WorkspaceDir, NewModulePath)) ModulePathList.append(NewModuleFullPath) else: NewModulePath = ModulePath InstallModuleContent(ModulePath, NewModulePath, '', Module, ContentZipFile, WorkspaceDir, ModuleList, None, DistPkg.Header.ReadOnly) # # Update module # Module.SetModulePath(Module.GetModulePath().replace( Path, NewModulePath, 1)) NewDict[Guid, Version, Name, Module.GetModulePath()] = Module # # generate all inf for modules # for (Module, Package) in ModuleList: CheckCNameInModuleRedefined(Module, DistPkg) FilePath = ModuleToInf(Module, Package, DistPkg.Header) Md5Signature = md5(__FileHookOpen__(str(FilePath), 'rb').read()) Md5Sum = Md5Signature.hexdigest() if Package: if (FilePath, Md5Sum) not in Package.FileList: Package.FileList.append((FilePath, Md5Sum)) else: if (FilePath, Md5Sum) not in Module.FileList: Module.FileList.append((FilePath, Md5Sum)) # # append the module unicode files to Package FileList # for (FilePath, Md5Sum) in Module.FileList: if str(FilePath).endswith('.uni') and Package and ( FilePath, Md5Sum) not in Package.FileList: Package.FileList.append((FilePath, Md5Sum)) return NewDict
def Main(): Logger.Initialize() Parser = OptionParser(version=(MSG_VERSION + ' Build ' + gBUILD_VERSION), description=MSG_DESCRIPTION, prog="UPT.exe", usage=MSG_USAGE) Parser.add_option("-d", "--debug", action="store", type="int", dest="debug_level", help=ST.HLP_PRINT_DEBUG_INFO) Parser.add_option("-v", "--verbose", action="store_true", dest="opt_verbose", help=ST.HLP_PRINT_INFORMATIONAL_STATEMENT) Parser.add_option("-s", "--silent", action="store_true", dest="opt_slient", help=ST.HLP_RETURN_NO_DISPLAY) Parser.add_option("-q", "--quiet", action="store_true", dest="opt_quiet", help=ST.HLP_RETURN_AND_DISPLAY) Parser.add_option("-i", "--install", action="append", type="string", dest="Install_Distribution_Package_File", help=ST.HLP_SPECIFY_PACKAGE_NAME_INSTALL) Parser.add_option("-c", "--create", action="store", type="string", dest="Create_Distribution_Package_File", help=ST.HLP_SPECIFY_PACKAGE_NAME_CREATE) Parser.add_option("-r", "--remove", action="store", type="string", dest="Remove_Distribution_Package_File", help=ST.HLP_SPECIFY_PACKAGE_NAME_REMOVE) Parser.add_option("-t", "--template", action="store", type="string", dest="Package_Information_Data_File", help=ST.HLP_SPECIFY_TEMPLATE_NAME_CREATE) Parser.add_option("-p", "--dec-filename", action="append", type="string", dest="EDK2_DEC_Filename", help=ST.HLP_SPECIFY_DEC_NAME_CREATE) Parser.add_option("-m", "--inf-filename", action="append", type="string", dest="EDK2_INF_Filename", help=ST.HLP_SPECIFY_INF_NAME_CREATE) Parser.add_option("-l", "--list", action="store_true", dest="List_Dist_Installed", help=ST.HLP_LIST_DIST_INSTALLED) Parser.add_option("-f", "--force", action="store_true", dest="Yes", help=ST.HLP_DISABLE_PROMPT) Parser.add_option("-n", "--custom-path", action="store_true", dest="CustomPath", help=ST.HLP_CUSTOM_PATH_PROMPT) Parser.add_option("-x", "--free-lock", action="store_true", dest="SkipLock", help=ST.HLP_SKIP_LOCK_CHECK) Parser.add_option("-u", "--replace", action="store", type="string", dest="Replace_Distribution_Package_File", help=ST.HLP_SPECIFY_PACKAGE_NAME_REPLACE) Parser.add_option("-o", "--original", action="store", type="string", dest="Original_Distribution_Package_File", help=ST.HLP_SPECIFY_PACKAGE_NAME_TO_BE_REPLACED) Parser.add_option("--use-guided-paths", action="store_true", dest="Use_Guided_Paths", help=ST.HLP_USE_GUIDED_PATHS) Parser.add_option("-j", "--test-install", action="append", type="string", dest="Test_Install_Distribution_Package_Files", help=ST.HLP_TEST_INSTALL) Opt = Parser.parse_args()[0] Var2Var = [ ("PackageInformationDataFile", Opt.Package_Information_Data_File), ("PackFileToInstall", Opt.Install_Distribution_Package_File), ("PackFileToCreate", Opt.Create_Distribution_Package_File), ("PackFileToRemove", Opt.Remove_Distribution_Package_File), ("PackageFileList", Opt.EDK2_DEC_Filename), ("ModuleFileList", Opt.EDK2_INF_Filename), ("InventoryWs", Opt.List_Dist_Installed), ("PackFileToReplace", Opt.Replace_Distribution_Package_File), ("PackFileToBeReplaced", Opt.Original_Distribution_Package_File), ("UseGuidedPkgPath", Opt.Use_Guided_Paths), ("TestDistFiles", Opt.Test_Install_Distribution_Package_Files) ] for Var in Var2Var: setattr(Opt, Var[0], Var[1]) try: GlobalData.gWORKSPACE, GlobalData.gPACKAGE_PATH = GetWorkspace() except FatalError as XExcept: if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) return XExcept.args[0] # Support WORKSPACE is a long path # Only works for windows system if pf.system() == 'Windows': Vol = 'B:' for Index in range(90, 65, -1): Vol = chr(Index) + ':' if not os.path.isdir(Vol): os.system('subst %s "%s"' % (Vol, GlobalData.gWORKSPACE)) break GlobalData.gWORKSPACE = '%s\\' % Vol WorkspaceDir = GlobalData.gWORKSPACE SetLogLevel(Opt) Mgr = FileHook.RecoverMgr(WorkspaceDir) FileHook.SetRecoverMgr(Mgr) GlobalData.gDB = IpiDatabase(os.path.normpath(os.path.join(WorkspaceDir, \ "Conf/DistributionPackageDatabase.db")), WorkspaceDir) GlobalData.gDB.InitDatabase(Opt.SkipLock) # # Make sure the Db will get closed correctly # try: ReturnCode = 0 CheckConflictOption(Opt) RunModule = None if Opt.PackFileToCreate: if Opt.PackageInformationDataFile: if not os.path.exists(Opt.PackageInformationDataFile): if not os.path.exists( os.path.join(WorkspaceDir, Opt.PackageInformationDataFile)): Logger.Error( "\nUPT", FILE_NOT_FOUND, ST.ERR_NO_TEMPLATE_FILE % Opt.PackageInformationDataFile) else: Opt.PackageInformationDataFile = os.path.join( WorkspaceDir, Opt.PackageInformationDataFile) else: Logger.Error("UPT", OPTION_MISSING, ExtraData=ST.ERR_REQUIRE_T_OPTION) if not Opt.PackFileToCreate.endswith('.dist'): Logger.Error("CreatePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Opt.PackFileToCreate) RunModule = MkPkg.Main elif Opt.PackFileToInstall: AbsPath = [] for Item in Opt.PackFileToInstall: if not Item.endswith('.dist'): Logger.Error("InstallPkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Item) AbsPath.append(GetFullPathDist(Item, WorkspaceDir)) if not AbsPath: Logger.Error("InstallPkg", FILE_NOT_FOUND, ST.ERR_INSTALL_DIST_NOT_FOUND % Item) Opt.PackFileToInstall = AbsPath setattr(Opt, 'PackageFile', Opt.PackFileToInstall) RunModule = InstallPkg.Main elif Opt.PackFileToRemove: if not Opt.PackFileToRemove.endswith('.dist'): Logger.Error("RemovePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Opt.PackFileToRemove) head, tail = os.path.split(Opt.PackFileToRemove) if head or not tail: Logger.Error("RemovePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_FILENAME_ONLY_FOR_REMOVE % Opt.PackFileToRemove) setattr(Opt, 'DistributionFile', Opt.PackFileToRemove) RunModule = RmPkg.Main elif Opt.InventoryWs: RunModule = InventoryWs.Main elif Opt.PackFileToBeReplaced and not Opt.PackFileToReplace: Logger.Error("ReplacePkg", OPTION_MISSING, ExtraData=ST.ERR_REQUIRE_U_OPTION) elif Opt.PackFileToReplace: if not Opt.PackFileToReplace.endswith('.dist'): Logger.Error("ReplacePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Opt.PackFileToReplace) if not Opt.PackFileToBeReplaced: Logger.Error("ReplacePkg", OPTION_MISSING, ExtraData=ST.ERR_REQUIRE_O_OPTION) if not Opt.PackFileToBeReplaced.endswith('.dist'): Logger.Error("ReplacePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Opt.PackFileToBeReplaced) head, tail = os.path.split(Opt.PackFileToBeReplaced) if head or not tail: Logger.Error( "ReplacePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_FILENAME_ONLY_FOR_REPLACE_ORIG % Opt.PackFileToBeReplaced) AbsPath = GetFullPathDist(Opt.PackFileToReplace, WorkspaceDir) if not AbsPath: Logger.Error( "ReplacePkg", FILE_NOT_FOUND, ST.ERR_REPLACE_DIST_NOT_FOUND % Opt.PackFileToReplace) Opt.PackFileToReplace = AbsPath RunModule = ReplacePkg.Main elif Opt.Test_Install_Distribution_Package_Files: for Dist in Opt.Test_Install_Distribution_Package_Files: if not Dist.endswith('.dist'): Logger.Error("TestInstall", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Dist) setattr(Opt, 'DistFiles', Opt.Test_Install_Distribution_Package_Files) RunModule = TestInstall.Main else: Parser.print_usage() return OPTION_MISSING ReturnCode = RunModule(Opt) except FatalError as XExcept: ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + \ format_exc()) finally: try: if ReturnCode != 0 and ReturnCode != UPT_ALREADY_INSTALLED_ERROR: Logger.Quiet(ST.MSG_RECOVER_START) GlobalData.gDB.RollBack() Mgr.rollback() Logger.Quiet(ST.MSG_RECOVER_DONE) else: GlobalData.gDB.Commit() Mgr.commit() except Exception: Logger.Quiet(ST.MSG_RECOVER_FAIL) GlobalData.gDB.CloseDb() if pf.system() == 'Windows': os.system('subst %s /D' % GlobalData.gWORKSPACE.replace('\\', '')) return ReturnCode
def Main(Options=None): ContentZipFile, DistFile = None, None ReturnCode = 0 try: DataBase = GlobalData.gDB WorkspaceDir = GlobalData.gWORKSPACE if not Options.DistFiles: Logger.Error("TestInstallPkg", TE.OPTION_MISSING, ExtraData=ST.ERR_SPECIFY_PACKAGE) DistPkgList = [] for DistFile in Options.DistFiles: DistPkg, ContentZipFile, __, DistFile = UnZipDp( WorkspaceDir, DistFile) DistPkgList.append(DistPkg) # # check dependency # Dep = DependencyRules(DataBase) Result = True DpObj = None try: Result, DpObj = Dep.CheckTestInstallPdDepexSatisfied(DistPkgList) except: Result = False if Result: Logger.Quiet(ST.MSG_TEST_INSTALL_PASS) else: Logger.Quiet(ST.MSG_TEST_INSTALL_FAIL) except TE.FatalError as XExcept: ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) except Exception as x: ReturnCode = TE.CODE_ERROR Logger.Error("\nTestInstallPkg", TE.CODE_ERROR, ST.ERR_UNKNOWN_FATAL_INSTALL_ERR % Options.DistFiles, ExtraData=ST.MSG_SEARCH_FOR_HELP % ST.MSG_EDKII_MAIL_ADDR, RaiseError=False) Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) finally: Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_STARTED) if DistFile: DistFile.Close() if ContentZipFile: ContentZipFile.Close() for TempDir in GlobalData.gUNPACK_DIR: shutil.rmtree(TempDir) GlobalData.gUNPACK_DIR = [] Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_DONE) if ReturnCode == 0: Logger.Quiet(ST.MSG_FINISH) return ReturnCode
def Main(Options=None): ContentZipFile, DistFile = None, None try: DataBase = GlobalData.gDB WorkspaceDir = GlobalData.gWORKSPACE Dep = DependencyRules(DataBase) DistPkg, ContentZipFile, DpPkgFileName, DistFile = UnZipDp( WorkspaceDir, Options.PackFileToReplace) StoredDistFile, OrigDpGuid, OrigDpVersion = GetInstalledDpInfo(Options.PackFileToBeReplaced, \ Dep, DataBase, WorkspaceDir) # # check dependency # CheckReplaceDpx(Dep, DistPkg, OrigDpGuid, OrigDpVersion) # # Remove the old distribution # RemoveDist(OrigDpGuid, OrigDpVersion, StoredDistFile, DataBase, WorkspaceDir, Options.Yes) # # Install the new distribution # InstallDp(DistPkg, DpPkgFileName, ContentZipFile, Options, Dep, WorkspaceDir, DataBase) ReturnCode = 0 except FatalError as XExcept: ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) except KeyboardInterrupt: ReturnCode = ABORT_ERROR if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) except: ReturnCode = CODE_ERROR Logger.Error("\nReplacePkg", CODE_ERROR, ST.ERR_UNKNOWN_FATAL_REPLACE_ERR % (Options.PackFileToReplace, Options.PackFileToBeReplaced), ExtraData=ST.MSG_SEARCH_FOR_HELP % ST.MSG_EDKII_MAIL_ADDR, RaiseError=False) Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) finally: Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_STARTED) if DistFile: DistFile.Close() if ContentZipFile: ContentZipFile.Close() for TempDir in GlobalData.gUNPACK_DIR: rmtree(TempDir) GlobalData.gUNPACK_DIR = [] Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_DONE) if ReturnCode == 0: Logger.Quiet(ST.MSG_FINISH) return ReturnCode
def Main(Options=None): if Options is None: Logger.Error("\nMkPkg", OPTION_UNKNOWN_ERROR, ST.ERR_OPTION_NOT_FOUND) try: DataBase = GlobalData.gDB ContentFileClosed = True WorkspaceDir = GlobalData.gWORKSPACE # # Init PackFileToCreate # if not Options.PackFileToCreate: Logger.Error("\nMkPkg", OPTION_UNKNOWN_ERROR, ST.ERR_OPTION_NOT_FOUND) # # Handle if the distribution package file already exists # CheckForExistingDp(Options.PackFileToCreate) # # Check package file existing and valid # CheckFileList('.DEC', Options.PackageFileList, ST.ERR_INVALID_PACKAGE_NAME, ST.ERR_INVALID_PACKAGE_PATH) # # Check module file existing and valid # CheckFileList('.INF', Options.ModuleFileList, ST.ERR_INVALID_MODULE_NAME, ST.ERR_INVALID_MODULE_PATH) # # Get list of files that installed with RePackage attribute available # RePkgDict = DataBase.GetRePkgDict() ContentFile = PackageFile(GlobalData.gCONTENT_FILE, "w") ContentFileClosed = False # # Add temp distribution header # if Options.PackageInformationDataFile: XmlFile = IniToXml(Options.PackageInformationDataFile) DistPkg = DistributionPackageXml().FromXml(XmlFile) remove(XmlFile) # # add distribution level tool/misc files # before pack, current dir should be workspace dir, else the full # path will be in the pack file # Cwd = getcwd() chdir(WorkspaceDir) ToolObject = DistPkg.Tools MiscObject = DistPkg.MiscellaneousFiles FileList = [] if ToolObject: FileList += ToolObject.GetFileList() if MiscObject: FileList += MiscObject.GetFileList() for FileObject in FileList: # # If you have unicode file names, please convert them to byte # strings in your desired encoding before passing them to # write(). # FromFile = os.path.normpath( FileObject.GetURI()).encode('utf_8') FileFullPath = mws.join(WorkspaceDir, FromFile) if FileFullPath in RePkgDict: (DpGuid, DpVersion, DpName, Repackage) = RePkgDict[FileFullPath] if not Repackage: Logger.Error("\nMkPkg", UPT_REPKG_ERROR, ST.ERR_UPT_REPKG_ERROR, ExtraData=ST.MSG_REPKG_CONFLICT %\ (FileFullPath, DpGuid, DpVersion, DpName) ) else: DistPkg.Header.RePackage = True ContentFile.PackFile(FromFile) chdir(Cwd) # # Add init dp information # else: DistPkg = DistributionPackageClass() DistPkg.Header.Name = 'Distribution Package' DistPkg.Header.Guid = str(uuid4()) DistPkg.Header.Version = '1.0' DistPkg.GetDistributionPackage(WorkspaceDir, Options.PackageFileList, \ Options.ModuleFileList) FileList, MetaDataFileList = DistPkg.GetDistributionFileList() for File in FileList + MetaDataFileList: FileFullPath = os.path.normpath(os.path.join(WorkspaceDir, File)) # # check whether file was included in a distribution that can not # be repackaged # if FileFullPath in RePkgDict: (DpGuid, DpVersion, DpName, Repackage) = RePkgDict[FileFullPath] if not Repackage: Logger.Error("\nMkPkg", UPT_REPKG_ERROR, ST.ERR_UPT_REPKG_ERROR, ExtraData = \ ST.MSG_REPKG_CONFLICT %(FileFullPath, DpName, \ DpGuid, DpVersion) ) else: DistPkg.Header.RePackage = True Cwd = getcwd() chdir(WorkspaceDir) ContentFile.PackFiles(FileList) chdir(Cwd) Logger.Verbose(ST.MSG_COMPRESS_DISTRIBUTION_PKG) ContentFile.Close() ContentFileClosed = True # # Add Md5Signature # DistPkg.Header.Signature = md5(open(str(ContentFile), 'rb').read()).hexdigest() # # Add current Date # DistPkg.Header.Date = str(strftime("%Y-%m-%dT%H:%M:%S", localtime())) # # Finish final dp file # DistPkgFile = PackageFile(Options.PackFileToCreate, "w") DistPkgFile.PackFile(str(ContentFile)) DistPkgXml = DistributionPackageXml() DistPkgFile.PackData(DistPkgXml.ToXml(DistPkg), GlobalData.gDESC_FILE) DistPkgFile.Close() Logger.Quiet(ST.MSG_FINISH) ReturnCode = 0 except FatalError as XExcept: ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % \ (python_version(), platform) + format_exc()) except KeyboardInterrupt: ReturnCode = ABORT_ERROR if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % \ (python_version(), platform) + format_exc()) except OSError: pass except: Logger.Error( "\nMkPkg", CODE_ERROR, ST.ERR_UNKNOWN_FATAL_CREATING_ERR % \ Options.PackFileToCreate, ExtraData=ST.MSG_SEARCH_FOR_HELP % ST.MSG_EDKII_MAIL_ADDR, RaiseError=False ) Logger.Quiet(ST.MSG_PYTHON_ON % \ (python_version(), platform) + format_exc()) ReturnCode = CODE_ERROR finally: if os.path.exists(GlobalData.gCONTENT_FILE): if not ContentFileClosed: ContentFile.Close() os.remove(GlobalData.gCONTENT_FILE) return ReturnCode