2 # Inventory workspace's distribution package information.
4 # Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
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
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.
15 Inventory workspace's distribution package information.
20 from sys
import platform
21 from traceback
import format_exc
22 from platform
import python_version
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
30 from Library
import GlobalData
32 ## InventoryDistInstalled
34 # This method retrieves the installed distribution information from the internal UPT database
36 # @param DataBase: the UPT database
38 def InventoryDistInstalled(DataBase
):
39 DistInstalled
= DataBase
.InventoryDistInstalled()
42 # find the max length for each item
47 DpOriginalNameStr
= "DpOriginalName"
48 MaxGuidlen
= len(DpGuidStr
)
49 MaxVerlen
= len(DpVerStr
)
50 MaxDpAliasFileNameLen
= len(DpNameStr
)
51 MaxDpOrigFileNamelen
= len(DpOriginalNameStr
)
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
))
59 OutMsgFmt
= "%-*s\t%-*s\t%-*s\t%-s"
60 OutMsg
= OutMsgFmt
% (MaxDpAliasFileNameLen
,
69 for (DpGuid
, DpVersion
, DpFileName
, DpAliasFileName
) in DistInstalled
:
70 OutMsg
= OutMsgFmt
% (MaxDpAliasFileNameLen
,
79 ## Tool entrance method
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.
85 # @param Options: command Options
87 def Main(Options
= None):
92 DataBase
= GlobalData
.gDB
93 InventoryDistInstalled(DataBase
)
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())
104 ReturnCode
= CODE_ERROR
105 Logger
.Error("\nInventoryWs",
107 ST
.ERR_UNKNOWN_FATAL_INVENTORYWS_ERR
,
108 ExtraData
=ST
.MSG_SEARCH_FOR_HELP
,
111 Logger
.Quiet(ST
.MSG_PYTHON_ON
% (python_version(),
112 platform
) + format_exc())
115 Logger
.Quiet(ST
.MSG_FINISH
)