public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [patch] BaseTool/UPT: Add Test Install
@ 2016-07-29  7:58 hesschen
  2016-08-02  4:04 ` Zhu, Yonghong
  0 siblings, 1 reply; 2+ messages in thread
From: hesschen @ 2016-07-29  7:58 UTC (permalink / raw)
  To: edk2-devel

Add a new function to test if a DIST file list
one by one to see if they can meet the requirement
of Dependency.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: hesschen <hesheng.chen@intel.com>
---
 .../Source/Python/UPT/Core/DependencyRules.py      |  21 ++++-
 BaseTools/Source/Python/UPT/Logger/StringTable.py  |   5 ++
 BaseTools/Source/Python/UPT/TestInstall.py         | 100 +++++++++++++++++++++
 BaseTools/Source/Python/UPT/UPT.py                 |  16 ++++
 4 files changed, 141 insertions(+), 1 deletion(-)
 create mode 100644 BaseTools/Source/Python/UPT/TestInstall.py

diff --git a/BaseTools/Source/Python/UPT/Core/DependencyRules.py b/BaseTools/Source/Python/UPT/Core/DependencyRules.py
index 4608ed6..ee06c53 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 - 2014, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2016, 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 
@@ -183,6 +183,25 @@ class DependencyRules(object):
     def CheckInstallDpDepexSatisfied(self, DpObj):
         self.PkgsToBeDepend = [(PkgInfo[1], PkgInfo[2]) for PkgInfo in self.WsPkgList]
         return self.CheckDpDepexSatisfied(DpObj)
+    
+    # # Check whether multiple DP depex satisfied by current workspace for Install
+    #
+    # @param DpObjList:  A distribution object list
+    # @return: True if distribution depex satisfied
+    #          False else
+    #
+    def CheckTestInstallPdDepexSatisfied(self, DpObjList):
+        self.PkgsToBeDepend = [(PkgInfo[1], PkgInfo[2]) for PkgInfo in self.WsPkgList]
+        for DpObj in DpObjList:
+            if self.CheckDpDepexSatisfied(DpObj):
+                for PkgKey in DpObj.PackageSurfaceArea.keys():
+                    PkgObj = DpObj.PackageSurfaceArea[PkgKey]
+                    self.PkgsToBeDepend.append((PkgObj.Guid, PkgObj.Version))
+            else:
+                return False, DpObj
+
+        return True, DpObj
+
 
     ## Check whether a DP depex satisfied by current workspace 
     #  (excluding the original distribution's packages to be replaced) for Replace
diff --git a/BaseTools/Source/Python/UPT/Logger/StringTable.py b/BaseTools/Source/Python/UPT/Logger/StringTable.py
index 96f0e1c..4c42661 100644
--- a/BaseTools/Source/Python/UPT/Logger/StringTable.py
+++ b/BaseTools/Source/Python/UPT/Logger/StringTable.py
@@ -858,3 +858,8 @@ HLP_SPECIFY_PACKAGE_NAME_TO_BE_REPLACED = _(
     "Specify the UEFI Distribution Package file name to be replaced")
 HLP_USE_GUIDED_PATHS = _(
     "Install packages to the following directory path by default: <PackageName>_<PACKAGE_GUID>_<PACKAGE_VERSION>")
+HLP_TEST_INSTALL = _(
+    "Specify the UEFI Distribution Package filenames to install")
+
+MSG_TEST_INSTALL_PASS = _("All distribution package file are satisfied for dependence check.")
+MSG_TEST_INSTALL_FAIL = _("NOT all distribution package file are satisfied for dependence check.")
diff --git a/BaseTools/Source/Python/UPT/TestInstall.py b/BaseTools/Source/Python/UPT/TestInstall.py
new file mode 100644
index 0000000..71fe928
--- /dev/null
+++ b/BaseTools/Source/Python/UPT/TestInstall.py
@@ -0,0 +1,100 @@
+# # @file
+# Test Install distribution package
+#
+# Copyright (c) 2016, 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.
+#
+"""
+Test Install multiple distribution package
+"""
+# #
+# Import Modules
+#
+from Library import GlobalData
+import Logger.Log as Logger
+from Logger import StringTable as ST
+import Logger.ToolError as TE
+from Core.DependencyRules import DependencyRules
+from InstallPkg import UnZipDp
+
+import shutil
+from traceback import format_exc
+from platform import python_version
+from sys import platform
+
+# # 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
+#
+def Main(Options=None):
+    ContentZipFile, DistFile = None, None
+    ReturnCode = 0
+
+    try:
+        DataBase = GlobalData.gDB
+        WorkspaceDir = GlobalData.gWORKSPACE
+        if not Options.DistFiles:
+            Logger.Error("TestInstallPkg", TE.OPTION_MISSING, ExtraData=ST.ERR_SPECIFY_PACKAGE)
+
+        DistPkgList = []
+        for DistFile in Options.DistFiles:
+            DistPkg, ContentZipFile, __, DistFile = UnZipDp(WorkspaceDir, DistFile)
+            DistPkgList.append(DistPkg)
+
+        #
+        # check dependency
+        #
+        Dep = DependencyRules(DataBase)
+        Result = True
+        DpObj = None
+        try:
+            Result, DpObj = Dep.CheckTestInstallPdDepexSatisfied(DistPkgList)
+        except:
+            Result = False
+        
+        if Result:
+            Logger.Quiet(ST.MSG_TEST_INSTALL_PASS)
+        else:
+            Logger.Quiet(ST.MSG_TEST_INSTALL_FAIL)
+
+    except TE.FatalError, XExcept:
+        ReturnCode = XExcept.args[0]
+        if Logger.GetLevel() <= Logger.DEBUG_9:
+            Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())
+
+    except Exception, x:
+        ReturnCode = TE.CODE_ERROR
+        Logger.Error(
+                    "\nTestInstallPkg",
+                    TE.CODE_ERROR,
+                    ST.ERR_UNKNOWN_FATAL_INSTALL_ERR % Options.DistFiles,
+                    ExtraData=ST.MSG_SEARCH_FOR_HELP,
+                    RaiseError=False
+                    )
+        Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())
+
+    finally:
+        Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_STARTED)
+        if DistFile:
+            DistFile.Close()
+        if ContentZipFile:
+            ContentZipFile.Close()
+        if GlobalData.gUNPACK_DIR:
+            shutil.rmtree(GlobalData.gUNPACK_DIR)
+            GlobalData.gUNPACK_DIR = None
+        Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_DONE)
+    if ReturnCode == 0:
+        Logger.Quiet(ST.MSG_FINISH)
+    return ReturnCode
+
diff --git a/BaseTools/Source/Python/UPT/UPT.py b/BaseTools/Source/Python/UPT/UPT.py
index 59c4a88..8dd949a 100644
--- a/BaseTools/Source/Python/UPT/UPT.py
+++ b/BaseTools/Source/Python/UPT/UPT.py
@@ -46,6 +46,7 @@ import InstallPkg
 import RmPkg
 import InventoryWs
 import ReplacePkg
+import TestInstall
 from Library.Misc import GetWorkspace
 from Library import GlobalData
 from Core.IpiDb import IpiDatabase
@@ -69,6 +70,9 @@ def CheckConflictOption(Opt):
         Logger.Error("UPT", OPTION_CONFLICT, ExtraData=ST.ERR_I_R_EXCLUSIVE)
     elif Opt.PackFileToCreate and  Opt.PackFileToRemove:
         Logger.Error("UPT", OPTION_CONFLICT, ExtraData=ST.ERR_C_R_EXCLUSIVE)
+    elif Opt.TestDistFiles and (Opt.PackFileToCreate or Opt.PackFileToInstall \
+                                or Opt.PackFileToRemove or Opt.PackFileToReplace):
+        Logger.Error("UPT", OPTION_CONFLICT, ExtraData=ST.ERR_C_R_EXCLUSIVE)
 
     if Opt.CustomPath and Opt.UseGuidedPkgPath:
         Logger.Warn("UPT", ST.WARN_CUSTOMPATH_OVERRIDE_USEGUIDEDPATH)
@@ -146,6 +150,9 @@ def Main():
 
     Parser.add_option("--use-guided-paths", action="store_true", dest="Use_Guided_Paths", help=ST.HLP_USE_GUIDED_PATHS)
 
+    Parser.add_option("-j", "--test-install", action="append", type="string",
+                      dest="Test_Install_Distribution_Package_Files", help=ST.HLP_TEST_INSTALL)
+
     Opt = Parser.parse_args()[0]
 
     Var2Var = [
@@ -159,6 +166,7 @@ def Main():
         ("PackFileToReplace", Opt.Replace_Distribution_Package_File),
         ("PackFileToBeReplaced", Opt.Original_Distribution_Package_File),
         ("UseGuidedPkgPath", Opt.Use_Guided_Paths),
+        ("TestDistFiles", Opt.Test_Install_Distribution_Package_Files)
     ]
 
     for Var in Var2Var:
@@ -265,6 +273,14 @@ def Main():
             Opt.PackFileToReplace = AbsPath
             RunModule = ReplacePkg.Main
 
+        elif Opt.Test_Install_Distribution_Package_Files:
+            for Dist in Opt.Test_Install_Distribution_Package_Files:
+                if not Dist.endswith('.dist'):
+                    Logger.Error("TestInstall", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Dist)
+
+            setattr(Opt, 'DistFiles', Opt.Test_Install_Distribution_Package_Files)
+            RunModule = TestInstall.Main
+
         else:
             Parser.print_usage()
             return OPTION_MISSING
-- 
2.7.2.windows.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [patch] BaseTool/UPT: Add Test Install
  2016-07-29  7:58 [patch] BaseTool/UPT: Add Test Install hesschen
@ 2016-08-02  4:04 ` Zhu, Yonghong
  0 siblings, 0 replies; 2+ messages in thread
