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