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