From: Zhu, Yonghong @ 2016-08-02  4:04 UTC (permalink / raw)
  To: Chen, Hesheng, edk2-devel@lists.01.org

Please remove the trailing whitespace when commit.

Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com> 

Best Regards,
Zhu Yonghong


-----Original Message-----
From: Chen, Hesheng 
Sent: Friday, July 29, 2016 3:58 PM
To: edk2-devel@lists.01.org
Cc: Zhu, Yonghong <yonghong.zhu@intel.com>
Subject: [patch] BaseTool/UPT: Add Test Install

Add a new function to test if a DIST file list one by one to see if they can meet the requirement of Dependency.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: hesschen <hesheng.chen@intel.com>
---
 .../Source/Python/UPT/Core/DependencyRules.py      |  21 ++++-
 BaseTools/Source/Python/UPT/Logger/StringTable.py  |   5 ++
 BaseTools/Source/Python/UPT/TestInstall.py         | 100 +++++++++++++++++++++
 BaseTools/Source/Python/UPT/UPT.py                 |  16 ++++
 4 files changed, 141 insertions(+), 1 deletion(-)  create mode 100644 BaseTools/Source/Python/UPT/TestInstall.py

diff --git a/BaseTools/Source/Python/UPT/Core/DependencyRules.py b/BaseTools/Source/Python/UPT/Core/DependencyRules.py
index 4608ed6..ee06c53 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 - 2014, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2016, 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 @@ -183,6 +183,25 @@ class DependencyRules(object):
     def CheckInstallDpDepexSatisfied(self, DpObj):
         self.PkgsToBeDepend = [(PkgInfo[1], PkgInfo[2]) for PkgInfo in self.WsPkgList]
         return self.CheckDpDepexSatisfied(DpObj)
