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, XExcept: ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())
def Main(Options=None): ContentZipFile, DistFile = None, None try: DataBase = GlobalData.gDB WorkspaceDir = GlobalData.gWORKSPACE if not Options.PackageFile: Logger.Error("InstallPkg", OPTION_MISSING, ExtraData=ST.ERR_SPECIFY_PACKAGE) # # unzip dist.pkg file # DistPkg, ContentZipFile, DpPkgFileName, DistFile = UnZipDp( WorkspaceDir, Options.PackageFile) # # check dependency # Dep = DependencyRules(DataBase) CheckInstallDpx(Dep, DistPkg) # # Install distribution # InstallDp(DistPkg, DpPkgFileName, ContentZipFile, Options, Dep, WorkspaceDir, DataBase) ReturnCode = 0 except FatalError, XExcept: ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())
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, XExcept: ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())
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, RaiseError=False ) Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + \ format_exc()) ReturnCode = CODE_ERROR return ReturnCode
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, XExcept: ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())
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, XExcept: ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + \ format_exc())
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, 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): try: DataBase = GlobalData.gDB if not Options.DistributionFile: Logger.Error("RmPkg", OPTION_MISSING, ExtraData=ST.ERR_SPECIFY_PACKAGE) CheckEnvVariable() WorkspaceDir = GlobalData.gWORKSPACE # # Prepare check dependency # Dep = DependencyRules(DataBase) if Options.DistributionFile: (Guid, Version, NewDpFileName) = \ DataBase.GetDpByName(os.path.split(Options.DistributionFile)[1]) if not Guid: Logger.Error("RmPkg", UNKNOWN_ERROR, ST.ERR_PACKAGE_NOT_INSTALLED % Options.DistributionFile) else: Guid = Options.PackageGuid Version = Options.PackageVersion # # 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 # # Check Dp depex # CheckDpDepex(Dep, Guid, Version, WorkspaceDir) # # 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 Options.Yes: # # check whether modified by users # Md5Sigature = md5.new(open(str(Path), 'rb').read()) if Md5Sum != Md5Sigature.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 Options.Yes) 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) Logger.Quiet(ST.MSG_FINISH) ReturnCode = 0 except FatalError, XExcept: ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + \ format_exc())
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, 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 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, 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 UnZipDp(WorkspaceDir, Options, DataBase): ContentZipFile = None Logger.Quiet(ST.MSG_UZIP_PARSE_XML) DpPkgFileName = Options.PackageFile DistFile = PackageFile(DpPkgFileName) DpDescFileName, ContentFileName = GetDPFile(DistFile.GetZipFile()) GlobalData.gUNPACK_DIR = os.path.normpath(os.path.join(WorkspaceDir, ".tmp")) DistPkgFile = DistFile.UnpackFile(DpDescFileName, os.path.normpath(os.path.join(GlobalData.gUNPACK_DIR, 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 # # prepare check dependency # Dep = DependencyRules(DataBase) # # Check distribution package installed or not # if Dep.CheckDpExists(DistPkg.Header.GetGuid(), DistPkg.Header.GetVersion()): Logger.Error("InstallPkg", UPT_ALREADY_INSTALLED_ERROR, ST.WRN_DIST_PKG_INSTALLED) # # Check distribution dependency (all module dependency should be # satisfied) # if not Dep.CheckDpDepexSatisfied(DistPkg): Logger.Error("InstallPkg", UNKNOWN_ERROR, ST.ERR_PACKAGE_NOT_MATCH_DEPENDENCY, ExtraData=DistPkg.Header.Name) # # unzip contents.zip file # ContentFile = DistFile.UnpackFile(ContentFileName, os.path.normpath(os.path.join(GlobalData.gUNPACK_DIR, ContentFileName))) if not ContentFile: Logger.Error("InstallPkg", FILE_NOT_FOUND, ST.ERR_FILE_BROKEN % ContentFileName) FilePointer = open(ContentFile, "rb") # # Assume no archive comment. # FilePointer.seek(0, SEEK_SET) FilePointer.seek(0, SEEK_END) # # Get file size # FileSize = FilePointer.tell() FilePointer.close() if FileSize != 0: ContentZipFile = PackageFile(ContentFile) # # verify MD5 signature when existed # if DistPkg.Header.Signature != '': Md5Sigature = md5.new(open(ContentFile, 'rb').read()) if DistPkg.Header.Signature != Md5Sigature.hexdigest(): ContentZipFile.Close() Logger.Error("InstallPkg", FILE_CHECKSUM_FAILURE, ExtraData=ContentFile) return DistPkg, Dep, ContentZipFile, DpPkgFileName