]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/UPT/InventoryWs.py
BaseTools: Use absolute import in UPT
[mirror_edk2.git] / BaseTools / Source / Python / UPT / InventoryWs.py
CommitLineData
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
f7496d71
LG
6# This program and the accompanying materials are licensed and made available\r
7# under the terms and conditions of the BSD License which accompanies this\r
8# distribution. The full text of the license may be found at\r
421ccda3
HC
9# http://opensource.org/licenses/bsd-license.php\r
10#\r
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13#\r
14"""\r
15Inventory workspace's distribution package information.\r
16"""\r
17##\r
18# Import Modules\r
19#\r
20from sys import platform\r
21from traceback import format_exc\r
22from platform import python_version\r
23\r
24from Logger import StringTable as ST\r
25from Logger.ToolError import FatalError\r
26from Logger.ToolError import ABORT_ERROR\r
27from Logger.ToolError import CODE_ERROR\r
28import Logger.Log as Logger\r
29\r
30from Library import GlobalData\r
31\r
32## InventoryDistInstalled\r
33#\r
34# This method retrieves the installed distribution information from the internal UPT database\r
35#\r
36# @param DataBase: the UPT database\r
37#\r
38def InventoryDistInstalled(DataBase):\r
39 DistInstalled = DataBase.InventoryDistInstalled()\r
f7496d71 40\r
421ccda3
HC
41 #\r
42 # find the max length for each item\r
43 #\r
44 DpNameStr = "DpName"\r
45 DpGuidStr = "DpGuid"\r
46 DpVerStr = "DpVer"\r
47 DpOriginalNameStr = "DpOriginalName"\r
48 MaxGuidlen = len(DpGuidStr)\r
49 MaxVerlen = len(DpVerStr)\r
f7496d71 50 MaxDpAliasFileNameLen = len(DpNameStr)\r
421ccda3 51 MaxDpOrigFileNamelen = len(DpOriginalNameStr)\r
f7496d71 52\r
421ccda3
HC
53 for (DpGuid, DpVersion, DpOriginalName, DpAliasFileName) in DistInstalled:\r
54 MaxGuidlen = max(MaxGuidlen, len(DpGuid))\r
55 MaxVerlen = max(MaxVerlen, len(DpVersion))\r
56 MaxDpAliasFileNameLen = max(MaxDpAliasFileNameLen, len(DpAliasFileName))\r
57 MaxDpOrigFileNamelen = max(MaxDpOrigFileNamelen, len(DpOriginalName))\r
58\r
59 OutMsgFmt = "%-*s\t%-*s\t%-*s\t%-s"\r
f7496d71
LG
60 OutMsg = OutMsgFmt % (MaxDpAliasFileNameLen,\r
61 DpNameStr,\r
62 MaxGuidlen,\r
63 DpGuidStr,\r
64 MaxVerlen,\r
65 DpVerStr,\r
421ccda3
HC
66 DpOriginalNameStr)\r
67 Logger.Info(OutMsg)\r
f7496d71 68\r
421ccda3 69 for (DpGuid, DpVersion, DpFileName, DpAliasFileName) in DistInstalled:\r
f7496d71
LG
70 OutMsg = OutMsgFmt % (MaxDpAliasFileNameLen,\r
71 DpAliasFileName,\r
72 MaxGuidlen,\r
73 DpGuid,\r
74 MaxVerlen,\r
75 DpVersion,\r
421ccda3
HC
76 DpFileName)\r
77 Logger.Info(OutMsg)\r
78\r
79## Tool entrance method\r
80#\r
81# This method mainly dispatch specific methods per the command line options.\r
82# If no error found, return zero value so the caller of this tool can know\r
83# if it's executed successfully or not.\r
84#\r
85# @param Options: command Options\r
86#\r
87def Main(Options = None):\r
88 if Options:\r
89 pass\r
90\r
91 try:\r
92 DataBase = GlobalData.gDB\r
f7496d71
LG
93 InventoryDistInstalled(DataBase)\r
94 ReturnCode = 0\r
5b0671c1 95 except FatalError as XExcept:\r
421ccda3
HC
96 ReturnCode = XExcept.args[0]\r
97 if Logger.GetLevel() <= Logger.DEBUG_9:\r
98 Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())\r
f7496d71 99 except KeyboardInterrupt:\r
421ccda3
HC
100 ReturnCode = ABORT_ERROR\r
101 if Logger.GetLevel() <= Logger.DEBUG_9:\r
102 Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())\r
103 except:\r
104 ReturnCode = CODE_ERROR\r
105 Logger.Error("\nInventoryWs",\r
106 CODE_ERROR,\r
107 ST.ERR_UNKNOWN_FATAL_INVENTORYWS_ERR,\r
108 ExtraData=ST.MSG_SEARCH_FOR_HELP,\r
109 RaiseError=False\r
110 )\r
111 Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(),\r
112 platform) + format_exc())\r
113\r
114 if ReturnCode == 0:\r
115 Logger.Quiet(ST.MSG_FINISH)\r
f7496d71
LG
116\r
117 return ReturnCode\r