]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/PackagingTool/DependencyRules.py
Check In tool source code based on Build tool project revision r1655.
[mirror_edk2.git] / BaseTools / Source / Python / PackagingTool / DependencyRules.py
1 ## @file
2 # This file is for installed package information database operations
3 #
4 # Copyright (c) 2007 ~ 2008, Intel Corporation
5 # All rights reserved. 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
9 #
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.
12 #
13
14 ##
15 # Import Modules
16 #
17 import sqlite3
18 import os
19
20 import Common.EdkLogger as EdkLogger
21 import IpiDb
22
23 (DEPEX_CHECK_SUCCESS, DEPEX_CHECK_MODULE_NOT_FOUND, \
24 DEPEX_CHECK_PACKAGE_NOT_FOUND, DEPEX_CHECK_DP_NOT_FOUND) = (0, 1, 2, 3)
25
26 ## IpiDb
27 #
28 # This class represents the installed package information databse
29 # Add/Remove/Get installed distribution package information here.
30 #
31 #
32 # @param object: Inherited from object class
33 # @param DbPath: A string for the path of the database
34 #
35 # @var Conn: Connection of the database
36 # @var Cur: Cursor of the connection
37 #
38 class DependencyRules(object):
39 def __init__(self, Db):
40 self.IpiDb = Db
41
42 ## Check whether a module exists in current workspace.
43 #
44 # @param Guid:
45 # @param Version:
46 #
47 def CheckModuleExists(self, Guid, Version, ReturnCode = DEPEX_CHECK_SUCCESS):
48 EdkLogger.verbose("\nCheck module exists in workspace started ...")
49 ModuleList = []
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:
54 return True
55 else:
56 ReturnCode = DEPEX_CHECK_MODULE_NOT_FOUND
57 return False
58
59
60 ## Check whether a module depex satified by current workspace.
61 #
62 # @param ModuleObj:
63 # @param DpObj:
64 #
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)
69 if not Exist:
70 if DpObj == None:
71 ReturnCode = DEPEX_CHECK_PACKAGE_NOT_FOUND
72 return False
73 for GuidVerPair in DpObj.PackageSurfaceArea.keys():
74 if Dep.PackageGuid == GuidVerPair[0]:
75 if Dep.PackageVersion == None or len(Dep.PackageVersion) == 0:
76 break
77 if Dep.PackageVersion == GuidVerPair[1]:
78 break
79 else:
80 ReturnCode = DEPEX_CHECK_PACKAGE_NOT_FOUND
81 return False
82 else:
83 ReturnCode = DEPEX_CHECK_PACKAGE_NOT_FOUND
84 return False
85 return True
86
87 EdkLogger.verbose("Check module depex met by workspace ... DONE!")
88
89 ## Check whether a package exists in current workspace.
90 #
91 # @param Guid:
92 # @param Version:
93 #
94 def CheckPackageExists(self, Guid, Version, ReturnCode = DEPEX_CHECK_SUCCESS):
95 EdkLogger.verbose("\nCheck package exists in workspace started ...")
96 PkgList = []
97 PkgList = self.IpiDb.GetPackage(Guid, Version)
98 if len(PkgList) > 0:
99 return True
100 else:
101 ReturnCode = DEPEX_CHECK_PACKAGE_NOT_FOUND
102 return False
103
104 EdkLogger.verbose("Check package exists in workspace ... DONE!")
105
106 ## Check whether a package depex satified by current workspace.
107 #
108 # @param ModuleObj:
109 # @param DpObj:
110 #
111 def CheckPackageDepexSatisfied(self, PkgObj, DpObj = None, ReturnCode = DEPEX_CHECK_SUCCESS):
112
113 for ModKey in PkgObj.Modules.keys():
114 ModObj = PkgObj.Modules[ModKey]
115 if self.CheckModuleDepexSatisfied(ModObj, DpObj, ReturnCode):
116 continue
117 else:
118 return False
119 return True
120
121 ## Check whether a DP exists in current workspace.
122 #
123 # @param Guid:
124 # @param Version:
125 #
126 def CheckDpExists(self, Guid, Version, ReturnCode = DEPEX_CHECK_SUCCESS):
127 EdkLogger.verbose("\nCheck DP exists in workspace started ...")
128 DpList = []
129 DpList = self.IpiDb.GetDp(Guid, Version)
130 if len(DpList) > 0:
131 return True
132 else:
133 ReturnCode = DEPEX_CHECK_DP_NOT_FOUND
134 return False
135
136 EdkLogger.verbose("Check DP exists in workspace ... DONE!")
137
138 ## Check whether a DP depex satified by current workspace.
139 #
140 # @param ModuleObj:
141 # @param DpObj:
142 #
143 def CheckDpDepexSatisfied(self, DpObj, ReturnCode = DEPEX_CHECK_SUCCESS):
144
145 for PkgKey in DpObj.PackageSurfaceArea.keys():
146 PkgObj = DpObj.PackageSurfaceArea[PkgKey]
147 if self.CheckPackageDepexSatisfied(PkgObj, DpObj, ReturnCode):
148 continue
149 else:
150 return False
151
152 for ModKey in DpObj.ModuleSurfaceArea.keys():
153 ModObj = PkgObj.ModuleSurfaceArea[ModKey]
154 if self.CheckModuleDepexSatisfied(ModObj, DpObj, ReturnCode):
155 continue
156 else:
157 return False
158
159 return True
160
161 ## Check whether a DP depex satified by current workspace.
162 #
163 # @param ModuleObj:
164 # @param DpObj:
165 #
166 def CheckDpDepexForRemove(self, DpGuid, DpVersion, ReturnCode = DEPEX_CHECK_SUCCESS):
167
168 # Get mod list that is dependent on pkg installed from this DP.
169 ModList = self.IpiDb.GetDpDependentModuleList(DpGuid, DpVersion)
170
171 if len(ModList) > 0:
172 return False
173
174 return True
175 ##
176 #
177 # This acts like the main() function for the script, unless it is 'import'ed into another
178 # script.
179 #
180 if __name__ == '__main__':
181 EdkLogger.Initialize()
182 EdkLogger.SetLevel(EdkLogger.DEBUG_0)
183
184
185