1# # @file
2# Test Install distribution package
3#
4# Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>
5#
6# SPDX-License-Identifier: BSD-2-Clause-Patent
7#
8"""
9Test Install multiple distribution package
10"""
11# #
12# Import Modules
13#
14from Library import GlobalData
15import Logger.Log as Logger
16from Logger import StringTable as ST
17import Logger.ToolError as TE
18from Core.DependencyRules import DependencyRules
19from InstallPkg import UnZipDp
20
21import shutil
22from traceback import format_exc
23from platform import python_version
24from sys import platform
25
26# # Tool entrance method
27#
28# This method mainly dispatch specific methods per the command line options.
29# If no error found, return zero value so the caller of this tool can know
30# if it's executed successfully or not.
31#
32# @param  Options: command Options
33#
34def Main(Options=None):
35    ContentZipFile, DistFile = None, None
36    ReturnCode = 0
37
38    try:
39        DataBase = GlobalData.gDB
40        WorkspaceDir = GlobalData.gWORKSPACE
41        if not Options.DistFiles:
42            Logger.Error("TestInstallPkg", TE.OPTION_MISSING, ExtraData=ST.ERR_SPECIFY_PACKAGE)
43
44        DistPkgList = []
45        for DistFile in Options.DistFiles:
46            DistPkg, ContentZipFile, __, DistFile = UnZipDp(WorkspaceDir, DistFile)
47            DistPkgList.append(DistPkg)
48
49        #
50        # check dependency
51        #
52        Dep = DependencyRules(DataBase)
53        Result = True
54        DpObj = None
55        try:
56            Result, DpObj = Dep.CheckTestInstallPdDepexSatisfied(DistPkgList)
57        except:
58            Result = False
59
60        if Result:
61            Logger.Quiet(ST.MSG_TEST_INSTALL_PASS)
62        else:
63            Logger.Quiet(ST.MSG_TEST_INSTALL_FAIL)
64
65    except TE.FatalError as XExcept:
66        ReturnCode = XExcept.args[0]
67        if Logger.GetLevel() <= Logger.DEBUG_9:
68            Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())
69
70    except Exception as x:
71        ReturnCode = TE.CODE_ERROR
72        Logger.Error(
73                    "\nTestInstallPkg",
74                    TE.CODE_ERROR,
75                    ST.ERR_UNKNOWN_FATAL_INSTALL_ERR % Options.DistFiles,
76                    ExtraData=ST.MSG_SEARCH_FOR_HELP % ST.MSG_EDKII_MAIL_ADDR,
77                    RaiseError=False
78                    )
79        Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())
80
81    finally:
82        Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_STARTED)
83        if DistFile:
84            DistFile.Close()
85        if ContentZipFile:
86            ContentZipFile.Close()
87        for TempDir in GlobalData.gUNPACK_DIR:
88            shutil.rmtree(TempDir)
89        GlobalData.gUNPACK_DIR = []
90        Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_DONE)
91    if ReturnCode == 0:
92        Logger.Quiet(ST.MSG_FINISH)
93    return ReturnCode
94
95