+    
+    # # Check whether multiple DP depex satisfied by current workspace for Install
+    #
+    # @param DpObjList:  A distribution object list
+    # @return: True if distribution depex satisfied
+    #          False else
+    #
+    def CheckTestInstallPdDepexSatisfied(self, DpObjList):
+        self.PkgsToBeDepend = [(PkgInfo[1], PkgInfo[2]) for PkgInfo in self.WsPkgList]
+        for DpObj in DpObjList:
+            if self.CheckDpDepexSatisfied(DpObj):
+                for PkgKey in DpObj.PackageSurfaceArea.keys():
+                    PkgObj = DpObj.PackageSurfaceArea[PkgKey]
+                    self.PkgsToBeDepend.append((PkgObj.Guid, PkgObj.Version))
+            else:
+                return False, DpObj
+
+        return True, DpObj
+
 
     ## Check whether a DP depex satisfied by current workspace 
     #  (excluding the original distribution's packages to be replaced) for Replace diff --git a/BaseTools/Source/Python/UPT/Logger/StringTable.py b/BaseTools/Source/Python/UPT/Logger/StringTable.py
index 96f0e1c..4c42661 100644
--- a/BaseTools/Source/Python/UPT/Logger/StringTable.py
+++ b/BaseTools/Source/Python/UPT/Logger/StringTable.py
@@ -858,3 +858,8 @@ HLP_SPECIFY_PACKAGE_NAME_TO_BE_REPLACED = _(
     "Specify the UEFI Distribution Package file name to be replaced")  HLP_USE_GUIDED_PATHS = _(
     "Install packages to the following directory path by default: <PackageName>_<PACKAGE_GUID>_<PACKAGE_VERSION>")
