Exemplo n.º 1
0
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)
Exemplo n.º 2
0
    def UnpackFile(self, File, ToFile):
        File = File.replace('\\', '/')
        if File in self._ZipFile.namelist():
            Msg = "%s -> %s" % (File, ToFile)
            Logger.Info(Msg)
            self.Extract(File, ToFile)
            return ToFile

        return ''
Exemplo n.º 3
0
def RemovePath(Path):
    Logger.Info(ST.MSG_REMOVE_FILE % Path)
    if not os.access(Path, os.W_OK):
        os.chmod(Path, S_IWUSR)
    os.remove(Path)
    try:
        os.removedirs(os.path.split(Path)[0])
    except OSError:
        pass
Exemplo n.º 4
0
def GenToolMisc(DistPkg, WorkspaceDir, ContentZipFile):
    ToolObject = DistPkg.Tools
    MiscObject = DistPkg.MiscellaneousFiles
    DistPkg.FileList = []
    FileList = []
    ToolFileNum = 0
    FileNum = 0
    RootDir = WorkspaceDir

    #
    # FileList stores both tools files and misc files
    # Misc file list must be appended to FileList *AFTER* Tools file list
    #
    if ToolObject:
        FileList += ToolObject.GetFileList()
        ToolFileNum = len(ToolObject.GetFileList())
        if 'EDK_TOOLS_PATH' in os.environ:
            RootDir = os.environ['EDK_TOOLS_PATH']
    if MiscObject:
        FileList += MiscObject.GetFileList()
    for FileObject in FileList:
        FileNum += 1
        if FileNum > ToolFileNum:
            #
            # Misc files, root should be changed to WORKSPACE
            #
            RootDir = WorkspaceDir
        File = ConvertPath(FileObject.GetURI())
        ToFile = os.path.normpath(os.path.join(RootDir, File))
        if os.path.exists(ToFile):
            Logger.Info(ST.WRN_FILE_EXISTED % ToFile)
            #
            # ask for user input the new file name
            #
            Logger.Info(ST.MSG_NEW_FILE_NAME)
            Input = stdin.readline()
            Input = Input.replace('\r', '').replace('\n', '')
            OrigPath = os.path.split(ToFile)[0]
            ToFile = os.path.normpath(os.path.join(OrigPath, Input))
        FromFile = os.path.join(FileObject.GetURI())
        Md5Sum = InstallFile(ContentZipFile, FromFile,
                             ToFile, DistPkg.Header.ReadOnly,
                             FileObject.GetExecutable())
        DistPkg.FileList.append((ToFile, Md5Sum))
Exemplo n.º 5
0
def CheckForExistingDp(Path):
    if os.path.exists(Path):
        Logger.Info(ST.MSG_DISTRIBUTION_PACKAGE_FILE_EXISTS % Path)
        Input = stdin.readline()
        Input = Input.replace('\r', '').replace('\n', '')
        if Input.upper() != "Y":
            Logger.Error("\nMkPkg",
                         ABORT_ERROR,
                         ST.ERR_USER_ABORT,
                         RaiseError=True)
Exemplo n.º 6
0
def InstallNewModule(WorkspaceDir, Path, PathList=None):
    if PathList is None:
        PathList = []
    Path = ConvertPath(Path)
    Path = os.path.normpath(Path)
    FullPath = os.path.normpath(os.path.join(WorkspaceDir, Path))
    if os.path.exists(FullPath) and FullPath not in PathList:
        Logger.Info(ST.ERR_DIR_ALREADY_EXIST % Path)
    elif Path == FullPath:
        Logger.Info(ST.MSG_RELATIVE_PATH_ONLY % FullPath)
    else:
        return Path

    Input = stdin.readline()
    Input = Input.replace('\r', '').replace('\n', '')
    if Input == '':
        Logger.Error("InstallPkg", UNKNOWN_ERROR, ST.ERR_USER_INTERRUPT)
    Input = Input.replace('\r', '').replace('\n', '')
    return InstallNewModule(WorkspaceDir, Input, PathList)
