summaryrefslogtreecommitdiff
path: root/BaseTools/Source/Python/UPT/Core
diff options
context:
space:
mode:
Diffstat (limited to 'BaseTools/Source/Python/UPT/Core')
-rw-r--r--BaseTools/Source/Python/UPT/Core/DependencyRules.py267
-rw-r--r--BaseTools/Source/Python/UPT/Core/DistributionPackageClass.py49
-rw-r--r--BaseTools/Source/Python/UPT/Core/FileHook.py199
-rw-r--r--BaseTools/Source/Python/UPT/Core/IpiDb.py59
-rw-r--r--BaseTools/Source/Python/UPT/Core/PackageFile.py11
5 files changed, 490 insertions, 95 deletions
diff --git a/BaseTools/Source/Python/UPT/Core/DependencyRules.py b/BaseTools/Source/Python/UPT/Core/DependencyRules.py
index 752d8e8f41..4608ed6030 100644
--- a/BaseTools/Source/Python/UPT/Core/DependencyRules.py
+++ b/BaseTools/Source/Python/UPT/Core/DependencyRules.py
@@ -1,7 +1,7 @@
## @file
# This file is for installed package information database operations
#
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2014, 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
@@ -20,14 +20,14 @@ Dependency
##
# Import Modules
#
-from os import getenv
-from os import environ
from os.path import dirname
import Logger.Log as Logger
from Logger import StringTable as ST
from Library.Parsing import GetWorkspacePackage
from Library.Parsing import GetWorkspaceModule
+from Library.Misc import GetRelativePath
+from Library import GlobalData
from PomAdapter.InfPomAlignment import InfPomAlignment
from Logger.ToolError import FatalError
from Logger.ToolError import EDK1_INF_ERROR
@@ -36,11 +36,9 @@ from Logger.ToolError import UNKNOWN_ERROR
DEPEX_CHECK_PACKAGE_NOT_FOUND, DEPEX_CHECK_DP_NOT_FOUND) = (0, 1, 2, 3)
-## IpiDb
+## DependencyRules
#
-# This class represents the installed package information database
-# Add/Remove/Get installed distribution package information here.
-#
+# This class represents the dependency rule check mechanism
#
# @param object: Inherited from object class
#
@@ -49,15 +47,17 @@ class DependencyRules(object):
self.IpiDb = Datab
self.WsPkgList = GetWorkspacePackage()
self.WsModuleList = GetWorkspaceModule()
-
- ## Check whether a module exists in current workspace.
+ self.PkgsToBeDepend = []
+
+ ## Check whether a module exists by checking the Guid+Version+Name+Path combination
#
# @param Guid: Guid of a module
# @param Version: Version of a module
+ # @param Name: Name of a module
+ # @param Path: Path of a module
+ # @return: True if module existed, else False
#
- def CheckModuleExists(self, Guid, Version, Name, Path, ReturnCode=DEPEX_CHECK_SUCCESS):
- if ReturnCode:
- pass
+ def CheckModuleExists(self, Guid, Version, Name, Path):
Logger.Verbose(ST.MSG_CHECK_MODULE_EXIST)
ModuleList = self.IpiDb.GetModInPackage(Guid, Version, Name, Path)
ModuleList.extend(self.IpiDb.GetStandaloneModule(Guid, Version, Name, Path))
@@ -67,15 +67,14 @@ class DependencyRules(object):
else:
return False
- ## Check whether a module depex satisfied by current workspace or dist.
+ ## Check whether a module depex satisfied.
#
# @param ModuleObj: A module object
- # @param DpObj: A depex object
+ # @param DpObj: A distribution object
+ # @return: True if module depex satisfied
+ # False else
#
- def CheckModuleDepexSatisfied(self, ModuleObj, DpObj=None, \
- ReturnCode=DEPEX_CHECK_SUCCESS):
- if ReturnCode:
- pass
+ def CheckModuleDepexSatisfied(self, ModuleObj, DpObj=None):
Logger.Verbose(ST.MSG_CHECK_MODULE_DEPEX_START)
Result = True
Dep = None
@@ -114,97 +113,122 @@ class DependencyRules(object):
Dep.GetVersion()))
return Result
- ## Check whether a package exists in current workspace.
+ ## Check whether a package exists in a package list specified by PkgsToBeDepend.
#
# @param Guid: Guid of a package
# @param Version: Version of a package
+ # @return: True if package exist
+ # False else
#
def CheckPackageExists(self, Guid, Version):
Logger.Verbose(ST.MSG_CHECK_PACKAGE_START)
- for (PkgName, PkgGuid, PkgVer, PkgPath) in self.WsPkgList:
- if PkgName or PkgPath:
- pass
+ Found = False
+ for (PkgGuid, PkgVer) in self.PkgsToBeDepend:
if (PkgGuid == Guid):
#
# if version is not empty and not equal, then not match
#
if Version and (PkgVer != Version):
- return False
+ Found = False
+ break
else:
- return True
+ Found = True
+ break
else:
- return False
-
+ Found = False
+
Logger.Verbose(ST.MSG_CHECK_PACKAGE_FINISH)
+ return Found
- ## Check whether a package depex satisfied by current workspace.
+ ## Check whether a package depex satisfied.
#
# @param PkgObj: A package object
- # @param DpObj: A package depex object
+ # @param DpObj: A distribution object
+ # @return: True if package depex satisified
+ # False else
#
- def CheckPackageDepexSatisfied(self, PkgObj, DpObj=None, \
- ReturnCode=DEPEX_CHECK_SUCCESS):
-
+ def CheckPackageDepexSatisfied(self, PkgObj, DpObj=None):
ModuleDict = PkgObj.GetModuleDict()
for ModKey in ModuleDict.keys():
ModObj = ModuleDict[ModKey]
- if self.CheckModuleDepexSatisfied(ModObj, DpObj, ReturnCode):
+ if self.CheckModuleDepexSatisfied(ModObj, DpObj):
continue
else:
return False
return True
- ## Check whether a DP exists in current workspace.
+ ## Check whether a DP exists.
#
- # @param Guid: Guid of a module
- # @param Version: Version of a module
- #
- def CheckDpExists(self, Guid, Version, ReturnCode=DEPEX_CHECK_SUCCESS):
- if ReturnCode:
- pass
+ # @param Guid: Guid of a Distribution
+ # @param Version: Version of a Distribution
+ # @return: True if Distribution exist
+ # False else
+ def CheckDpExists(self, Guid, Version):
Logger.Verbose(ST.MSG_CHECK_DP_START)
DpList = self.IpiDb.GetDp(Guid, Version)
if len(DpList) > 0:
- return True
+ Found = True
else:
- return False
-
- Logger.Verbose(ST.MSG_CHECK_DP_FINISH)
-
+ Found = False
+
+ Logger.Verbose(ST.MSG_CHECK_DP_FINISH)
+ return Found
+
+ ## Check whether a DP depex satisfied by current workspace for Install
+ #
+ # @param DpObj: A distribution object
+ # @return: True if distribution depex satisfied
+ # False else
+ #
+ def CheckInstallDpDepexSatisfied(self, DpObj):
+ self.PkgsToBeDepend = [(PkgInfo[1], PkgInfo[2]) for PkgInfo in self.WsPkgList]
+ return self.CheckDpDepexSatisfied(DpObj)
+
+ ## Check whether a DP depex satisfied by current workspace
+ # (excluding the original distribution's packages to be replaced) for Replace
+ #
+ # @param DpObj: A distribution object
+ # @param OrigDpGuid: The original distribution's Guid
+ # @param OrigDpVersion: The original distribution's Version
+ #
+ def ReplaceCheckNewDpDepex(self, DpObj, OrigDpGuid, OrigDpVersion):
+ self.PkgsToBeDepend = [(PkgInfo[1], PkgInfo[2]) for PkgInfo in self.WsPkgList]
+ OrigDpPackageList = self.IpiDb.GetPackageListFromDp(OrigDpGuid, OrigDpVersion)
+ for OrigPkgInfo in OrigDpPackageList:
+ Guid, Version = OrigPkgInfo[0], OrigPkgInfo[1]
+ if (Guid, Version) in self.PkgsToBeDepend:
+ self.PkgsToBeDepend.remove((Guid, Version))
+ return self.CheckDpDepexSatisfied(DpObj)
+
## Check whether a DP depex satisfied by current workspace.
#
- # @param DpObj: Depex object
- # @param ReturnCode: ReturnCode
+ # @param DpObj: A distribution object
#
- def CheckDpDepexSatisfied(self, DpObj, ReturnCode=DEPEX_CHECK_SUCCESS):
-
+ def CheckDpDepexSatisfied(self, DpObj):
for PkgKey in DpObj.PackageSurfaceArea.keys():
PkgObj = DpObj.PackageSurfaceArea[PkgKey]
- if self.CheckPackageDepexSatisfied(PkgObj, DpObj, ReturnCode):
+ if self.CheckPackageDepexSatisfied(PkgObj, DpObj):
continue
else:
return False
for ModKey in DpObj.ModuleSurfaceArea.keys():
ModObj = DpObj.ModuleSurfaceArea[ModKey]
- if self.CheckModuleDepexSatisfied(ModObj, DpObj, ReturnCode):
+ if self.CheckModuleDepexSatisfied(ModObj, DpObj):
continue
else:
return False
return True
- ## Check whether a DP depex satisfied by current workspace. Return False
- # if Can not remove (there is dependency), True else
+ ## Check whether a DP could be removed from current workspace.
#
# @param DpGuid: File's guid
# @param DpVersion: File's version
- # @param ReturnCode: ReturnCode
- #
- def CheckDpDepexForRemove(self, DpGuid, DpVersion, \
- ReturnCode=DEPEX_CHECK_SUCCESS):
- if ReturnCode:
- pass
+ # @retval Removable: True if distribution could be removed, False Else
+ # @retval DependModuleList: the list of modules that make distribution can not be removed
+ #
+ def CheckDpDepexForRemove(self, DpGuid, DpVersion):
Removable = True
DependModuleList = []
WsModuleList = self.WsModuleList
@@ -223,15 +247,14 @@ class DependencyRules(object):
# List of item (PkgGuid, PkgVersion, InstallPath)
DpPackageList = self.IpiDb.GetPackageListFromDp(DpGuid, DpVersion)
DpPackagePathList = []
- WorkSP = environ["WORKSPACE"]
+ WorkSP = GlobalData.gWORKSPACE
for (PkgName, PkgGuid, PkgVersion, DecFile) in self.WsPkgList:
if PkgName:
pass
DecPath = dirname(DecFile)
if DecPath.find(WorkSP) > -1:
- InstallPath = DecPath[DecPath.find(WorkSP) + len(WorkSP) + 1:]
- DecFileRelaPath = \
- DecFile[DecFile.find(WorkSP) + len(WorkSP) + 1:]
+ InstallPath = GetRelativePath(DecPath,WorkSP)
+ DecFileRelaPath = GetRelativePath(DecFile,WorkSP)
else:
InstallPath = DecPath
DecFileRelaPath = DecFile
@@ -251,26 +274,87 @@ class DependencyRules(object):
# check modules to see if has dependency on package of current DP
#
for Module in WsModuleList:
- if (CheckModuleDependFromInf(Module, DpPackagePathList)):
+ if (not VerifyRemoveModuleDep(Module, DpPackagePathList)):
Removable = False
DependModuleList.append(Module)
return (Removable, DependModuleList)
+ ## Check whether a DP could be replaced by a distribution containing NewDpPkgList
+ # from current workspace.
+ #
+ # @param OrigDpGuid: original Dp's Guid
+ # @param OrigDpVersion: original Dp's version
+ # @param NewDpPkgList: a list of package information (Guid, Version) in new Dp
+ # @retval Replaceable: True if distribution could be replaced, False Else
+ # @retval DependModuleList: the list of modules that make distribution can not be replaced
+ #
+ def CheckDpDepexForReplace(self, OrigDpGuid, OrigDpVersion, NewDpPkgList):
+ Replaceable = True
+ DependModuleList = []
+ WsModuleList = self.WsModuleList
+ #
+ # remove modules that included in current DP
+ # List of item (FilePath)
+ DpModuleList = self.IpiDb.GetDpModuleList(OrigDpGuid, OrigDpVersion)
+ for Module in DpModuleList:
+ if Module in WsModuleList:
+ WsModuleList.remove(Module)
+ else:
+ Logger.Warn("UPT\n",
+ ST.ERR_MODULE_NOT_INSTALLED % Module)
+
+ OtherPkgList = NewDpPkgList
+ #
+ # get packages in current Dp and find the install path
+ # List of item (PkgGuid, PkgVersion, InstallPath)
+ DpPackageList = self.IpiDb.GetPackageListFromDp(OrigDpGuid, OrigDpVersion)
+ DpPackagePathList = []
+ WorkSP = GlobalData.gWORKSPACE
+ for (PkgName, PkgGuid, PkgVersion, DecFile) in self.WsPkgList:
+ if PkgName:
+ pass
+ DecPath = dirname(DecFile)
+ if DecPath.find(WorkSP) > -1:
+ InstallPath = GetRelativePath(DecPath,WorkSP)
+ DecFileRelaPath = GetRelativePath(DecFile,WorkSP)
+ else:
+ InstallPath = DecPath
+ DecFileRelaPath = DecFile
+
+ if (PkgGuid, PkgVersion, InstallPath) in DpPackageList:
+ DpPackagePathList.append(DecFileRelaPath)
+ DpPackageList.remove((PkgGuid, PkgVersion, InstallPath))
+ else:
+ OtherPkgList.append((PkgGuid, PkgVersion))
+
+ #
+ # the left items in DpPackageList are the packages that installed but not found anymore
+ #
+ for (PkgGuid, PkgVersion, InstallPath) in DpPackageList:
+ Logger.Warn("UPT",
+ ST.WARN_INSTALLED_PACKAGE_NOT_FOUND%(PkgGuid, PkgVersion, InstallPath))
+
+ #
+ # check modules to see if it can be satisfied by package not belong to removed DP
+ #
+ for Module in WsModuleList:
+ if (not VerifyReplaceModuleDep(Module, DpPackagePathList, OtherPkgList)):
+ Replaceable = False
+ DependModuleList.append(Module)
+ return (Replaceable, DependModuleList)
+
+
## check whether module depends on packages in DpPackagePathList, return True
# if found, False else
#
# @param Path: a module path
# @param DpPackagePathList: a list of Package Paths
+# @retval: False: module depends on package in DpPackagePathList
+# True: module doesn't depend on package in DpPackagePathList
#
-def CheckModuleDependFromInf(Path, DpPackagePathList):
-
- #
- # use InfParser to parse inf, then get the information for now,
- # later on, may consider only parse to get the package dependency info
- # (Need to take care how to deal wit Macros)
- #
- WorkSP = getenv('WORKSPACE')
+def VerifyRemoveModuleDep(Path, DpPackagePathList):
+ WorkSP = GlobalData.gWORKSPACE
try:
PomAli = InfPomAlignment(Path, WorkSP, Skip=True)
@@ -278,16 +362,47 @@ def CheckModuleDependFromInf(Path, DpPackagePathList):
for Item in PomAli.GetPackageDependencyList():
if Item.GetPackageFilePath() in DpPackagePathList:
Logger.Info(ST.MSG_MODULE_DEPEND_ON % (Path, Item.GetPackageFilePath()))
- return True
+ return False
else:
- return False
+ return True
except FatalError, ErrCode:
if ErrCode.message == EDK1_INF_ERROR:
Logger.Warn("UPT",
ST.WRN_EDK1_INF_FOUND%Path)
- return False
+ return True
else:
- return False
-
+ return True
+
+## check whether module depends on packages in DpPackagePathList and can not be satisfied by OtherPkgList
+#
+# @param Path: a module path
+# @param DpPackagePathList: a list of Package Paths
+# @param OtherPkgList: a list of Package Information (Guid, Version)
+# @retval: False: module depends on package in DpPackagePathList and can not be satisfied by OtherPkgList
+# True: either module doesn't depend on DpPackagePathList or module depends on DpPackagePathList
+# but can be satisfied by OtherPkgList
+#
+def VerifyReplaceModuleDep(Path, DpPackagePathList, OtherPkgList):
+ WorkSP = GlobalData.gWORKSPACE
+
+ try:
+ PomAli = InfPomAlignment(Path, WorkSP, Skip=True)
+
+ for Item in PomAli.GetPackageDependencyList():
+ if Item.GetPackageFilePath() in DpPackagePathList:
+ Guid, Version = Item.GetGuid(), Item.GetVersion()
+ if (Guid, Version) not in OtherPkgList:
+ Logger.Info(ST.MSG_MODULE_DEPEND_ON % (Path, Item.GetPackageFilePath()))
+ return False
+ else:
+ return True
+ except FatalError, ErrCode:
+ if ErrCode.message == EDK1_INF_ERROR:
+ Logger.Warn("UPT",
+ ST.WRN_EDK1_INF_FOUND%Path)
+ return True
+ else:
+ return True
+
diff --git a/BaseTools/Source/Python/UPT/Core/DistributionPackageClass.py b/BaseTools/Source/Python/UPT/Core/DistributionPackageClass.py
index 8ac8d4ed52..6db13b06b6 100644
--- a/BaseTools/Source/Python/UPT/Core/DistributionPackageClass.py
+++ b/BaseTools/Source/Python/UPT/Core/DistributionPackageClass.py
@@ -1,7 +1,7 @@
## @file
# This file is used to define a class object to describe a distribution package
#
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2014, 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
@@ -195,6 +195,7 @@ class DistributionPackageClass(object):
#
def GetDistributionFileList(self):
MetaDataFileList = []
+ SkipModulesUniList = []
for Guid, Version, Path in self.PackageSurfaceArea:
Package = self.PackageSurfaceArea[Guid, Version, Path]
@@ -206,7 +207,15 @@ class DistributionPackageClass(object):
SearchPath = os.path.normpath(os.path.join(os.path.dirname(FullPath), IncludePath))
AddPath = os.path.normpath(os.path.join(PackagePath, IncludePath))
self.FileList += GetNonMetaDataFiles(SearchPath, ['CVS', '.svn'], False, AddPath)
-
+ #
+ # Add the miscellaneous files on DEC file
+ #
+ for MiscFileObj in Package.GetMiscFileList():
+ for FileObj in MiscFileObj.GetFileList():
+ MiscFileFullPath = os.path.normpath(os.path.join(os.path.dirname(FullPath), FileObj.GetURI()))
+ if MiscFileFullPath not in self.FileList:
+ self.FileList.append(MiscFileFullPath)
+
Module = None
ModuleDict = Package.GetModuleDict()
for Guid, Version, Name, Path in ModuleDict:
@@ -215,15 +224,43 @@ class DistributionPackageClass(object):
FullPath = Module.GetFullPath()
PkgRelPath = os.path.normpath(os.path.join(PackagePath, ModulePath))
MetaDataFileList.append(Path)
- self.FileList += GetNonMetaDataFiles(os.path.dirname(FullPath), ['CVS', '.svn'], False, PkgRelPath)
-
+ SkipList = ['CVS', '.svn']
+ NonMetaDataFileList = []
+ if Module.UniFileClassObject:
+ for UniFile in Module.UniFileClassObject.IncFileList:
+ OriPath = os.path.normpath(os.path.dirname(FullPath))
+ UniFilePath = os.path.normpath(os.path.join(PkgRelPath, UniFile.Path[len(OriPath) + 1:]))
+ if UniFilePath not in SkipModulesUniList:
+ SkipModulesUniList.append(UniFilePath)
+ for IncludeFile in Module.UniFileClassObject.IncludePathList:
+ if IncludeFile not in SkipModulesUniList:
+ SkipModulesUniList.append(IncludeFile)
+ NonMetaDataFileList = GetNonMetaDataFiles(os.path.dirname(FullPath), SkipList, False, PkgRelPath)
+ for NonMetaDataFile in NonMetaDataFileList:
+ if NonMetaDataFile not in self.FileList:
+ self.FileList.append(NonMetaDataFile)
for Guid, Version, Name, Path in self.ModuleSurfaceArea:
Module = self.ModuleSurfaceArea[Guid, Version, Name, Path]
ModulePath = Module.GetModulePath()
FullPath = Module.GetFullPath()
MetaDataFileList.append(Path)
- self.FileList += GetNonMetaDataFiles(os.path.dirname(FullPath), ['CVS', '.svn'], False, ModulePath)
-
+ SkipList = ['CVS', '.svn']
+ NonMetaDataFileList = []
+ if Module.UniFileClassObject:
+ for UniFile in Module.UniFileClassObject.IncFileList:
+ OriPath = os.path.normpath(os.path.dirname(FullPath))
+ UniFilePath = os.path.normpath(os.path.join(ModulePath, UniFile.Path[len(OriPath) + 1:]))
+ if UniFilePath not in SkipModulesUniList:
+ SkipModulesUniList.append(UniFilePath)
+ NonMetaDataFileList = GetNonMetaDataFiles(os.path.dirname(FullPath), SkipList, False, ModulePath)
+ for NonMetaDataFile in NonMetaDataFileList:
+ if NonMetaDataFile not in self.FileList:
+ self.FileList.append(NonMetaDataFile)
+
+ for SkipModuleUni in SkipModulesUniList:
+ if SkipModuleUni in self.FileList:
+ self.FileList.remove(SkipModuleUni)
+
return self.FileList, MetaDataFileList
diff --git a/BaseTools/Source/Python/UPT/Core/FileHook.py b/BaseTools/Source/Python/UPT/Core/FileHook.py
new file mode 100644
index 0000000000..d8736a8723
--- /dev/null
+++ b/BaseTools/Source/Python/UPT/Core/FileHook.py
@@ -0,0 +1,199 @@
+## @file
+# This file hooks file and directory creation and removal
+#
+# Copyright (c) 2014, 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
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+
+'''
+File hook
+'''
+
+import os
+import stat
+import time
+import zipfile
+from time import sleep
+from Library import GlobalData
+
+__built_in_remove__ = os.remove
+__built_in_mkdir__ = os.mkdir
+__built_in_rmdir__ = os.rmdir
+__built_in_chmod__ = os.chmod
+__built_in_open__ = open
+
+_RMFILE = 0
+_MKFILE = 1
+_RMDIR = 2
+_MKDIR = 3
+_CHMOD = 4
+
+gBACKUPFILE = 'file.backup'
+gEXCEPTION_LIST = ['Conf'+os.sep+'DistributionPackageDatabase.db', '.tmp', gBACKUPFILE]
+
+class _PathInfo:
+ def __init__(self, action, path, mode=-1):
+ self.action = action
+ self.path = path
+ self.mode = mode
+
+class RecoverMgr:
+ def __init__(self, workspace):
+ self.rlist = []
+ self.zip = None
+ self.workspace = os.path.normpath(workspace)
+ self.backupfile = gBACKUPFILE
+ self.zipfile = os.path.join(self.workspace, gBACKUPFILE)
+
+ def _createzip(self):
+ if self.zip:
+ return
+ self.zip = zipfile.ZipFile(self.zipfile, 'w', zipfile.ZIP_DEFLATED)
+
+ def _save(self, tmp, path):
+ if not self._tryhook(path):
+ return
+ self.rlist.append(_PathInfo(tmp, path))
+
+ def bkrmfile(self, path):
+ arc = self._tryhook(path)
+ if arc and os.path.isfile(path):
+ self._createzip()
+ self.zip.write(path, arc.encode('utf_8'))
+ sta = os.stat(path)
+ oldmode = stat.S_IMODE(sta.st_mode)
+ self.rlist.append(_PathInfo(_CHMOD, path, oldmode))
+ self.rlist.append(_PathInfo(_RMFILE, path))
+ __built_in_remove__(path)
+
+ def bkmkfile(self, path, mode, bufsize):
+ if not os.path.exists(path):
+ self._save(_MKFILE, path)
+ return __built_in_open__(path, mode, bufsize)
+
+ def bkrmdir(self, path):
+ if os.path.exists(path):
+ sta = os.stat(path)
+ oldmode = stat.S_IMODE(sta.st_mode)
+ self.rlist.append(_PathInfo(_CHMOD, path, oldmode))
+ self._save(_RMDIR, path)
+ __built_in_rmdir__(path)
+
+ def bkmkdir(self, path, mode):
+ if not os.path.exists(path):
+ self._save(_MKDIR, path)
+ __built_in_mkdir__(path, mode)
+
+ def bkchmod(self, path, mode):
+ if self._tryhook(path) and os.path.exists(path):
+ sta = os.stat(path)
+ oldmode = stat.S_IMODE(sta.st_mode)
+ self.rlist.append(_PathInfo(_CHMOD, path, oldmode))
+ __built_in_chmod__(path, mode)
+
+ def rollback(self):
+ if self.zip:
+ self.zip.close()
+ self.zip = None
+ index = len(self.rlist) - 1
+ while index >= 0:
+ item = self.rlist[index]
+ exist = os.path.exists(item.path)
+ if item.action == _MKFILE and exist:
+ #if not os.access(item.path, os.W_OK):
+ # os.chmod(item.path, S_IWUSR)
+ __built_in_remove__(item.path)
+ elif item.action == _RMFILE and not exist:
+ if not self.zip:
+ self.zip = zipfile.ZipFile(self.zipfile, 'r', zipfile.ZIP_DEFLATED)
+ arcname = os.path.normpath(item.path)
+ arcname = arcname[len(self.workspace)+1:].encode('utf_8')
+ if os.sep != "/" and os.sep in arcname:
+ arcname = arcname.replace(os.sep, '/')
+ mtime = self.zip.getinfo(arcname).date_time
+ content = self.zip.read(arcname)
+ filep = __built_in_open__(item.path, "wb")
+ filep.write(content)
+ filep.close()
+ intime = time.mktime(mtime + (0, 0, 0))
+ os.utime(item.path, (intime, intime))
+ elif item.action == _MKDIR and exist:
+ while True:
+ try:
+ __built_in_rmdir__(item.path)
+ break
+ except IOError:
+ # Sleep a short time and try again
+ # The anti-virus software may delay the file removal in this directory
+ sleep(0.1)
+ elif item.action == _RMDIR and not exist:
+ __built_in_mkdir__(item.path)
+ elif item.action == _CHMOD and exist:
+ try:
+ __built_in_chmod__(item.path, item.mode)
+ except EnvironmentError:
+ pass
+ index -= 1
+ self.commit()
+
+ def commit(self):
+ if self.zip:
+ self.zip.close()
+ __built_in_remove__(self.zipfile)
+
+ # Check if path needs to be hooked
+ def _tryhook(self, path):
+ path = os.path.normpath(path)
+ works = self.workspace if str(self.workspace).endswith(os.sep) else (self.workspace + os.sep)
+ if not path.startswith(works):
+ return ''
+ for exceptdir in gEXCEPTION_LIST:
+ full = os.path.join(self.workspace, exceptdir)
+ if full == path or path.startswith(full + os.sep) or os.path.split(full)[0] == path:
+ return ''
+ return path[len(self.workspace)+1:]
+
+def _hookrm(path):
+ if GlobalData.gRECOVERMGR:
+ GlobalData.gRECOVERMGR.bkrmfile(path)
+ else:
+ __built_in_remove__(path)
+
+def _hookmkdir(path, mode=0777):
+ if GlobalData.gRECOVERMGR:
+ GlobalData.gRECOVERMGR.bkmkdir(path, mode)
+ else:
+ __built_in_mkdir__(path, mode)
+
+def _hookrmdir(path):
+ if GlobalData.gRECOVERMGR:
+ GlobalData.gRECOVERMGR.bkrmdir(path)
+ else:
+ __built_in_rmdir__(path)
+
+def _hookmkfile(path, mode='r', bufsize=-1):
+ if GlobalData.gRECOVERMGR:
+ return GlobalData.gRECOVERMGR.bkmkfile(path, mode, bufsize)
+ return __built_in_open__(path, mode, bufsize)
+
+def _hookchmod(path, mode):
+ if GlobalData.gRECOVERMGR:
+ GlobalData.gRECOVERMGR.bkchmod(path, mode)
+ else:
+ __built_in_chmod__(path, mode)
+
+def SetRecoverMgr(mgr):
+ GlobalData.gRECOVERMGR = mgr
+
+os.remove = _hookrm
+os.mkdir = _hookmkdir
+os.rmdir = _hookrmdir
+os.chmod = _hookchmod
+__FileHookOpen__ = _hookmkfile
diff --git a/BaseTools/Source/Python/UPT/Core/IpiDb.py b/BaseTools/Source/Python/UPT/Core/IpiDb.py
index e45acb7d48..2c444f903c 100644
--- a/BaseTools/Source/Python/UPT/Core/IpiDb.py
+++ b/BaseTools/Source/Python/UPT/Core/IpiDb.py
@@ -1,7 +1,7 @@
## @file
# This file is for installed package information database operations
#
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2014, 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
@@ -27,6 +27,7 @@ import Logger.Log as Logger
from Logger import StringTable as ST
from Logger.ToolError import UPT_ALREADY_RUNNING_ERROR
from Logger.ToolError import UPT_DB_UPDATE_ERROR
+import platform as pf
## IpiDb
#
@@ -39,7 +40,7 @@ from Logger.ToolError import UPT_DB_UPDATE_ERROR
#
#
class IpiDatabase(object):
- def __init__(self, DbPath):
+ def __init__(self, DbPath, Workspace):
Dir = os.path.dirname(DbPath)
if not os.path.isdir(Dir):
os.mkdir(Dir)
@@ -54,6 +55,7 @@ class IpiDatabase(object):
self.ModDepexTable = 'ModDepexInfo'
self.DpFileListTable = 'DpFileListInfo'
self.DummyTable = 'Dummy'
+ self.Workspace = os.path.normpath(Workspace)
## Initialize build database
#
@@ -156,6 +158,12 @@ class IpiDatabase(object):
Logger.Verbose(ST.MSG_INIT_IPI_FINISH)
+ def RollBack(self):
+ self.Conn.rollback()
+
+ def Commit(self):
+ self.Conn.commit()
+
## Add a distribution install information from DpObj
#
# @param DpObj:
@@ -222,7 +230,6 @@ class IpiDatabase(object):
self._AddDp(DpObj.Header.GetGuid(), DpObj.Header.GetVersion(), \
NewDpPkgFileName, DpPkgFileName, RePackage)
- self.Conn.commit()
except sqlite3.IntegrityError, DetailMsg:
Logger.Error("UPT",
UPT_DB_UPDATE_ERROR,
@@ -266,7 +273,13 @@ class IpiDatabase(object):
# @param Path: A Md5Sum
#
def _AddDpFilePathList(self, DpGuid, DpVersion, Path, Md5Sum):
-
+ Path = os.path.normpath(Path)
+ if pf.system() == 'Windows':
+ if Path.startswith(self.Workspace):
+ Path = Path[len(self.Workspace):]
+ else:
+ if Path.startswith(self.Workspace + os.sep):
+ Path = Path[len(self.Workspace)+1:]
SqlCommand = """insert into %s values('%s', '%s', '%s', '%s')""" % \
(self.DpFileListTable, Path, DpGuid, DpVersion, Md5Sum)
@@ -320,6 +333,11 @@ class IpiDatabase(object):
if PkgVersion == None or len(PkgVersion.strip()) == 0:
PkgVersion = 'N/A'
+
+ if os.name == 'posix':
+ Path = Path.replace('\\', os.sep)
+ else:
+ Path = Path.replace('/', os.sep)
#
# Add module from package information to DB.
@@ -378,6 +396,11 @@ class IpiDatabase(object):
if DepexVersion == None or len(DepexVersion.strip()) == 0:
DepexVersion = 'N/A'
+
+ if os.name == 'posix':
+ Path = Path.replace('\\', os.sep)
+ else:
+ Path = Path.replace('/', os.sep)
#
# Add module depex information to DB.
@@ -478,7 +501,7 @@ class IpiDatabase(object):
(self.DpTable, DpGuid, DpVersion)
self.Cur.execute(SqlCommand)
- self.Conn.commit()
+ #self.Conn.commit()
## Get a list of distribution install information.
#
@@ -554,7 +577,7 @@ class IpiDatabase(object):
for Result in self.Cur:
Path = Result[0]
Md5Sum = Result[3]
- PathList.append((Path, Md5Sum))
+ PathList.append((os.path.join(self.Workspace, Path), Md5Sum))
return PathList
@@ -824,7 +847,7 @@ class IpiDatabase(object):
self.Cur.execute(SqlCommand)
for ModuleInfo in self.Cur:
FilePath = ModuleInfo[0]
- ModList.append(FilePath)
+ ModList.append(os.path.join(self.Workspace, FilePath))
return ModList
@@ -844,7 +867,7 @@ class IpiDatabase(object):
ModuleVersion = '%s' and InstallPath ='%s'
""" % (self.ModDepexTable, Guid, Version, Path)
self.Cur.execute(SqlCommand)
- self.Conn.commit()
+
DepexList = []
for DepInfo in self.Cur:
@@ -853,7 +876,25 @@ class IpiDatabase(object):
DepexList.append((DepexGuid, DepexVersion))
return DepexList
-
+
+ ## Inventory the distribution installed to current workspace
+ #
+ # Inventory the distribution installed to current workspace
+ #
+ def InventoryDistInstalled(self):
+ SqlCommand = """select * from %s """ % (self.DpTable)
+ self.Cur.execute(SqlCommand)
+
+ DpInfoList = []
+ for Result in self.Cur:
+ DpGuid = Result[0]
+ DpVersion = Result[1]
+ DpAliasName = Result[3]
+ DpFileName = Result[4]
+ DpInfoList.append((DpGuid, DpVersion, DpFileName, DpAliasName))
+
+ return DpInfoList
+
## Close entire database
#
# Close the connection and cursor
diff --git a/BaseTools/Source/Python/UPT/Core/PackageFile.py b/BaseTools/Source/Python/UPT/Core/PackageFile.py
index 04c5d4e8d0..47ea0bc0a9 100644
--- a/BaseTools/Source/Python/UPT/Core/PackageFile.py
+++ b/BaseTools/Source/Python/UPT/Core/PackageFile.py
@@ -2,7 +2,7 @@
#
# PackageFile class represents the zip file of a distribution package.
#
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2014, 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
@@ -36,7 +36,7 @@ import Logger.Log as Logger
from Logger import StringTable as ST
from Library.Misc import CreateDirectory
from Library.Misc import RemoveDirectory
-
+from Core.FileHook import __FileHookOpen__
class PackageFile:
@@ -96,7 +96,7 @@ class PackageFile:
## Extract the file
#
# @param Which: the source path
- # @param To: the destination path
+ # @param ToDest: the destination path
#
def Extract(self, Which, ToDest):
Which = os.path.normpath(Which)
@@ -116,7 +116,8 @@ class PackageFile:
Logger.Warn("PackagingTool", \
ST.WRN_FILE_NOT_OVERWRITTEN % ToDest)
return
- ToFile = open(ToDest, "wb")
+ else:
+ ToFile = __FileHookOpen__(ToDest, 'wb')
except BaseException, Xstr:
Logger.Error("PackagingTool", FILE_OPEN_FAILURE,
ExtraData="%s (%s)" % (ToDest, str(Xstr)))
@@ -234,6 +235,8 @@ class PackageFile:
#
def PackData(self, Data, ArcName):
try:
+ if os.path.splitext(ArcName)[1].lower() == '.pkg':
+ Data = Data.encode('utf_8')
self._ZipFile.writestr(ArcName, Data)
except BaseException, Xstr:
Logger.Error("PackagingTool", FILE_COMPRESS_FAILURE,