+HLP_TEST_INSTALL = _(
+    "Specify the UEFI Distribution Package filenames to install")
+
+MSG_TEST_INSTALL_PASS = _("All distribution package file are satisfied 
+for dependence check.") MSG_TEST_INSTALL_FAIL = _("NOT all distribution 
+package file are satisfied for dependence check.")
diff --git a/BaseTools/Source/Python/UPT/TestInstall.py b/BaseTools/Source/Python/UPT/TestInstall.py
new file mode 100644
index 0000000..71fe928
--- /dev/null
+++ b/BaseTools/Source/Python/UPT/TestInstall.py
@@ -0,0 +1,100 @@
+# # @file
+# Test Install distribution package
+#
+# Copyright (c) 2016, 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.
+#
+"""
+Test Install multiple distribution package """
+# #
+# Import Modules
+#
+from Library import GlobalData
+import Logger.Log as Logger
+from Logger import StringTable as ST
+import Logger.ToolError as TE
+from Core.DependencyRules import DependencyRules from InstallPkg import 
+UnZipDp
+
+import shutil
+from traceback import format_exc
+from platform import python_version
+from sys import platform
+
+# # 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
+#
+def Main(Options=None):
+    ContentZipFile, DistFile = None, None
+    ReturnCode = 0
+
+    try:
+        DataBase = GlobalData.gDB
+        WorkspaceDir = GlobalData.gWORKSPACE
+        if not Options.DistFiles:
+            Logger.Error("TestInstallPkg", TE.OPTION_MISSING, 
+ ExtraData=ST.ERR_SPECIFY_PACKAGE)
+
+        DistPkgList = []
+        for DistFile in Options.DistFiles:
+            DistPkg, ContentZipFile, __, DistFile = UnZipDp(WorkspaceDir, DistFile)
+            DistPkgList.append(DistPkg)
+
+        #
+        # check dependency
+        #
+        Dep = DependencyRules(DataBase)
+        Result = True
+        DpObj = None
+        try:
+            Result, DpObj = Dep.CheckTestInstallPdDepexSatisfied(DistPkgList)
+        except:
+            Result = False
+        
+        if Result:
+            Logger.Quiet(ST.MSG_TEST_INSTALL_PASS)
+        else:
+            Logger.Quiet(ST.MSG_TEST_INSTALL_FAIL)
+
+    except TE.FatalError, XExcept:
+        ReturnCode = XExcept.args[0]
+        if Logger.GetLevel() <= Logger.DEBUG_9:
+            Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), 
+ platform) + format_exc())
+
+    except Exception, x:
+        ReturnCode = TE.CODE_ERROR
+        Logger.Error(
+                    "\nTestInstallPkg",
+                    TE.CODE_ERROR,
+                    ST.ERR_UNKNOWN_FATAL_INSTALL_ERR % Options.DistFiles,
+                    ExtraData=ST.MSG_SEARCH_FOR_HELP,
+                    RaiseError=False
+                    )
+        Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + 
+ format_exc())
+
+    finally:
+        Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_STARTED)
+        if DistFile:
+            DistFile.Close()
+        if ContentZipFile:
+            ContentZipFile.Close()
+        if GlobalData.gUNPACK_DIR:
+            shutil.rmtree(GlobalData.gUNPACK_DIR)
+            GlobalData.gUNPACK_DIR = None
+        Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_DONE)
+    if ReturnCode == 0:
+        Logger.Quiet(ST.MSG_FINISH)
+    return ReturnCode
+
diff --git a/BaseTools/Source/Python/UPT/UPT.py b/BaseTools/Source/Python/UPT/UPT.py
index 59c4a88..8dd949a 100644
--- a/BaseTools/Source/Python/UPT/UPT.py
+++ b/BaseTools/Source/Python/UPT/UPT.py
@@ -46,6 +46,7 @@ import InstallPkg
 import RmPkg
 import InventoryWs
 import ReplacePkg
