MkPkg.py revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# Install distribution package.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# This program and the accompanying materials are licensed and made available
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# under the terms and conditions of the BSD License which accompanies this
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# distribution. The full text of the license may be found at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# http://opensource.org/licenses/bsd-license.php
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# Import Modules
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom Logger.ToolError import OPTION_UNKNOWN_ERROR
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom Logger.ToolError import OPTION_VALUE_INVALID
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom Xml.XmlParser import DistributionPackageXml
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom Core.DistributionPackageClass import DistributionPackageClass
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster## CheckForExistingDp
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# Check if there is a same name DP file existing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# @param Path: The path to be checked
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Info(ST.MSG_DISTRIBUTION_PACKAGE_FILE_EXISTS % Path)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Input = Input.replace('\r', '').replace('\n', '')
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Error("\nMkPkg", ABORT_ERROR, ST.ERR_USER_ABORT, RaiseError=True)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster## Tool entrance method
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# This method mainly dispatch specific methods per the command line options.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# If no error found, return zero value so the caller of this tool can know
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# if it's executed successfully or not.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Error("\nMkPkg", OPTION_UNKNOWN_ERROR, ST.ERR_OPTION_NOT_FOUND)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Init PackFileToCreate
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Error("\nMkPkg", OPTION_UNKNOWN_ERROR, ST.ERR_OPTION_NOT_FOUND)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Handle if the distribution package file already exists
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Check package file existing and valid
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster CheckFileList('.DEC', Options.PackageFileList, ST.ERR_INVALID_PACKAGE_NAME, ST.ERR_INVALID_PACKAGE_PATH)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Check module file existing and valid
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster CheckFileList('.INF', Options.ModuleFileList, ST.ERR_INVALID_MODULE_NAME, ST.ERR_INVALID_MODULE_PATH)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Get list of files that installed with RePackage attribute available
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ContentFile = PackageFile(GlobalData.gCONTENT_FILE, "w")
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Add temp distribution header
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster XmlFile = IniToXml(Options.PackageInformationDataFile)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkg = DistributionPackageXml().FromXml(XmlFile)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # add distribution level tool/misc files
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # before pack, current dir should be workspace dir, else the full
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # path will be in the pack file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # If you have unicode file names, please convert them to byte
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # strings in your desired encoding before passing them to
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster FromFile = os.path.normpath(FileObject.GetURI()).encode('utf_8')
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster FileFullPath = os.path.normpath(os.path.join(WorkspaceDir, FromFile))
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (DpGuid, DpVersion, DpName, Repackage) = RePkgDict[FileFullPath]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Add init dp information
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkg.GetDistributionPackage(WorkspaceDir, Options.PackageFileList, \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster FileList, MetaDataFileList = DistPkg.GetDistributionFileList()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster FileFullPath = os.path.normpath(os.path.join(WorkspaceDir, File))
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # check whether file was included in a distribution that can not
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # be repackaged
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (DpGuid, DpVersion, DpName, Repackage) = RePkgDict[FileFullPath]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ST.MSG_REPKG_CONFLICT %(FileFullPath, DpName, \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Verbose(ST.MSG_COMPRESS_DISTRIBUTION_PKG)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Add Md5Sigature
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkg.Header.Signature = md5.new(open(str(ContentFile), 'rb').read()).hexdigest()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Add current Date
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkg.Header.Date = str(strftime("%Y-%m-%dT%H:%M:%S", localtime()))
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Finish final dp file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkgFile = PackageFile(Options.PackFileToCreate, "w")
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkgFile.PackData(DistPkgXml.ToXml(DistPkg), GlobalData.gDESC_FILE)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster## CheckFileList
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# @param QualifiedExt: QualifiedExt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# @param FileList: FileList
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# @param ErrorStringExt: ErrorStringExt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# @param ErrorStringFullPath: ErrorStringFullPath
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterdef CheckFileList(QualifiedExt, FileList, ErrorStringExt, ErrorStringFullPath):
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Error("\nMkPkg", OPTION_VALUE_INVALID, \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Path = os.path.normpath(os.path.join(WorkspaceDir, Item))
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Error("\nMkPkg", FILE_NOT_FOUND, ST.ERR_NOT_FOUND % Item)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Error("\nMkPkg", OPTION_VALUE_INVALID, \