2 # This file is for installed package information database operations
4 # Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 import Common
.EdkLogger
as EdkLogger
23 (DEPEX_CHECK_SUCCESS
, DEPEX_CHECK_MODULE_NOT_FOUND
, \
24 DEPEX_CHECK_PACKAGE_NOT_FOUND
, DEPEX_CHECK_DP_NOT_FOUND
) = (0, 1, 2, 3)
28 # This class represents the installed package information database
29 # Add/Remove/Get installed distribution package information here.
32 # @param object: Inherited from object class
33 # @param DbPath: A string for the path of the database
35 # @var Conn: Connection of the database
36 # @var Cur: Cursor of the connection
38 class DependencyRules(object):
39 def __init__(self
, Db
):
42 ## Check whether a module exists in current workspace.
47 def CheckModuleExists(self
, Guid
, Version
, ReturnCode
= DEPEX_CHECK_SUCCESS
):
48 EdkLogger
.verbose("\nCheck module exists in workspace started ...")
50 ModuleList
= self
.IpiDb
.GetModInPackage(Guid
, Version
)
51 ModuleList
.extend(self
.IpiDb
.GetStandaloneModule(Guid
, Version
))
52 EdkLogger
.verbose("Check module exists in workspace ... DONE!")
53 if len(ModuleList
) > 0:
56 ReturnCode
= DEPEX_CHECK_MODULE_NOT_FOUND
60 ## Check whether a module depex satisfied by current workspace.
65 def CheckModuleDepexSatisfied(self
, ModuleObj
, DpObj
= None, ReturnCode
= DEPEX_CHECK_SUCCESS
):
66 EdkLogger
.verbose("\nCheck module depex met by workspace started ...")
67 for Dep
in ModuleObj
.PackageDependencies
:
68 Exist
= self
.CheckPackageExists(Dep
.PackageGuid
, Dep
.PackageVersion
, ReturnCode
)
71 ReturnCode
= DEPEX_CHECK_PACKAGE_NOT_FOUND
73 for GuidVerPair
in DpObj
.PackageSurfaceArea
.keys():
74 if Dep
.PackageGuid
== GuidVerPair
[0]:
75 if Dep
.PackageVersion
== None or len(Dep
.PackageVersion
) == 0:
77 if Dep
.PackageVersion
== GuidVerPair
[1]:
80 ReturnCode
= DEPEX_CHECK_PACKAGE_NOT_FOUND
83 ReturnCode
= DEPEX_CHECK_PACKAGE_NOT_FOUND
87 EdkLogger
.verbose("Check module depex met by workspace ... DONE!")
89 ## Check whether a package exists in current workspace.
94 def CheckPackageExists(self
, Guid
, Version
, ReturnCode
= DEPEX_CHECK_SUCCESS
):
95 EdkLogger
.verbose("\nCheck package exists in workspace started ...")
97 PkgList
= self
.IpiDb
.GetPackage(Guid
, Version
)
101 ReturnCode
= DEPEX_CHECK_PACKAGE_NOT_FOUND
104 EdkLogger
.verbose("Check package exists in workspace ... DONE!")
106 ## Check whether a package depex satisfied by current workspace.
111 def CheckPackageDepexSatisfied(self
, PkgObj
, DpObj
= None, ReturnCode
= DEPEX_CHECK_SUCCESS
):
113 for ModKey
in PkgObj
.Modules
.keys():
114 ModObj
= PkgObj
.Modules
[ModKey
]
115 if self
.CheckModuleDepexSatisfied(ModObj
, DpObj
, ReturnCode
):
121 ## Check whether a DP exists in current workspace.
126 def CheckDpExists(self
, Guid
, Version
, ReturnCode
= DEPEX_CHECK_SUCCESS
):
127 EdkLogger
.verbose("\nCheck DP exists in workspace started ...")
129 DpList
= self
.IpiDb
.GetDp(Guid
, Version
)
133 ReturnCode
= DEPEX_CHECK_DP_NOT_FOUND
136 EdkLogger
.verbose("Check DP exists in workspace ... DONE!")
138 ## Check whether a DP depex satisfied by current workspace.
143 def CheckDpDepexSatisfied(self
, DpObj
, ReturnCode
= DEPEX_CHECK_SUCCESS
):
145 for PkgKey
in DpObj
.PackageSurfaceArea
.keys():
146 PkgObj
= DpObj
.PackageSurfaceArea
[PkgKey
]
147 if self
.CheckPackageDepexSatisfied(PkgObj
, DpObj
, ReturnCode
):
152 for ModKey
in DpObj
.ModuleSurfaceArea
.keys():
153 ModObj
= PkgObj
.ModuleSurfaceArea
[ModKey
]
154 if self
.CheckModuleDepexSatisfied(ModObj
, DpObj
, ReturnCode
):
161 ## Check whether a DP depex satisfied by current workspace.
166 def CheckDpDepexForRemove(self
, DpGuid
, DpVersion
, ReturnCode
= DEPEX_CHECK_SUCCESS
):
168 # Get mod list that is dependent on pkg installed from this DP.
169 ModList
= self
.IpiDb
.GetDpDependentModuleList(DpGuid
, DpVersion
)
177 # This acts like the main() function for the script, unless it is 'import'ed into another
180 if __name__
== '__main__':
181 EdkLogger
.Initialize()
182 EdkLogger
.SetLevel(EdkLogger
.DEBUG_0
)