Exemplo n.º 7
0
def InstallNewPackage(WorkspaceDir, Path, CustomPath=False):
    if os.path.isabs(Path):
        Logger.Info(ST.MSG_RELATIVE_PATH_ONLY % Path)
    elif CustomPath:
        Logger.Info(ST.MSG_NEW_PKG_PATH)
    else:
        Path = ConvertPath(Path)
        Path = os.path.normpath(Path)
        FullPath = os.path.normpath(os.path.join(WorkspaceDir, Path))
        if os.path.exists(FullPath):
            Logger.Info(ST.ERR_DIR_ALREADY_EXIST % FullPath)
        else:
            return Path

    Input = stdin.readline()
    Input = Input.replace('\r', '').replace('\n', '')
    if Input == '':
        Logger.Error("InstallPkg", UNKNOWN_ERROR, ST.ERR_USER_INTERRUPT)
    Input = Input.replace('\r', '').replace('\n', '')
    return InstallNewPackage(WorkspaceDir, Input, False)
Exemplo n.º 8
0
def InstallNewFile(WorkspaceDir, File):
    FullPath = os.path.normpath(os.path.join(WorkspaceDir, File))
    if os.path.exists(FullPath):
        Logger.Info(ST.ERR_FILE_ALREADY_EXIST % File)
        Input = stdin.readline()
        Input = Input.replace('\r', '').replace('\n', '')
        if Input == '':
            Logger.Error("InstallPkg", UNKNOWN_ERROR, ST.ERR_USER_INTERRUPT)
        Input = Input.replace('\r', '').replace('\n', '')
        return InstallNewFile(WorkspaceDir, Input)
    else:
        return File
Exemplo n.º 9
0
def InventoryDistInstalled(DataBase):
    DistInstalled = DataBase.InventoryDistInstalled()

    #
    # find the max length for each item
    #
    DpNameStr = "DpName"
    DpGuidStr = "DpGuid"
    DpVerStr = "DpVer"
    DpOriginalNameStr = "DpOriginalName"
    MaxGuidlen = len(DpGuidStr)
    MaxVerlen = len(DpVerStr)
    MaxDpAliasFileNameLen = len(DpNameStr)
    MaxDpOrigFileNamelen = len(DpOriginalNameStr)

    for (DpGuid, DpVersion, DpOriginalName, DpAliasFileName) in DistInstalled:
        MaxGuidlen = max(MaxGuidlen, len(DpGuid))
        MaxVerlen = max(MaxVerlen, len(DpVersion))
        MaxDpAliasFileNameLen = max(MaxDpAliasFileNameLen, len(DpAliasFileName))
        MaxDpOrigFileNamelen = max(MaxDpOrigFileNamelen, len(DpOriginalName))

    OutMsgFmt = "%-*s\t%-*s\t%-*s\t%-s"
    OutMsg = OutMsgFmt % (MaxDpAliasFileNameLen,
                          DpNameStr,
                          MaxGuidlen,
                          DpGuidStr,
                          MaxVerlen,
                          DpVerStr,
                          DpOriginalNameStr)
    Logger.Info(OutMsg)

    for (DpGuid, DpVersion, DpFileName, DpAliasFileName) in DistInstalled:
        OutMsg = OutMsgFmt % (MaxDpAliasFileNameLen,
                            DpAliasFileName,
                            MaxGuidlen,
                            DpGuid,
                            MaxVerlen,
                            DpVersion,
                            DpFileName)
        Logger.Info(OutMsg)
