## @file
# Install distribution package.
#
# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
# distribution. The full text of the license may be found at
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
"""
Install a distribution package
"""
##
# Import Modules
#
import stat
import md5
## InstallNewPackage
#
# @param WorkspaceDir: Workspace Directory
# @param Path: Package Path
# @param CustomPath: whether need to customize path at first
#
elif CustomPath:
else:
else:
return Path
if Input == '':
## InstallNewModule
#
# @param WorkspaceDir: Workspace Directory
# @param Path: Standalone Module Path
# @param PathList: The already installed standalone module Path list
#
if PathList == None:
PathList = []
else:
return Path
if Input == '':
## InstallNewFile
#
# @param WorkspaceDir: Workspace Direction
# @param File: File
#
if Input == '':
else:
return File
## UnZipDp
#
# UnZipDp
#
ContentZipFile = None
if not DistPkgFile:
#
# Generate distpkg
#
#
# prepare check dependency
#
#
# Check distribution package installed or not
#
#
# Check distribution dependency (all module dependency should be
# satisfied)
#
#
# unzip contents.zip file
#
if not ContentFile:
#
# Assume no archive comment.
#
#
# Get file size
#
if FileSize != 0:
#
# verify MD5 signature when existed
#
## GetPackageList
#
# GetPackageList
#
InstallPackageContent(PackagePath, NewPackagePath, Package, ContentZipFile, Dep, WorkspaceDir, ModuleList,
#
# 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:
return NewDict
## GetModuleList
#
# GetModuleList
#
#
# 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
#
# here check for the multiple inf share the same module path cases:
# they should be installed into the same directory
#
ModuleFullPath = \
if ModuleFullPath not in ModulePathList:
else:
InstallModuleContent(ModulePath, NewModulePath, '', Module, ContentZipFile, WorkspaceDir, ModuleList, None,
#
# Update module
#
#
# generate all inf for modules
#
if Package:
else:
return NewDict
## GenToolMisc
#
# GenToolMisc
#
#
FileList = []
ToolFileNum = 0
FileNum = 0
#
# FileList stores both tools files and misc files
# Misc file list must be appended to FileList *AFTER* Tools file list
#
if ToolObject:
if MiscObject:
for FileObject in FileList:
FileNum += 1
if FileNum > ToolFileNum:
#
# Misc files, root should be changed to WORKSPACE
#
#
# ask for user input the new file name
#
Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, DistPkg.Header.ReadOnly, FileObject.GetExecutable())
## Tool entrance method
#
# This method mainly dispatch specific methods per the command line options.
# If no error found, return zero value so the caller of this tool can know
# if it's executed successfully or not.
#
# @param Options: command Options
#
ContentZipFile, DistFile = None, None
try:
if not Options.PackageFile:
#
# unzip dist.pkg file
#
#
# PackageList, ModuleList record the information for the meta-data
# files that need to be generated later
#
PackageList = []
ModuleList = []
#
#
#
# ask for user input the new file name
#
#
# update database
#
ReturnCode = 0
except FatalError, XExcept:
platform) + format_exc())
except KeyboardInterrupt:
platform) + format_exc())
except:
"\nInstallPkg",
)
platform) + format_exc())
finally:
if DistFile:
if ContentZipFile:
GlobalData.gUNPACK_DIR = None
if ReturnCode == 0:
return ReturnCode
## InstallModuleContent method
#
# If this is standalone module, then Package should be none,
# ModulePath should be ''
# @param FromPath: FromPath
# @param NewPath: NewPath
# @param ModulePath: ModulePath
# @param Module: Module
# @param ContentZipFile: ContentZipFile
# @param WorkspaceDir: WorkspaceDir
# @param ModuleList: ModuleList
# @param Package: Package
#
if not IsValidInstallPath(NewPath):
if not MiscFile:
continue
if not IsValidInstallPath(File):
elif Package:
continue
if not IsValidInstallPath(File):
elif Package:
continue
for FileName in FileNameList:
if not IsValidInstallPath(File):
elif Package:
continue
InstallModuleContentZipFile(ContentZipFile, FromPath, ModulePath, WorkspaceDir, NewPath, Module, Package, ReadOnly,
## InstallModuleContentZipFile
#
# InstallModuleContentZipFile
#
def InstallModuleContentZipFile(ContentZipFile, FromPath, ModulePath, WorkspaceDir, NewPath, Module, Package, ReadOnly,
#
# Extract other files under current module path in content Zip file but not listed in the description
#
if ContentZipFile:
if not IsValidInstallPath(FileName):
if Package:
break
else:
elif Package:
continue
## FileUnderPath
# Check whether FileName started with directory specified by CheckPath
#
# @param FileName: the FileName need to be checked
# @param CheckPath: the path need to be checked against
# @return: True or False
#
return True
return False
## InstallFile
# Extract File from Zipfile, set file attribute, and return the Md5Sum
#
# @return: True or False
#
if ReadOnly:
if not Executable:
else:
elif Executable:
else:
return Md5Sum
## InstallPackageContent method
#
# @param FromPath: FromPath
# @param ToPath: ToPath
# @param Package: Package
# @param ContentZipFile: ContentZipFile
# @param Dep: Dep
# @param WorkspaceDir: WorkspaceDir
# @param ModuleList: ModuleList
#
if Dep:
pass
if not IsValidInstallPath(ToPath):
if not IsValidInstallPath(FromPath):
if not IsValidInstallPath(FileName):
if not IsValidInstallPath(FileName):
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
#
continue
if ReadOnly:
else:
if not IsValidInstallPath(FileName):
#
# Update package
#
ToPath, 1))
#
# Install files in module
#
Module = None
## GetDPFile method
#
# @param ZipFile: A ZipFile
#
ContentFile = ''
DescFile = ''
if not ContentFile:
continue
if not DescFile:
continue
else:
continue
if not DescFile or not ContentFile:
return DescFile, ContentFile