]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/PackagingTool/DependencyRules.py
Sync EDKII BaseTools to BaseTools project r2065.
[mirror_edk2.git] / BaseTools / Source / Python / PackagingTool / DependencyRules.py
CommitLineData
30fdf114
LG
1## @file\r
2# This file is for installed package information database operations\r
3#\r
08dd311f 4# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
40d841f6 5# This program and the accompanying materials\r
30fdf114
LG
6# are licensed and made available under the terms and conditions of the BSD License\r
7# which accompanies this distribution. The full text of the license may be found at\r
8# http://opensource.org/licenses/bsd-license.php\r
9#\r
10# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12#\r
13\r
14##\r
15# Import Modules\r
16#\r
17import sqlite3\r
18import os\r
19\r
20import Common.EdkLogger as EdkLogger\r
21import IpiDb\r
22\r
23(DEPEX_CHECK_SUCCESS, DEPEX_CHECK_MODULE_NOT_FOUND, \\r
24DEPEX_CHECK_PACKAGE_NOT_FOUND, DEPEX_CHECK_DP_NOT_FOUND) = (0, 1, 2, 3)\r
25\r
26## IpiDb\r
27#\r
08dd311f 28# This class represents the installed package information database\r
30fdf114
LG
29# Add/Remove/Get installed distribution package information here.\r
30# \r
31# \r
32# @param object: Inherited from object class\r
33# @param DbPath: A string for the path of the database\r
34#\r
35# @var Conn: Connection of the database\r
36# @var Cur: Cursor of the connection\r
37#\r
38class DependencyRules(object):\r
39 def __init__(self, Db):\r
40 self.IpiDb = Db\r
41 \r
42 ## Check whether a module exists in current workspace.\r
43 #\r
44 # @param Guid: \r
45 # @param Version:\r
46 #\r
47 def CheckModuleExists(self, Guid, Version, ReturnCode = DEPEX_CHECK_SUCCESS):\r
48 EdkLogger.verbose("\nCheck module exists in workspace started ...")\r
49 ModuleList = []\r
50 ModuleList = self.IpiDb.GetModInPackage(Guid, Version)\r
51 ModuleList.extend(self.IpiDb.GetStandaloneModule(Guid, Version))\r
52 EdkLogger.verbose("Check module exists in workspace ... DONE!")\r
53 if len(ModuleList) > 0:\r
54 return True\r
55 else:\r
56 ReturnCode = DEPEX_CHECK_MODULE_NOT_FOUND\r
57 return False\r
58 \r
59\r
08dd311f 60 ## Check whether a module depex satisfied by current workspace.\r
30fdf114
LG
61 #\r
62 # @param ModuleObj: \r
63 # @param DpObj:\r
64 #\r
65 def CheckModuleDepexSatisfied(self, ModuleObj, DpObj = None, ReturnCode = DEPEX_CHECK_SUCCESS):\r
66 EdkLogger.verbose("\nCheck module depex met by workspace started ...")\r
67 for Dep in ModuleObj.PackageDependencies:\r
68 Exist = self.CheckPackageExists(Dep.PackageGuid, Dep.PackageVersion, ReturnCode)\r
69 if not Exist:\r
70 if DpObj == None:\r
71 ReturnCode = DEPEX_CHECK_PACKAGE_NOT_FOUND\r
72 return False\r
73 for GuidVerPair in DpObj.PackageSurfaceArea.keys():\r
74 if Dep.PackageGuid == GuidVerPair[0]:\r
75 if Dep.PackageVersion == None or len(Dep.PackageVersion) == 0:\r
76 break\r
77 if Dep.PackageVersion == GuidVerPair[1]:\r
78 break\r
79 else:\r
80 ReturnCode = DEPEX_CHECK_PACKAGE_NOT_FOUND\r
81 return False\r
82 else:\r
83 ReturnCode = DEPEX_CHECK_PACKAGE_NOT_FOUND\r
84 return False\r
85 return True\r
86 \r
87 EdkLogger.verbose("Check module depex met by workspace ... DONE!")\r
88 \r
89 ## Check whether a package exists in current workspace.\r
90 #\r
91 # @param Guid: \r
92 # @param Version:\r
93 #\r
94 def CheckPackageExists(self, Guid, Version, ReturnCode = DEPEX_CHECK_SUCCESS):\r
95 EdkLogger.verbose("\nCheck package exists in workspace started ...")\r
96 PkgList = []\r
97 PkgList = self.IpiDb.GetPackage(Guid, Version)\r
98 if len(PkgList) > 0:\r
99 return True\r
100 else:\r
101 ReturnCode = DEPEX_CHECK_PACKAGE_NOT_FOUND\r
102 return False\r
103 \r
104 EdkLogger.verbose("Check package exists in workspace ... DONE!")\r
105 \r
08dd311f 106 ## Check whether a package depex satisfied by current workspace.\r
30fdf114
LG
107 #\r
108 # @param ModuleObj: \r
109 # @param DpObj:\r
110 #\r
111 def CheckPackageDepexSatisfied(self, PkgObj, DpObj = None, ReturnCode = DEPEX_CHECK_SUCCESS):\r
112 \r
113 for ModKey in PkgObj.Modules.keys():\r
114 ModObj = PkgObj.Modules[ModKey]\r
115 if self.CheckModuleDepexSatisfied(ModObj, DpObj, ReturnCode):\r
116 continue\r
117 else:\r
118 return False\r
119 return True\r
120 \r
121 ## Check whether a DP exists in current workspace.\r
122 #\r
123 # @param Guid: \r
124 # @param Version:\r
125 #\r
126 def CheckDpExists(self, Guid, Version, ReturnCode = DEPEX_CHECK_SUCCESS):\r
127 EdkLogger.verbose("\nCheck DP exists in workspace started ...")\r
128 DpList = []\r
129 DpList = self.IpiDb.GetDp(Guid, Version)\r
130 if len(DpList) > 0:\r
131 return True\r
132 else:\r
133 ReturnCode = DEPEX_CHECK_DP_NOT_FOUND\r
134 return False\r
135 \r
136 EdkLogger.verbose("Check DP exists in workspace ... DONE!")\r
137 \r
08dd311f 138 ## Check whether a DP depex satisfied by current workspace.\r
30fdf114
LG
139 #\r
140 # @param ModuleObj: \r
141 # @param DpObj:\r
142 #\r
143 def CheckDpDepexSatisfied(self, DpObj, ReturnCode = DEPEX_CHECK_SUCCESS):\r
144 \r
145 for PkgKey in DpObj.PackageSurfaceArea.keys():\r
146 PkgObj = DpObj.PackageSurfaceArea[PkgKey]\r
147 if self.CheckPackageDepexSatisfied(PkgObj, DpObj, ReturnCode):\r
148 continue\r
149 else:\r
150 return False\r
151 \r
152 for ModKey in DpObj.ModuleSurfaceArea.keys():\r
153 ModObj = PkgObj.ModuleSurfaceArea[ModKey]\r
154 if self.CheckModuleDepexSatisfied(ModObj, DpObj, ReturnCode):\r
155 continue\r
156 else:\r
157 return False\r
158 \r
159 return True\r
160 \r
08dd311f 161 ## Check whether a DP depex satisfied by current workspace.\r
30fdf114
LG
162 #\r
163 # @param ModuleObj: \r
164 # @param DpObj:\r
165 #\r
166 def CheckDpDepexForRemove(self, DpGuid, DpVersion, ReturnCode = DEPEX_CHECK_SUCCESS):\r
167 \r
168 # Get mod list that is dependent on pkg installed from this DP.\r
169 ModList = self.IpiDb.GetDpDependentModuleList(DpGuid, DpVersion)\r
170 \r
171 if len(ModList) > 0:\r
172 return False\r
173 \r
174 return True\r
175##\r
176#\r
177# This acts like the main() function for the script, unless it is 'import'ed into another\r
178# script.\r
179#\r
180if __name__ == '__main__':\r
181 EdkLogger.Initialize()\r
182 EdkLogger.SetLevel(EdkLogger.DEBUG_0)\r
183\r
184\r
185