Exemplo n.º 1
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.º 2
0
def InstallPackageContent(FromPath,
                          ToPath,
                          Package,
                          ContentZipFile,
                          Dep,
                          WorkspaceDir,
                          ModuleList,
                          ReadOnly=False):
    if Dep:
        pass
    Package.FileList = []

    if ToPath.startswith("\\") or ToPath.startswith("/"):
        ToPath = ToPath[1:]

    if not IsValidInstallPath(ToPath):
        Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE % ToPath)

    if FromPath.startswith("\\") or FromPath.startswith("/"):
        FromPath = FromPath[1:]

    if not IsValidInstallPath(FromPath):
        Logger.Error("UPT", FORMAT_INVALID,
                     ST.ERR_FILE_NAME_INVALIDE % FromPath)

    PackageFullPath = os.path.normpath(os.path.join(WorkspaceDir, ToPath))
    for MiscFile in Package.GetMiscFileList():
        for Item in MiscFile.GetFileList():
            FileName = Item.GetURI()
            if FileName.startswith("\\") or FileName.startswith("/"):
                FileName = FileName[1:]

            if not IsValidInstallPath(FileName):
                Logger.Error("UPT", FORMAT_INVALID,
                             ST.ERR_FILE_NAME_INVALIDE % FileName)

            FromFile = os.path.join(FromPath, FileName)
            Executable = Item.GetExecutable()
            ToFile = (os.path.join(PackageFullPath, ConvertPath(FileName)))
            Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly,
                                 Executable)
            if (ToFile, Md5Sum) not in Package.FileList:
                Package.FileList.append((ToFile, Md5Sum))
    PackageIncludeArchList = []
    for Item in Package.GetPackageIncludeFileList():
        FileName = Item.GetFilePath()
        if FileName.startswith("\\") or FileName.startswith("/"):
            FileName = FileName[1:]

        if not IsValidInstallPath(FileName):
            Logger.Error("UPT", FORMAT_INVALID,
                         ST.ERR_FILE_NAME_INVALIDE % FileName)

        FromFile = os.path.join(FromPath, FileName)
        ToFile = os.path.normpath(
            os.path.join(PackageFullPath, ConvertPath(FileName)))
        RetFile = ContentZipFile.UnpackFile(FromFile, ToFile)
        if RetFile == '':
            #
            # a non-exist path in Zipfile will return '', which means an include directory in our case
            # save the information for later DEC creation usage and also create the directory
            #
            PackageIncludeArchList.append(
                [Item.GetFilePath(), Item.GetSupArchList()])
            CreateDirectory(ToFile)
            continue
        if ReadOnly:
            chmod(ToFile, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
        else:
            chmod(
                ToFile, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH
                | stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH)
        Md5Sigature = md5.new(__FileHookOpen__(str(ToFile), 'rb').read())
        Md5Sum = Md5Sigature.hexdigest()
        if (ToFile, Md5Sum) not in Package.FileList:
            Package.FileList.append((ToFile, Md5Sum))
    Package.SetIncludeArchList(PackageIncludeArchList)

    for Item in Package.GetStandardIncludeFileList():
        FileName = Item.GetFilePath()
        if FileName.startswith("\\") or FileName.startswith("/"):
            FileName = FileName[1:]

        if not IsValidInstallPath(FileName):
            Logger.Error("UPT", FORMAT_INVALID,
                         ST.ERR_FILE_NAME_INVALIDE % FileName)

        FromFile = os.path.join(FromPath, FileName)
        ToFile = os.path.normpath(
            os.path.join(PackageFullPath, ConvertPath(FileName)))
        Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly)
        if (ToFile, Md5Sum) not in Package.FileList:
            Package.FileList.append((ToFile, Md5Sum))

    #
    # Update package
    #
    Package.SetPackagePath(Package.GetPackagePath().replace(
        FromPath, ToPath, 1))
    Package.SetFullPath(
        os.path.normpath(
            os.path.join(PackageFullPath,
                         ConvertPath(Package.GetName()) + '.dec')))

    #
    # Install files in module
    #
    Module = None
    ModuleDict = Package.GetModuleDict()
    for ModuleGuid, ModuleVersion, ModuleName, ModulePath in ModuleDict:
        Module = ModuleDict[ModuleGuid, ModuleVersion, ModuleName, ModulePath]
        InstallModuleContent(FromPath, ToPath, ModulePath, Module,
                             ContentZipFile, WorkspaceDir, ModuleList, Package,
                             ReadOnly)
Exemplo n.º 3
0
def Main(Options = None):
    ContentZipFile, DistFile = None, None

    try:
        DataBase = GlobalData.gDB        
        CheckEnvVariable()
        WorkspaceDir = GlobalData.gWORKSPACE
        if not Options.PackageFile:
            Logger.Error("InstallPkg", OPTION_MISSING, ExtraData=ST.ERR_SPECIFY_PACKAGE)
        
        #
        # unzip dist.pkg file
        #
        DistPkg, Dep, ContentZipFile, DpPkgFileName = UnZipDp(WorkspaceDir, Options, 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]
        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 + '_' + DistPkg.Header.GetGuid() + '_' + DistPkg.Header.GetVersion() + 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:]

        #
        # update database
        #
        Logger.Quiet(ST.MSG_UPDATE_PACKAGE_DATABASE)
        DataBase.AddDPObject(DistPkg, NewDpPkgFileName, DistFileName, 
                       DistPkg.Header.RePackage)
        
        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())