Example #1
0
 def __init__(self):
     self.DistP = DistributionPackageClass()
     self.Pkg = ''
Example #2
0
def Main(Options=None):
    if Options == None:
        Logger.Error("\nMkPkg", OPTION_UNKNOWN_ERROR, ST.ERR_OPTION_NOT_FOUND)
    try:
        DataBase = GlobalData.gDB
        ContentFileClosed = True
        CheckEnvVariable()
        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 = os.path.normpath(
                    os.path.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 Md5Sigature
        #
        DistPkg.Header.Signature = md5.new(
            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, XExcept:
        ReturnCode = XExcept.args[0]
        if Logger.GetLevel() <= Logger.DEBUG_9:
            Logger.Quiet(ST.MSG_PYTHON_ON % \
                         (python_version(), platform) + format_exc())
Example #3
0
    def FromXml(self, Filename=None):
        if Filename is not None:
            self.DistP = DistributionPackageClass()
            #
            # Load to XML
            #
            self.Pkg = XmlParseFile(Filename)

            #
            # Parse Header information
            #
            Tmp = DistributionPackageHeaderXml()
            DistributionPackageHeader = \
            Tmp.FromXml(XmlNode(self.Pkg, '/DistributionPackage/DistributionHeader'), 'DistributionHeader')
            self.DistP.Header = DistributionPackageHeader
            #
            # Parse each PackageSurfaceArea
            #
            for Item in XmlList(self.Pkg,
                                '/DistributionPackage/PackageSurfaceArea'):
                Psa = PackageSurfaceAreaXml()
                Package = Psa.FromXml(Item, 'PackageSurfaceArea')
                self.DistP.PackageSurfaceArea[(Package.GetGuid(), \
                                               Package.GetVersion(), \
                                               Package.GetPackagePath())] = \
                                               Package
            #
            # Parse each ModuleSurfaceArea
            #
            for Item in XmlList(self.Pkg,
                                '/DistributionPackage/ModuleSurfaceArea'):
                Msa = ModuleSurfaceAreaXml()
                Module = Msa.FromXml(Item, 'ModuleSurfaceArea', True)
                ModuleKey = (Module.GetGuid(), Module.GetVersion(),
                             Module.GetName(), Module.GetModulePath())
                self.DistP.ModuleSurfaceArea[ModuleKey] = Module

            #
            # Parse Tools
            #
            Tmp = MiscellaneousFileXml()
            self.DistP.Tools = Tmp.FromXml2(
                XmlNode(self.Pkg, '/DistributionPackage/Tools'), 'Tools')

            #
            # Parse MiscFiles
            #
            Tmp = MiscellaneousFileXml()
            self.DistP.MiscellaneousFiles = \
            Tmp.FromXml2(XmlNode(self.Pkg, \
                                 '/DistributionPackage/MiscellaneousFiles'), \
                                 'MiscellaneousFiles')

            #
            # Parse UserExtensions
            #
            for Item in XmlList(self.Pkg,
                                '/DistributionPackage/UserExtensions'):
                Tmp = UserExtensionsXml()
                self.DistP.UserExtensions.append(
                    Tmp.FromXml2(Item, 'UserExtensions'))

            #
            # Check Required Items for XML
            #
            self.ValidateDistributionPackage()

            return self.DistP