Exemplo n.º 10
0
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()
Exemplo n.º 11
0
 def PackFile(self, File, ArcName=None):
     try:
         #
         # avoid packing same file multiple times
         #
         if platform.system() != 'Windows':
             File = File.replace('\\', '/')
         ZipedFilesNameList = self._ZipFile.namelist()
         for ZipedFile in ZipedFilesNameList:
             if File == os.path.normpath(ZipedFile):
                 return
         Logger.Info("packing ..." + File)
         self._ZipFile.write(File, ArcName)
     except BaseException as Xstr:
         Logger.Error("PackagingTool", FILE_COMPRESS_FAILURE,
                         ExtraData="%s (%s)" % (File, str(Xstr)))
Exemplo n.º 12
0
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
Exemplo n.º 13
0
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
Exemplo n.º 14
0
def BackupDist(DpPkgFileName, Guid, Version, WorkspaceDir):
    DistFileName = os.path.split(DpPkgFileName)[1]
    DestDir = os.path.normpath(os.path.join(WorkspaceDir, GlobalData.gUPT_DIR))
    CreateDirectory(DestDir)
    DestFile = os.path.normpath(os.path.join(DestDir, DistFileName))
    if os.path.exists(DestFile):
        FileName, Ext = os.path.splitext(DistFileName)
        NewFileName = FileName + '_' + Guid + '_' + Version + Ext
        DestFile = os.path.normpath(os.path.join(DestDir, NewFileName))
        if os.path.exists(DestFile):
            #
            # ask for user input the new file name
            #
            Logger.Info(ST.MSG_NEW_FILE_NAME_FOR_DIST)
            Input = stdin.readline()
            Input = Input.replace('\r', '').replace('\n', '')
            DestFile = os.path.normpath(os.path.join(DestDir, Input))
    copyfile(DpPkgFileName, DestFile)
    NewDpPkgFileName = DestFile[DestFile.find(DestDir) + len(DestDir) + 1:]
    return NewDpPkgFileName
Exemplo n.º 15
0
def GetPackageList(DistPkg, Dep, WorkspaceDir, Options, ContentZipFile,
                   ModuleList, PackageList):
    NewDict = Sdict()
    for Guid, Version, Path in DistPkg.PackageSurfaceArea:
        PackagePath = Path
        Package = DistPkg.PackageSurfaceArea[Guid, Version, Path]
        Logger.Info(ST.MSG_INSTALL_PACKAGE % Package.GetName())
        #         if Dep.CheckPackageExists(Guid, Version):
        #             Logger.Info(ST.WRN_PACKAGE_EXISTED %(Guid, Version))
        if Options.UseGuidedPkgPath:
            GuidedPkgPath = "%s_%s_%s" % (Package.GetName(), Guid, Version)
            NewPackagePath = InstallNewPackage(WorkspaceDir, GuidedPkgPath,
                                               Options.CustomPath)
        else:
            NewPackagePath = InstallNewPackage(WorkspaceDir, PackagePath,
                                               Options.CustomPath)
        InstallPackageContent(PackagePath, NewPackagePath, Package,
                              ContentZipFile, Dep, WorkspaceDir, ModuleList,
                              DistPkg.Header.ReadOnly)
        PackageList.append(Package)

        NewDict[Guid, Version, Package.GetPackagePath()] = Package

    #
    # Now generate meta-data files, first generate all dec for package
    # dec should be generated before inf, and inf should be generated after
    # all packages installed, else hard to resolve modules' package
    # dependency (Hard to get the location of the newly installed package)
    #
    for Package in PackageList:
        FilePath = PackageToDec(Package, DistPkg.Header)
        Md5Signature = md5(__FileHookOpen__(str(FilePath), 'rb').read())
        Md5Sum = Md5Signature.hexdigest()
        if (FilePath, Md5Sum) not in Package.FileList:
            Package.FileList.append((FilePath, Md5Sum))

    return NewDict
Exemplo n.º 16
0
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
Exemplo n.º 17
0
 def Unpack(self, ToDest):
     for FileN in self._ZipFile.namelist():
         ToFile = os.path.normpath(os.path.join(ToDest, FileN))
         Msg = "%s -> %s" % (FileN, ToFile)
         Logger.Info(Msg)
         self.Extract(FileN, ToFile)