]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | ## @file\r |
2 | # This file is for installed package information database operations\r | |
3 | #\r | |
40d841f6 LG |
4 | # Copyright (c) 2007 - 2008, Intel Corporation. All rights reserved.<BR>\r |
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 | |
17 | import sqlite3\r | |
18 | import os\r | |
19 | import time\r | |
20 | import Common.EdkLogger as EdkLogger\r | |
21 | \r | |
22 | from CommonDataClass import DistributionPackageClass\r | |
23 | \r | |
24 | ## IpiDb\r | |
25 | #\r | |
26 | # This class represents the installed package information databse\r | |
27 | # Add/Remove/Get installed distribution package information here.\r | |
28 | # \r | |
29 | # \r | |
30 | # @param object: Inherited from object class\r | |
31 | # @param DbPath: A string for the path of the database\r | |
32 | #\r | |
33 | # @var Conn: Connection of the database\r | |
34 | # @var Cur: Cursor of the connection\r | |
35 | #\r | |
36 | class IpiDatabase(object):\r | |
37 | def __init__(self, DbPath):\r | |
38 | Dir = os.path.dirname(DbPath)\r | |
39 | if not os.path.isdir(Dir):\r | |
40 | os.mkdir(Dir)\r | |
41 | self.Conn = sqlite3.connect(DbPath, isolation_level = 'DEFERRED')\r | |
42 | self.Conn.execute("PRAGMA page_size=4096")\r | |
43 | self.Conn.execute("PRAGMA synchronous=OFF")\r | |
44 | self.Cur = self.Conn.cursor()\r | |
45 | self.DpTable = 'DpInfo'\r | |
46 | self.PkgTable = 'PkgInfo'\r | |
47 | self.ModInPkgTable = 'ModInPkgInfo'\r | |
48 | self.StandaloneModTable = 'StandaloneModInfo'\r | |
49 | self.ModDepexTable = 'ModDepexInfo'\r | |
50 | self.DpFileListTable = 'DpFileListInfo'\r | |
51 | \r | |
52 | ## Initialize build database\r | |
53 | #\r | |
54 | #\r | |
55 | def InitDatabase(self):\r | |
56 | EdkLogger.verbose("\nInitialize IPI database started ...")\r | |
57 | \r | |
58 | #\r | |
59 | # Create new table\r | |
60 | #\r | |
61 | SqlCommand = """create table IF NOT EXISTS %s (DpGuid TEXT NOT NULL,\r | |
62 | DpVersion TEXT NOT NULL,\r | |
63 | InstallTime REAL NOT NULL,\r | |
64 | PkgFileName TEXT,\r | |
65 | PRIMARY KEY (DpGuid, DpVersion)\r | |
66 | )""" % self.DpTable\r | |
67 | self.Cur.execute(SqlCommand)\r | |
68 | \r | |
69 | SqlCommand = """create table IF NOT EXISTS %s (FilePath TEXT NOT NULL,\r | |
70 | DpGuid TEXT,\r | |
71 | DpVersion TEXT,\r | |
72 | PRIMARY KEY (FilePath)\r | |
73 | )""" % self.DpFileListTable\r | |
74 | self.Cur.execute(SqlCommand)\r | |
75 | \r | |
76 | SqlCommand = """create table IF NOT EXISTS %s (PackageGuid TEXT NOT NULL,\r | |
77 | PackageVersion TEXT NOT NULL,\r | |
78 | InstallTime REAL NOT NULL,\r | |
79 | DpGuid TEXT,\r | |
80 | DpVersion TEXT,\r | |
81 | InstallPath TEXT NOT NULL,\r | |
82 | PRIMARY KEY (PackageGuid, PackageVersion, InstallPath)\r | |
83 | )""" % self.PkgTable\r | |
84 | self.Cur.execute(SqlCommand)\r | |
85 | \r | |
86 | SqlCommand = """create table IF NOT EXISTS %s (ModuleGuid TEXT NOT NULL,\r | |
87 | ModuleVersion TEXT NOT NULL,\r | |
88 | InstallTime REAL NOT NULL,\r | |
89 | PackageGuid TEXT,\r | |
90 | PackageVersion TEXT,\r | |
91 | InstallPath TEXT NOT NULL,\r | |
92 | PRIMARY KEY (ModuleGuid, ModuleVersion, InstallPath)\r | |
93 | )""" % self.ModInPkgTable\r | |
94 | self.Cur.execute(SqlCommand)\r | |
95 | \r | |
96 | SqlCommand = """create table IF NOT EXISTS %s (ModuleGuid TEXT NOT NULL,\r | |
97 | ModuleVersion TEXT NOT NULL,\r | |
98 | InstallTime REAL NOT NULL,\r | |
99 | DpGuid TEXT,\r | |
100 | DpVersion TEXT,\r | |
101 | InstallPath TEXT NOT NULL,\r | |
102 | PRIMARY KEY (ModuleGuid, ModuleVersion, InstallPath)\r | |
103 | )""" % self.StandaloneModTable\r | |
104 | self.Cur.execute(SqlCommand)\r | |
105 | \r | |
106 | SqlCommand = """create table IF NOT EXISTS %s (ModuleGuid TEXT NOT NULL,\r | |
107 | ModuleVersion TEXT NOT NULL,\r | |
108 | InstallPath TEXT NOT NULL,\r | |
109 | DepexGuid TEXT,\r | |
110 | DepexVersion TEXT\r | |
111 | )""" % self.ModDepexTable\r | |
112 | self.Cur.execute(SqlCommand)\r | |
113 | \r | |
114 | self.Conn.commit()\r | |
115 | \r | |
116 | EdkLogger.verbose("Initialize IPI database ... DONE!")\r | |
117 | \r | |
118 | ## Add a distribution install information from DpObj\r | |
119 | #\r | |
120 | # @param DpObj:\r | |
121 | #\r | |
122 | def AddDPObject(self, DpObj):\r | |
123 | \r | |
124 | for PkgKey in DpObj.PackageSurfaceArea.keys():\r | |
125 | PkgGuid = PkgKey[0]\r | |
126 | PkgVersion = PkgKey[1]\r | |
127 | PkgInstallPath = PkgKey[2]\r | |
128 | self.AddPackage(PkgGuid, PkgVersion, DpObj.Header.Guid, DpObj.Header.Version, PkgInstallPath)\r | |
129 | PkgObj = DpObj.PackageSurfaceArea[PkgKey]\r | |
130 | for ModKey in PkgObj.Modules.keys():\r | |
131 | ModGuid = ModKey[0]\r | |
132 | ModVersion = ModKey[1]\r | |
133 | ModInstallPath = ModKey[2]\r | |
134 | self.AddModuleInPackage(ModGuid, ModVersion, PkgGuid, PkgVersion, ModInstallPath)\r | |
135 | ModObj = PkgObj.Modules[ModKey]\r | |
136 | for Dep in ModObj.PackageDependencies:\r | |
137 | DepexGuid = Dep.PackageGuid\r | |
138 | DepexVersion = Dep.PackageVersion\r | |
139 | self.AddModuleDepex(ModGuid, ModVersion, ModInstallPath, DepexGuid, DepexVersion)\r | |
140 | for FilePath in PkgObj.FileList:\r | |
141 | self.AddDpFilePathList(DpObj.Header.Guid, DpObj.Header.Version, FilePath)\r | |
142 | \r | |
143 | for ModKey in DpObj.ModuleSurfaceArea.keys():\r | |
144 | ModGuid = ModKey[0]\r | |
145 | ModVersion = ModKey[1]\r | |
146 | ModInstallPath = ModKey[2]\r | |
147 | self.AddStandaloneModule(ModGuid, ModVersion, DpObj.Header.Guid, DpObj.Header.Version, ModInstallPath)\r | |
148 | ModObj = DpObj.ModuleSurfaceArea[ModKey]\r | |
149 | for Dep in ModObj.PackageDependencies:\r | |
150 | DepexGuid = Dep.PackageGuid\r | |
151 | DepexVersion = Dep.PackageVersion\r | |
152 | self.AddModuleDepex(ModGuid, ModVersion, ModInstallPath, DepexGuid, DepexVersion)\r | |
153 | for FilePath in ModObj.FileList:\r | |
154 | self.AddDpFilePathList(DpObj.Header.Guid, DpObj.Header.Version, FilePath)\r | |
155 | \r | |
156 | self.AddDp(DpObj.Header.Guid, DpObj.Header.Version, DpObj.Header.FileName) \r | |
157 | ## Add a distribution install information\r | |
158 | #\r | |
159 | # @param Guid: \r | |
160 | # @param Version:\r | |
161 | # @param PkgFileName:\r | |
162 | #\r | |
163 | def AddDp(self, Guid, Version, PkgFileName = None):\r | |
164 | \r | |
165 | if Version == None or len(Version.strip()) == 0:\r | |
166 | Version = 'N/A'\r | |
167 | \r | |
168 | #\r | |
169 | # Add newly installed DP information to DB.\r | |
170 | #\r | |
171 | if PkgFileName == None or len(PkgFileName.strip()) == 0:\r | |
172 | PkgFileName = 'N/A'\r | |
173 | (Guid, Version, PkgFileName) = (Guid, Version, PkgFileName)\r | |
174 | CurrentTime = time.time()\r | |
175 | SqlCommand = """insert into %s values('%s', '%s', %s, '%s')""" % (self.DpTable, Guid, Version, CurrentTime, PkgFileName)\r | |
176 | self.Cur.execute(SqlCommand)\r | |
177 | self.Conn.commit()\r | |
178 | \r | |
179 | ## Add a file list from DP\r | |
180 | #\r | |
181 | # @param DpGuid: \r | |
182 | # @param DpVersion:\r | |
183 | # @param Path\r | |
184 | #\r | |
185 | def AddDpFilePathList(self, DpGuid, DpVersion, Path):\r | |
186 | \r | |
187 | SqlCommand = """insert into %s values('%s', '%s', '%s')""" % (self.DpFileListTable, Path, DpGuid, DpVersion)\r | |
188 | self.Cur.execute(SqlCommand)\r | |
189 | self.Conn.commit()\r | |
190 | \r | |
191 | ## Add a package install information\r | |
192 | #\r | |
193 | # @param Guid: \r | |
194 | # @param Version:\r | |
195 | # @param DpGuid: \r | |
196 | # @param DpVersion:\r | |
197 | # @param Path\r | |
198 | #\r | |
199 | def AddPackage(self, Guid, Version, DpGuid = None, DpVersion = None, Path = ''):\r | |
200 | \r | |
201 | if Version == None or len(Version.strip()) == 0:\r | |
202 | Version = 'N/A'\r | |
203 | \r | |
204 | if DpGuid == None or len(DpGuid.strip()) == 0:\r | |
205 | DpGuid = 'N/A'\r | |
206 | \r | |
207 | if DpVersion == None or len(DpVersion.strip()) == 0:\r | |
208 | DpVersion = 'N/A'\r | |
209 | \r | |
210 | #\r | |
211 | # Add newly installed package information to DB.\r | |
212 | #\r | |
213 | \r | |
214 | CurrentTime = time.time()\r | |
215 | SqlCommand = """insert into %s values('%s', '%s', %s, '%s', '%s', '%s')""" % (self.PkgTable, Guid, Version, CurrentTime, DpGuid, DpVersion, Path)\r | |
216 | self.Cur.execute(SqlCommand)\r | |
217 | self.Conn.commit()\r | |
218 | \r | |
219 | ## Add a module that from a package install information\r | |
220 | #\r | |
221 | # @param Guid: \r | |
222 | # @param Version:\r | |
223 | # @param PkgFileName:\r | |
224 | #\r | |
225 | def AddModuleInPackage(self, Guid, Version, PkgGuid = None, PkgVersion = None, Path = ''):\r | |
226 | \r | |
227 | if Version == None or len(Version.strip()) == 0:\r | |
228 | Version = 'N/A'\r | |
229 | \r | |
230 | if PkgGuid == None or len(PkgGuid.strip()) == 0:\r | |
231 | PkgGuid = 'N/A'\r | |
232 | \r | |
233 | if PkgVersion == None or len(PkgVersion.strip()) == 0:\r | |
234 | PkgVersion = 'N/A'\r | |
235 | \r | |
236 | #\r | |
237 | # Add module from package information to DB.\r | |
238 | #\r | |
239 | CurrentTime = time.time()\r | |
240 | SqlCommand = """insert into %s values('%s', '%s', %s, '%s', '%s', '%s')""" % (self.ModInPkgTable, Guid, Version, CurrentTime, PkgGuid, PkgVersion, Path)\r | |
241 | self.Cur.execute(SqlCommand)\r | |
242 | self.Conn.commit()\r | |
243 | \r | |
244 | ## Add a module that is standalone install information\r | |
245 | #\r | |
246 | # @param Guid: \r | |
247 | # @param Version:\r | |
248 | # @param PkgFileName:\r | |
249 | #\r | |
250 | def AddStandaloneModule(self, Guid, Version, DpGuid = None, DpVersion = None, Path = ''):\r | |
251 | \r | |
252 | if Version == None or len(Version.strip()) == 0:\r | |
253 | Version = 'N/A'\r | |
254 | \r | |
255 | if DpGuid == None or len(DpGuid.strip()) == 0:\r | |
256 | DpGuid = 'N/A'\r | |
257 | \r | |
258 | if DpVersion == None or len(DpVersion.strip()) == 0:\r | |
259 | DpVersion = 'N/A'\r | |
260 | \r | |
261 | #\r | |
262 | # Add module standalone information to DB.\r | |
263 | #\r | |
264 | CurrentTime = time.time()\r | |
265 | SqlCommand = """insert into %s values('%s', '%s', %s, '%s', '%s', '%s')""" % (self.StandaloneModTable, Guid, Version, CurrentTime, DpGuid, DpVersion, Path)\r | |
266 | self.Cur.execute(SqlCommand)\r | |
267 | self.Conn.commit()\r | |
268 | \r | |
269 | ## Add a module depex\r | |
270 | #\r | |
271 | # @param Guid: \r | |
272 | # @param Version:\r | |
273 | # @param DepexGuid:\r | |
274 | # @param DepexVersion:\r | |
275 | #\r | |
276 | def AddModuleDepex(self, Guid, Version, Path, DepexGuid = None, DepexVersion = None):\r | |
277 | \r | |
278 | if DepexGuid == None or len(DepexGuid.strip()) == 0:\r | |
279 | DepexGuid = 'N/A'\r | |
280 | \r | |
281 | if DepexVersion == None or len(DepexVersion.strip()) == 0:\r | |
282 | DepexVersion = 'N/A'\r | |
283 | \r | |
284 | #\r | |
285 | # Add module depex information to DB.\r | |
286 | #\r | |
287 | \r | |
288 | SqlCommand = """insert into %s values('%s', '%s', '%s', '%s', '%s')""" % (self.ModDepexTable, Guid, Version, Path, DepexGuid, DepexVersion)\r | |
289 | self.Cur.execute(SqlCommand)\r | |
290 | self.Conn.commit()\r | |
291 | \r | |
292 | ## Remove a distribution install information, if no version specified, remove all DPs with this Guid.\r | |
293 | #\r | |
294 | # @param DpObj: \r | |
295 | #\r | |
296 | def RemoveDpObj(self, DpGuid, DpVersion):\r | |
297 | \r | |
298 | PkgList = self.GetPackageListFromDp(DpGuid, DpVersion)\r | |
299 | \r | |
300 | # delete from ModDepex the standalone module's dependency\r | |
301 | SqlCommand = """delete from ModDepexInfo where ModDepexInfo.ModuleGuid in \r | |
302 | (select ModuleGuid from StandaloneModInfo as B where B.DpGuid = '%s' and B.DpVersion = '%s')\r | |
303 | and ModDepexInfo.ModuleVersion in\r | |
304 | (select ModuleVersion from StandaloneModInfo as B where B.DpGuid = '%s' and B.DpVersion = '%s')\r | |
305 | and ModDepexInfo.InstallPath in\r | |
306 | (select InstallPath from StandaloneModInfo as B where B.DpGuid = '%s' and B.DpVersion = '%s') """ \\r | |
307 | %(DpGuid, DpVersion, DpGuid, DpVersion, DpGuid, DpVersion)\r | |
308 | \r | |
309 | # SqlCommand = """delete from %s where %s.DpGuid ='%s' and %s.DpVersion = '%s' and \r | |
310 | # %s.ModuleGuid = %s.ModuleGuid and %s.ModuleVersion = %s.ModuleVersion and \r | |
311 | # %s.InstallPath = %s.InstallPath""" \\r | |
312 | # % (self.ModDepexTable, self.StandaloneModTable, DpGuid, self.StandaloneModTable, DpVersion, self.ModDepexTable, self.StandaloneModTable, self.ModDepexTable, self.StandaloneModTable, self.ModDepexTable, self.StandaloneModTable)\r | |
313 | # print SqlCommand\r | |
314 | self.Cur.execute(SqlCommand)\r | |
315 | \r | |
316 | # delete from ModDepex the from pkg module's dependency\r | |
317 | for Pkg in PkgList:\r | |
318 | # SqlCommand = """delete from %s where %s.PackageGuid ='%s' and %s.PackageVersion = '%s' and \r | |
319 | # %s.ModuleGuid = %s.ModuleGuid and %s.ModuleVersion = %s.ModuleVersion and \r | |
320 | # %s.InstallPath = %s.InstallPath""" \\r | |
321 | # % (self.ModDepexTable, self.ModInPkgTable, Pkg[0], self.ModInPkgTable, Pkg[1], self.ModDepexTable, self.ModInPkgTable, self.ModDepexTable, self.ModInPkgTable, self.ModDepexTable, self.ModInPkgTable)\r | |
322 | SqlCommand = """delete from ModDepexInfo where ModDepexInfo.ModuleGuid in \r | |
323 | (select ModuleGuid from ModInPkgInfo where ModInPkgInfo.PackageGuid ='%s' and ModInPkgInfo.PackageVersion = '%s')\r | |
324 | and ModDepexInfo.ModuleVersion in\r | |
325 | (select ModuleVersion from ModInPkgInfo where ModInPkgInfo.PackageGuid ='%s' and ModInPkgInfo.PackageVersion = '%s')\r | |
326 | and ModDepexInfo.InstallPath in\r | |
327 | (select InstallPath from ModInPkgInfo where ModInPkgInfo.PackageGuid ='%s' and ModInPkgInfo.PackageVersion = '%s')""" \\r | |
328 | % (Pkg[0], Pkg[1],Pkg[0], Pkg[1],Pkg[0], Pkg[1])\r | |
329 | \r | |
330 | self.Cur.execute(SqlCommand)\r | |
331 | \r | |
332 | # delete the standalone module\r | |
333 | SqlCommand = """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % (self.StandaloneModTable, DpGuid, DpVersion)\r | |
334 | self.Cur.execute(SqlCommand)\r | |
335 | \r | |
336 | # delete the from pkg module\r | |
337 | for Pkg in PkgList:\r | |
338 | SqlCommand = """delete from %s where %s.PackageGuid ='%s' and %s.PackageVersion = '%s'""" \\r | |
339 | % (self.ModInPkgTable, self.ModInPkgTable, Pkg[0], self.ModInPkgTable, Pkg[1])\r | |
340 | self.Cur.execute(SqlCommand)\r | |
341 | \r | |
342 | # delete packages\r | |
343 | SqlCommand = """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % (self.PkgTable, DpGuid, DpVersion)\r | |
344 | self.Cur.execute(SqlCommand)\r | |
345 | \r | |
346 | # delete file list from DP\r | |
347 | SqlCommand = """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % (self.DpFileListTable, DpGuid, DpVersion)\r | |
348 | self.Cur.execute(SqlCommand)\r | |
349 | \r | |
350 | # delete DP\r | |
351 | SqlCommand = """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % (self.DpTable, DpGuid, DpVersion)\r | |
352 | self.Cur.execute(SqlCommand)\r | |
353 | \r | |
354 | self.Conn.commit()\r | |
355 | \r | |
356 | ## Get a list of distribution install information.\r | |
357 | #\r | |
358 | # @param Guid: \r | |
359 | # @param Version: \r | |
360 | #\r | |
361 | def GetDp(self, Guid, Version):\r | |
362 | \r | |
363 | if Version == None or len(Version.strip()) == 0:\r | |
364 | Version = 'N/A'\r | |
365 | EdkLogger.verbose("\nGetting list of DP install information started ...")\r | |
366 | (DpGuid, DpVersion) = (Guid, Version)\r | |
367 | SqlCommand = """select * from %s where DpGuid ='%s'""" % (self.DpTable, DpGuid)\r | |
368 | self.Cur.execute(SqlCommand)\r | |
369 | \r | |
370 | else:\r | |
371 | EdkLogger.verbose("\nGetting DP install information started ...")\r | |
372 | (DpGuid, DpVersion) = (Guid, Version)\r | |
373 | SqlCommand = """select * from %s where DpGuid ='%s' and DpVersion = '%s'""" % (self.DpTable, DpGuid, DpVersion)\r | |
374 | self.Cur.execute(SqlCommand)\r | |
375 | \r | |
376 | DpList = []\r | |
377 | for DpInfo in self.Cur:\r | |
378 | DpGuid = DpInfo[0]\r | |
379 | DpVersion = DpInfo[1]\r | |
380 | InstallTime = DpInfo[2]\r | |
381 | PkgFileName = DpInfo[3]\r | |
382 | DpList.append((DpGuid, DpVersion, InstallTime, PkgFileName))\r | |
383 | \r | |
384 | EdkLogger.verbose("Getting DP install information ... DONE!")\r | |
385 | return DpList\r | |
386 | \r | |
387 | ## Get a list of distribution install file path information.\r | |
388 | #\r | |
389 | # @param Guid: \r | |
390 | # @param Version: \r | |
391 | #\r | |
392 | def GetDpFileList(self, Guid, Version):\r | |
393 | \r | |
394 | (DpGuid, DpVersion) = (Guid, Version)\r | |
395 | SqlCommand = """select * from %s where DpGuid ='%s' and DpVersion = '%s'""" % (self.DpFileListTable, DpGuid, DpVersion)\r | |
396 | self.Cur.execute(SqlCommand)\r | |
397 | \r | |
398 | PathList = []\r | |
399 | for Result in self.Cur:\r | |
400 | Path = Result[0]\r | |
401 | PathList.append(Path)\r | |
402 | \r | |
403 | return PathList\r | |
404 | \r | |
405 | ## Get a list of package information.\r | |
406 | #\r | |
407 | # @param Guid: \r | |
408 | # @param Version: \r | |
409 | #\r | |
410 | def GetPackage(self, Guid, Version, DpGuid = '', DpVersion = ''):\r | |
411 | \r | |
412 | if DpVersion == '' or DpGuid == '':\r | |
413 | \r | |
414 | (PackageGuid, PackageVersion) = (Guid, Version)\r | |
415 | SqlCommand = """select * from %s where PackageGuid ='%s' and PackageVersion = '%s'""" % (self.PkgTable, PackageGuid, PackageVersion)\r | |
416 | self.Cur.execute(SqlCommand)\r | |
417 | \r | |
418 | elif Version == None or len(Version.strip()) == 0:\r | |
419 | \r | |
420 | SqlCommand = """select * from %s where PackageGuid ='%s'""" % (self.PkgTable, Guid)\r | |
421 | self.Cur.execute(SqlCommand)\r | |
422 | else:\r | |
423 | (PackageGuid, PackageVersion) = (Guid, Version)\r | |
424 | SqlCommand = """select * from %s where PackageGuid ='%s' and PackageVersion = '%s'\r | |
425 | and DpGuid = '%s' and DpVersion = '%s'""" % (self.PkgTable, PackageGuid, PackageVersion, DpGuid, DpVersion)\r | |
426 | self.Cur.execute(SqlCommand)\r | |
427 | \r | |
428 | PkgList = []\r | |
429 | for PkgInfo in self.Cur:\r | |
430 | PkgGuid = PkgInfo[0]\r | |
431 | PkgVersion = PkgInfo[1]\r | |
432 | InstallTime = PkgInfo[2]\r | |
433 | InstallPath = PkgInfo[5]\r | |
434 | PkgList.append((PkgGuid, PkgVersion, InstallTime, DpGuid, DpVersion, InstallPath))\r | |
435 | \r | |
436 | return PkgList\r | |
437 | \r | |
438 | ## Get a list of module in package information.\r | |
439 | #\r | |
440 | # @param Guid: \r | |
441 | # @param Version: \r | |
442 | #\r | |
443 | def GetModInPackage(self, Guid, Version, PkgGuid = '', PkgVersion = ''):\r | |
444 | \r | |
445 | if PkgVersion == '' or PkgGuid == '':\r | |
446 | \r | |
447 | (ModuleGuid, ModuleVersion) = (Guid, Version)\r | |
448 | SqlCommand = """select * from %s where ModuleGuid ='%s' and ModuleVersion = '%s'""" % (self.ModInPkgTable, ModuleGuid, ModuleVersion)\r | |
449 | self.Cur.execute(SqlCommand)\r | |
450 | \r | |
451 | else:\r | |
452 | (ModuleGuid, ModuleVersion) = (Guid, Version)\r | |
453 | SqlCommand = """select * from %s where ModuleGuid ='%s' and ModuleVersion = '%s' and PackageGuid ='%s' and PackageVersion = '%s'\r | |
454 | """ % (self.ModInPkgTable, ModuleGuid, ModuleVersion, PkgGuid, PkgVersion)\r | |
455 | self.Cur.execute(SqlCommand)\r | |
456 | \r | |
457 | ModList = []\r | |
458 | for ModInfo in self.Cur:\r | |
459 | ModGuid = ModInfo[0]\r | |
460 | ModVersion = ModInfo[1]\r | |
461 | InstallTime = ModInfo[2]\r | |
462 | InstallPath = ModInfo[5]\r | |
463 | ModList.append((ModGuid, ModVersion, InstallTime, PkgGuid, PkgVersion, InstallPath))\r | |
464 | \r | |
465 | return ModList\r | |
466 | \r | |
467 | ## Get a list of module standalone.\r | |
468 | #\r | |
469 | # @param Guid: \r | |
470 | # @param Version: \r | |
471 | #\r | |
472 | def GetStandaloneModule(self, Guid, Version, DpGuid = '', DpVersion = ''):\r | |
473 | \r | |
474 | if DpGuid == '':\r | |
475 | \r | |
476 | (ModuleGuid, ModuleVersion) = (Guid, Version)\r | |
477 | SqlCommand = """select * from %s where ModuleGuid ='%s' and ModuleVersion = '%s'""" % (self.StandaloneModTable, ModuleGuid, ModuleVersion)\r | |
478 | self.Cur.execute(SqlCommand)\r | |
479 | \r | |
480 | else:\r | |
481 | (ModuleGuid, ModuleVersion) = (Guid, Version)\r | |
482 | SqlCommand = """select * from %s where ModuleGuid ='%s' and ModuleVersion = '%s' and DpGuid ='%s' and DpVersion = '%s'\r | |
483 | """ % (self.StandaloneModTable, ModuleGuid, ModuleVersion, DpGuid, DpVersion)\r | |
484 | self.Cur.execute(SqlCommand)\r | |
485 | \r | |
486 | ModList = []\r | |
487 | for ModInfo in self.Cur:\r | |
488 | ModGuid = ModInfo[0]\r | |
489 | ModVersion = ModInfo[1]\r | |
490 | InstallTime = ModInfo[2]\r | |
491 | InstallPath = ModInfo[5]\r | |
492 | ModList.append((ModGuid, ModVersion, InstallTime, DpGuid, DpVersion, InstallPath))\r | |
493 | \r | |
494 | return ModList\r | |
495 | \r | |
496 | ## Get a list of module information that comes from DP.\r | |
497 | #\r | |
498 | # @param DpGuid: \r | |
499 | # @param DpVersion: \r | |
500 | #\r | |
501 | def GetStandaloneModuleInstallPathListFromDp(self, DpGuid, DpVersion):\r | |
502 | \r | |
503 | PathList = []\r | |
504 | SqlCommand = """select t1.InstallPath from %s t1 where t1.DpGuid ='%s' and t1.DpVersion = '%s'\r | |
505 | """ % (self.StandaloneModTable, DpGuid, DpVersion)\r | |
506 | self.Cur.execute(SqlCommand)\r | |
507 | \r | |
508 | for Result in self.Cur:\r | |
509 | InstallPath = Result[0]\r | |
510 | PathList.append(InstallPath)\r | |
511 | \r | |
512 | return PathList\r | |
513 | \r | |
514 | ## Get a list of package information.\r | |
515 | #\r | |
516 | # @param DpGuid: \r | |
517 | # @param DpVersion: \r | |
518 | #\r | |
519 | def GetPackageListFromDp(self, DpGuid, DpVersion):\r | |
520 | \r | |
521 | \r | |
522 | SqlCommand = """select * from %s where DpGuid ='%s' and DpVersion = '%s'\r | |
523 | """ % (self.PkgTable, DpGuid, DpVersion)\r | |
524 | self.Cur.execute(SqlCommand)\r | |
525 | \r | |
526 | PkgList = []\r | |
527 | for PkgInfo in self.Cur:\r | |
528 | PkgGuid = PkgInfo[0]\r | |
529 | PkgVersion = PkgInfo[1]\r | |
530 | InstallPath = PkgInfo[5]\r | |
531 | PkgList.append((PkgGuid, PkgVersion, InstallPath))\r | |
532 | \r | |
533 | return PkgList\r | |
534 | \r | |
535 | ## Get a list of modules that depends on package information from a DP.\r | |
536 | #\r | |
537 | # @param DpGuid: \r | |
538 | # @param DpVersion: \r | |
539 | #\r | |
540 | def GetDpDependentModuleList(self, DpGuid, DpVersion):\r | |
541 | \r | |
542 | ModList = []\r | |
543 | PkgList = self.GetPackageListFromDp(DpGuid, DpVersion)\r | |
544 | if len(PkgList) > 0:\r | |
545 | return ModList\r | |
546 | \r | |
547 | for Pkg in PkgList:\r | |
548 | SqlCommand = """select t1.ModuleGuid, t1.ModuleVersion, t1.InstallPath \r | |
549 | from %s as t1, %s as t2, where t1.ModuleGuid = t2.ModuleGuid and \r | |
550 | t1.ModuleVersion = t2.ModuleVersion and t2.DepexGuid ='%s' and (t2.DepexVersion = '%s' or t2.DepexVersion = 'N/A') and\r | |
551 | t1.PackageGuid != '%s' and t1.PackageVersion != '%s'\r | |
552 | """ % (self.ModInPkgTable, self.ModDepexTable, Pkg[0], Pkg[1], Pkg[0], Pkg[1])\r | |
553 | self.Cur.execute(SqlCommand)\r | |
554 | for ModInfo in self.Cur:\r | |
555 | ModGuid = ModInfo[0]\r | |
556 | ModVersion = ModInfo[1]\r | |
557 | InstallPath = ModInfo[2]\r | |
558 | ModList.append((ModGuid, ModVersion, InstallPath))\r | |
559 | \r | |
560 | SqlCommand = """select t1.ModuleGuid, t1.ModuleVersion, t1.InstallPath \r | |
561 | from %s as t1, %s as t2, where t1.ModuleGuid = t2.ModuleGuid and \r | |
562 | t1.ModuleVersion = t2.ModuleVersion and t2.DepexGuid ='%s' and (t2.DepexVersion = '%s' or t2.DepexVersion = 'N/A') and\r | |
563 | t1.DpGuid != '%s' and t1.DpVersion != '%s'\r | |
564 | """ % (self.StandaloneModTable, self.ModDepexTable, Pkg[0], Pkg[1], DpGuid, DpVersion)\r | |
565 | self.Cur.execute(SqlCommand)\r | |
566 | for ModInfo in self.Cur:\r | |
567 | ModGuid = ModInfo[0]\r | |
568 | ModVersion = ModInfo[1]\r | |
569 | InstallPath = ModInfo[2]\r | |
570 | ModList.append((ModGuid, ModVersion, InstallPath))\r | |
571 | \r | |
572 | \r | |
573 | return ModList\r | |
574 | \r | |
575 | ## Get a module depex\r | |
576 | #\r | |
577 | # @param Guid: \r | |
578 | # @param Version:\r | |
579 | # @param Path:\r | |
580 | #\r | |
581 | def GetModuleDepex(self, Guid, Version, Path):\r | |
582 | \r | |
583 | #\r | |
584 | # Get module depex information to DB.\r | |
585 | #\r | |
586 | \r | |
587 | SqlCommand = """select * from %s where ModuleGuid ='%s' and ModuleVersion = '%s' and InstallPath ='%s'\r | |
588 | """ % (self.ModDepexTable, Guid, Version, Path)\r | |
589 | self.Cur.execute(SqlCommand)\r | |
590 | self.Conn.commit()\r | |
591 | \r | |
592 | DepexList = []\r | |
593 | for DepInfo in self.Cur:\r | |
594 | DepexGuid = DepInfo[3]\r | |
595 | DepexVersion = DepInfo[4]\r | |
596 | DepexList.append((DepexGuid, DepexVersion))\r | |
597 | \r | |
598 | return DepexList\r | |
599 | \r | |
600 | ## Close entire database\r | |
601 | #\r | |
602 | # Close the connection and cursor\r | |
603 | #\r | |
604 | def CloseDb(self):\r | |
605 | \r | |
606 | self.Cur.close()\r | |
607 | self.Conn.close()\r | |
608 | \r | |
609 | ## Convert To Sql String\r | |
610 | #\r | |
611 | # 1. Replace "'" with "''" in each item of StringList\r | |
612 | # \r | |
613 | # @param StringList: A list for strings to be converted\r | |
614 | #\r | |
615 | def __ConvertToSqlString(self, StringList):\r | |
616 | return map(lambda s: s.replace("'", "''") , StringList)\r | |
617 | ##\r | |
618 | #\r | |
619 | # This acts like the main() function for the script, unless it is 'import'ed into another\r | |
620 | # script.\r | |
621 | #\r | |
622 | if __name__ == '__main__':\r | |
623 | EdkLogger.Initialize()\r | |
624 | EdkLogger.SetLevel(EdkLogger.DEBUG_0)\r | |
625 | DATABASE_PATH = "C://MyWork//Conf//.cache//XML.db"\r | |
626 | Db = IpiDatabase(DATABASE_PATH)\r | |
627 | Db.InitDatabase()\r | |
628 | \r | |
629 |