+import TestInstall
 from Library.Misc import GetWorkspace
 from Library import GlobalData
 from Core.IpiDb import IpiDatabase
@@ -69,6 +70,9 @@ def CheckConflictOption(Opt):
         Logger.Error("UPT", OPTION_CONFLICT, ExtraData=ST.ERR_I_R_EXCLUSIVE)
     elif Opt.PackFileToCreate and  Opt.PackFileToRemove:
         Logger.Error("UPT", OPTION_CONFLICT, ExtraData=ST.ERR_C_R_EXCLUSIVE)
+    elif Opt.TestDistFiles and (Opt.PackFileToCreate or Opt.PackFileToInstall \
+                                or Opt.PackFileToRemove or Opt.PackFileToReplace):
+        Logger.Error("UPT", OPTION_CONFLICT, 
+ ExtraData=ST.ERR_C_R_EXCLUSIVE)
 
     if Opt.CustomPath and Opt.UseGuidedPkgPath:
         Logger.Warn("UPT", ST.WARN_CUSTOMPATH_OVERRIDE_USEGUIDEDPATH)
@@ -146,6 +150,9 @@ def Main():
 
     Parser.add_option("--use-guided-paths", action="store_true", dest="Use_Guided_Paths", help=ST.HLP_USE_GUIDED_PATHS)
 
+    Parser.add_option("-j", "--test-install", action="append", type="string",
+                      dest="Test_Install_Distribution_Package_Files", 
+ help=ST.HLP_TEST_INSTALL)
+
     Opt = Parser.parse_args()[0]
 
     Var2Var = [
@@ -159,6 +166,7 @@ def Main():
         ("PackFileToReplace", Opt.Replace_Distribution_Package_File),
         ("PackFileToBeReplaced", Opt.Original_Distribution_Package_File),
         ("UseGuidedPkgPath", Opt.Use_Guided_Paths),
+        ("TestDistFiles", Opt.Test_Install_Distribution_Package_Files)
     ]
 
     for Var in Var2Var:
@@ -265,6 +273,14 @@ def Main():
             Opt.PackFileToReplace = AbsPath
             RunModule = ReplacePkg.Main
 
+        elif Opt.Test_Install_Distribution_Package_Files:
+            for Dist in Opt.Test_Install_Distribution_Package_Files:
+                if not Dist.endswith('.dist'):
+                    Logger.Error("TestInstall", FILE_TYPE_MISMATCH, 
+ ExtraData=ST.ERR_DIST_EXT_ERROR % Dist)
+
+            setattr(Opt, 'DistFiles', Opt.Test_Install_Distribution_Package_Files)
+            RunModule = TestInstall.Main
+
         else:
             Parser.print_usage()
             return OPTION_MISSING
--
2.7.2.windows.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-08-02  4:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-29  7:58 [patch] BaseTool/UPT: Add Test Install hesschen
2016-08-02  4:04 ` Zhu, Yonghong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox