MkPkg.py revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster## @file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# Install distribution package.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#
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#
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#
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster'''
8af80418ba1ec431c8027fa9668e5678658d3611Allan FosterMkPkg
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster'''
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster##
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# Import Modules
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom os import remove
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom os import getcwd
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom os import chdir
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport os.path
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom sys import stdin
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom sys import platform
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom traceback import format_exc
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom platform import python_version
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport md5
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom time import strftime
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom time import localtime
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom uuid import uuid4
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom Logger import StringTable as ST
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom Logger.ToolError import OPTION_UNKNOWN_ERROR
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom Logger.ToolError import OPTION_VALUE_INVALID
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom Logger.ToolError import ABORT_ERROR
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom Logger.ToolError import UPT_REPKG_ERROR
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom Logger.ToolError import CODE_ERROR
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom Logger.ToolError import FatalError
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom Logger.ToolError import FILE_NOT_FOUND
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport Logger.Log as Logger
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom Xml.XmlParser import DistributionPackageXml
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom Xml.IniToXml import IniToXml
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom Library.Misc import CheckEnvVariable
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom Library import GlobalData
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom Library.ParserValidate import IsValidPath
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom Core.DistributionPackageClass import DistributionPackageClass
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfrom Core.PackageFile import PackageFile
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster## CheckForExistingDp
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# Check if there is a same name DP file existing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# @param Path: The path to be checked
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterdef CheckForExistingDp(Path):
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if os.path.exists(Path):
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Info(ST.MSG_DISTRIBUTION_PACKAGE_FILE_EXISTS % Path)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Input = stdin.readline()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Input = Input.replace('\r', '').replace('\n', '')
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if Input.upper() != "Y":
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Error("\nMkPkg", ABORT_ERROR, ST.ERR_USER_ABORT, RaiseError=True)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster## Tool entrance method
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#
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#
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterdef Main(Options = None):
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if Options == None:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Error("\nMkPkg", OPTION_UNKNOWN_ERROR, ST.ERR_OPTION_NOT_FOUND)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DataBase = GlobalData.gDB
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ContentFileClosed = True
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster CheckEnvVariable()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster WorkspaceDir = GlobalData.gWORKSPACE
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Init PackFileToCreate
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if not Options.PackFileToCreate:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Error("\nMkPkg", OPTION_UNKNOWN_ERROR, ST.ERR_OPTION_NOT_FOUND)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Handle if the distribution package file already exists
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster CheckForExistingDp(Options.PackFileToCreate)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Check package file existing and valid
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster CheckFileList('.DEC', Options.PackageFileList, ST.ERR_INVALID_PACKAGE_NAME, ST.ERR_INVALID_PACKAGE_PATH)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Check module file existing and valid
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster CheckFileList('.INF', Options.ModuleFileList, ST.ERR_INVALID_MODULE_NAME, ST.ERR_INVALID_MODULE_PATH)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Get list of files that installed with RePackage attribute available
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster RePkgDict = DataBase.GetRePkgDict()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ContentFile = PackageFile(GlobalData.gCONTENT_FILE, "w")
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ContentFileClosed = False
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Add temp distribution header
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if Options.PackageInformationDataFile:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster XmlFile = IniToXml(Options.PackageInformationDataFile)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkg = DistributionPackageXml().FromXml(XmlFile)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster remove(XmlFile)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
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 #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Cwd = getcwd()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster chdir(WorkspaceDir)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ToolObject = DistPkg.Tools
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster MiscObject = DistPkg.MiscellaneousFiles
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster FileList = []
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ToolObject:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster FileList += ToolObject.GetFileList()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if MiscObject:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster FileList += MiscObject.GetFileList()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for FileObject in FileList:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
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 # write().
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster FromFile = os.path.normpath(FileObject.GetURI()).encode('utf_8')
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster FileFullPath = os.path.normpath(os.path.join(WorkspaceDir, FromFile))
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if FileFullPath in RePkgDict:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (DpGuid, DpVersion, DpName, Repackage) = RePkgDict[FileFullPath]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if not Repackage:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Error("\nMkPkg",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster UPT_REPKG_ERROR,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ST.ERR_UPT_REPKG_ERROR,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ExtraData=ST.MSG_REPKG_CONFLICT %\
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (FileFullPath, DpGuid, DpVersion, DpName)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster )
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster else:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkg.Header.RePackage = True
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ContentFile.PackFile(FromFile)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster chdir(Cwd)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Add init dp information
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster else:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkg = DistributionPackageClass()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkg.Header.Name = 'Distribution Package'
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkg.Header.Guid = str(uuid4())
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkg.Header.Version = '1.0'
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkg.GetDistributionPackage(WorkspaceDir, Options.PackageFileList, \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Options.ModuleFileList)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster FileList, MetaDataFileList = DistPkg.GetDistributionFileList()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for File in FileList + MetaDataFileList:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster FileFullPath = os.path.normpath(os.path.join(WorkspaceDir, File))
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # check whether file was included in a distribution that can not
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # be repackaged
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if FileFullPath in RePkgDict:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (DpGuid, DpVersion, DpName, Repackage) = RePkgDict[FileFullPath]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if not Repackage:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Error("\nMkPkg",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster UPT_REPKG_ERROR,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ST.ERR_UPT_REPKG_ERROR,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ExtraData = \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ST.MSG_REPKG_CONFLICT %(FileFullPath, DpName, \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DpGuid, DpVersion)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster )
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster else:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkg.Header.RePackage = True
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Cwd = getcwd()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster chdir(WorkspaceDir)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ContentFile.PackFiles(FileList)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster chdir(Cwd)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Verbose(ST.MSG_COMPRESS_DISTRIBUTION_PKG)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ContentFile.Close()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ContentFileClosed = True
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Add Md5Sigature
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkg.Header.Signature = md5.new(open(str(ContentFile), 'rb').read()).hexdigest()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Add current Date
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkg.Header.Date = str(strftime("%Y-%m-%dT%H:%M:%S", localtime()))
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Finish final dp file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkgFile = PackageFile(Options.PackFileToCreate, "w")
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkgFile.PackFile(str(ContentFile))
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkgXml = DistributionPackageXml()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkgFile.PackData(DistPkgXml.ToXml(DistPkg), GlobalData.gDESC_FILE)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DistPkgFile.Close()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Quiet(ST.MSG_FINISH)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ReturnCode = 0
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster except FatalError, XExcept:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ReturnCode = XExcept.args[0]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if Logger.GetLevel() <= Logger.DEBUG_9:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Quiet(ST.MSG_PYTHON_ON % \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (python_version(), platform) + format_exc())
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster except KeyboardInterrupt:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ReturnCode = ABORT_ERROR
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if Logger.GetLevel() <= Logger.DEBUG_9:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Quiet(ST.MSG_PYTHON_ON % \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (python_version(), platform) + format_exc())
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster except OSError:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster pass
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster except:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Error(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "\nMkPkg",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster CODE_ERROR,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ST.ERR_UNKNOWN_FATAL_CREATING_ERR % \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Options.PackFileToCreate,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ExtraData=ST.MSG_SEARCH_FOR_HELP,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster RaiseError=False
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster )
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Quiet(ST.MSG_PYTHON_ON % \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (python_version(), platform) + format_exc())
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ReturnCode = CODE_ERROR
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster finally:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if os.path.exists(GlobalData.gCONTENT_FILE):
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if not ContentFileClosed:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ContentFile.Close()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster os.remove(GlobalData.gCONTENT_FILE)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return ReturnCode
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster## CheckFileList
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# @param QualifiedExt: QualifiedExt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# @param FileList: FileList
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# @param ErrorStringExt: ErrorStringExt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# @param ErrorStringFullPath: ErrorStringFullPath
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterdef CheckFileList(QualifiedExt, FileList, ErrorStringExt, ErrorStringFullPath):
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if not FileList:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster WorkspaceDir = GlobalData.gWORKSPACE
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster WorkspaceDir = os.path.normpath(WorkspaceDir)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for Item in FileList:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Ext = os.path.splitext(Item)[1]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if Ext.upper() != QualifiedExt.upper():
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Error("\nMkPkg", OPTION_VALUE_INVALID, \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ErrorStringExt % Item)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Item = os.path.normpath(Item)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Path = os.path.normpath(os.path.join(WorkspaceDir, Item))
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if not os.path.exists(Path):
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Error("\nMkPkg", FILE_NOT_FOUND, ST.ERR_NOT_FOUND % Item)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster elif Item == Path:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Error("\nMkPkg", OPTION_VALUE_INVALID,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ErrorStringFullPath % Item)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster elif not IsValidPath(Item, WorkspaceDir):
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Error("\nMkPkg", OPTION_VALUE_INVALID, \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ErrorStringExt % Item)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if not os.path.split(Item)[0]:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger.Error("\nMkPkg", OPTION_VALUE_INVALID, \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ST.ERR_INVALID_METAFILE_PATH % Item)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster