]>
Commit | Line | Data |
---|---|---|
421ccda3 HC |
1 | ## @file\r |
2 | # Inventory workspace's distribution package information.\r | |
3 | #\r | |
f7496d71 | 4 | # Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>\r |
421ccda3 | 5 | #\r |
2e351cbe | 6 | # SPDX-License-Identifier: BSD-2-Clause-Patent\r |
421ccda3 HC |
7 | #\r |
8 | """\r | |
9 | Inventory workspace's distribution package information.\r | |
10 | """\r | |
11 | ##\r | |
12 | # Import Modules\r | |
13 | #\r | |
14 | from sys import platform\r | |
15 | from traceback import format_exc\r | |
16 | from platform import python_version\r | |
17 | \r | |
18 | from Logger import StringTable as ST\r | |
19 | from Logger.ToolError import FatalError\r | |
20 | from Logger.ToolError import ABORT_ERROR\r | |
21 | from Logger.ToolError import CODE_ERROR\r | |
22 | import Logger.Log as Logger\r | |
23 | \r | |
24 | from Library import GlobalData\r | |
25 | \r | |
26 | ## InventoryDistInstalled\r | |
27 | #\r | |
28 | # This method retrieves the installed distribution information from the internal UPT database\r | |
29 | #\r | |
30 | # @param DataBase: the UPT database\r | |
31 | #\r | |
32 | def InventoryDistInstalled(DataBase):\r | |
33 | DistInstalled = DataBase.InventoryDistInstalled()\r | |
f7496d71 | 34 | \r |
421ccda3 HC |
35 | #\r |
36 | # find the max length for each item\r | |
37 | #\r | |
38 | DpNameStr = "DpName"\r | |
39 | DpGuidStr = "DpGuid"\r | |
40 | DpVerStr = "DpVer"\r | |
41 | DpOriginalNameStr = "DpOriginalName"\r | |
42 | MaxGuidlen = len(DpGuidStr)\r | |
43 | MaxVerlen = len(DpVerStr)\r | |
f7496d71 | 44 | MaxDpAliasFileNameLen = len(DpNameStr)\r |
421ccda3 | 45 | MaxDpOrigFileNamelen = len(DpOriginalNameStr)\r |
f7496d71 | 46 | \r |
421ccda3 HC |
47 | for (DpGuid, DpVersion, DpOriginalName, DpAliasFileName) in DistInstalled:\r |
48 | MaxGuidlen = max(MaxGuidlen, len(DpGuid))\r | |
49 | MaxVerlen = max(MaxVerlen, len(DpVersion))\r | |
50 | MaxDpAliasFileNameLen = max(MaxDpAliasFileNameLen, len(DpAliasFileName))\r | |
51 | MaxDpOrigFileNamelen = max(MaxDpOrigFileNamelen, len(DpOriginalName))\r | |
52 | \r | |
53 | OutMsgFmt = "%-*s\t%-*s\t%-*s\t%-s"\r | |
f7496d71 LG |
54 | OutMsg = OutMsgFmt % (MaxDpAliasFileNameLen,\r |
55 | DpNameStr,\r | |
56 | MaxGuidlen,\r | |
57 | DpGuidStr,\r | |
58 | MaxVerlen,\r | |
59 | DpVerStr,\r | |
421ccda3 HC |
60 | DpOriginalNameStr)\r |
61 | Logger.Info(OutMsg)\r | |
f7496d71 | 62 | \r |
421ccda3 | 63 | for (DpGuid, DpVersion, DpFileName, DpAliasFileName) in DistInstalled:\r |
f7496d71 LG |
64 | OutMsg = OutMsgFmt % (MaxDpAliasFileNameLen,\r |
65 | DpAliasFileName,\r | |
66 | MaxGuidlen,\r | |
67 | DpGuid,\r | |
68 | MaxVerlen,\r | |
69 | DpVersion,\r | |
421ccda3 HC |
70 | DpFileName)\r |
71 | Logger.Info(OutMsg)\r | |
72 | \r | |
73 | ## Tool entrance method\r | |
74 | #\r | |
75 | # This method mainly dispatch specific methods per the command line options.\r | |
76 | # If no error found, return zero value so the caller of this tool can know\r | |
77 | # if it's executed successfully or not.\r | |
78 | #\r | |
79 | # @param Options: command Options\r | |
80 | #\r | |
81 | def Main(Options = None):\r | |
82 | if Options:\r | |
83 | pass\r | |
84 | \r | |
85 | try:\r | |
86 | DataBase = GlobalData.gDB\r | |
f7496d71 LG |
87 | InventoryDistInstalled(DataBase)\r |
88 | ReturnCode = 0\r | |
5b0671c1 | 89 | except FatalError as XExcept:\r |
421ccda3 HC |
90 | ReturnCode = XExcept.args[0]\r |
91 | if Logger.GetLevel() <= Logger.DEBUG_9:\r | |
92 | Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())\r | |
f7496d71 | 93 | except KeyboardInterrupt:\r |
421ccda3 HC |
94 | ReturnCode = ABORT_ERROR\r |
95 | if Logger.GetLevel() <= Logger.DEBUG_9:\r | |
96 | Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())\r | |
97 | except:\r | |
98 | ReturnCode = CODE_ERROR\r | |
99 | Logger.Error("\nInventoryWs",\r | |
100 | CODE_ERROR,\r | |
101 | ST.ERR_UNKNOWN_FATAL_INVENTORYWS_ERR,\r | |
c1387446 | 102 | ExtraData=ST.MSG_SEARCH_FOR_HELP % ST.MSG_EDKII_MAIL_ADDR,\r |
421ccda3 HC |
103 | RaiseError=False\r |
104 | )\r | |
105 | Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(),\r | |
106 | platform) + format_exc())\r | |
107 | \r | |
108 | if ReturnCode == 0:\r | |
109 | Logger.Quiet(ST.MSG_FINISH)\r | |
f7496d71 LG |
110 | \r |
111 | return ReturnCode\r |