]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/UPT/Core/IpiDb.py
38f872c2addf46887030a3c845b89843eea381e4
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Core / IpiDb.py
1 ## @file
2 # This file is for installed package information database operations
3 #
4 # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
5 #
6 # This program and the accompanying materials are licensed and made available
7 # under the terms and conditions of the BSD License which accompanies this
8 # distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
10 #
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 #
14
15 '''
16 IpiDb
17 '''
18
19 ##
20 # Import Modules
21 #
22 import sqlite3
23 import os.path
24 import time
25
26 import Logger.Log as Logger
27 from Logger import StringTable as ST
28 from Logger.ToolError import UPT_ALREADY_RUNNING_ERROR
29
30 ## IpiDb
31 #
32 # This class represents the installed package information database
33 # Add/Remove/Get installed distribution package information here.
34 #
35 #
36 # @param object: Inherited from object class
37 # @param DbPath: A string for the path of the database
38 #
39 #
40 class IpiDatabase(object):
41 def __init__(self, DbPath):
42 Dir = os.path.dirname(DbPath)
43 if not os.path.isdir(Dir):
44 os.mkdir(Dir)
45 self.Conn = sqlite3.connect(DbPath, isolation_level='DEFERRED')
46 self.Conn.execute("PRAGMA page_size=4096")
47 self.Conn.execute("PRAGMA synchronous=OFF")
48 self.Cur = self.Conn.cursor()
49 self.DpTable = 'DpInfo'
50 self.PkgTable = 'PkgInfo'
51 self.ModInPkgTable = 'ModInPkgInfo'
52 self.StandaloneModTable = 'StandaloneModInfo'
53 self.ModDepexTable = 'ModDepexInfo'
54 self.DpFileListTable = 'DpFileListInfo'
55 self.DummyTable = 'Dummy'
56
57 ## Initialize build database
58 #
59 #
60 def InitDatabase(self, SkipLock = False):
61 Logger.Verbose(ST.MSG_INIT_IPI_START)
62 if not SkipLock:
63 try:
64 #
65 # Create a dummy table, if already existed,
66 # then UPT is already running
67 #
68 SqlCommand = """
69 create table %s (
70 Dummy TEXT NOT NULL,
71 PRIMARY KEY (Dummy)
72 )""" % self.DummyTable
73 self.Cur.execute(SqlCommand)
74 self.Conn.commit()
75 except sqlite3.OperationalError:
76 Logger.Error("UPT",
77 UPT_ALREADY_RUNNING_ERROR,
78 ST.ERR_UPT_ALREADY_RUNNING_ERROR
79 )
80
81 #
82 # Create new table
83 #
84 SqlCommand = """
85 create table IF NOT EXISTS %s (
86 DpGuid TEXT NOT NULL,DpVersion TEXT NOT NULL,
87 InstallTime REAL NOT NULL,
88 NewPkgFileName TEXT NOT NULL,
89 PkgFileName TEXT NOT NULL,
90 RePackage TEXT NOT NULL,
91 PRIMARY KEY (DpGuid, DpVersion)
92 )""" % self.DpTable
93 self.Cur.execute(SqlCommand)
94
95 SqlCommand = """
96 create table IF NOT EXISTS %s (
97 FilePath TEXT NOT NULL,
98 DpGuid TEXT,
99 DpVersion TEXT,
100 Md5Sum TEXT,
101 PRIMARY KEY (FilePath)
102 )""" % self.DpFileListTable
103 self.Cur.execute(SqlCommand)
104
105 SqlCommand = """
106 create table IF NOT EXISTS %s (
107 PackageGuid TEXT NOT NULL,
108 PackageVersion TEXT NOT NULL,
109 InstallTime REAL NOT NULL,
110 DpGuid TEXT,
111 DpVersion TEXT,
112 InstallPath TEXT NOT NULL,
113 PRIMARY KEY (PackageGuid, PackageVersion, InstallPath)
114 )""" % self.PkgTable
115 self.Cur.execute(SqlCommand)
116
117 SqlCommand = """
118 create table IF NOT EXISTS %s (
119 ModuleGuid TEXT NOT NULL,
120 ModuleVersion TEXT NOT NULL,
121 InstallTime REAL NOT NULL,
122 PackageGuid TEXT,
123 PackageVersion TEXT,
124 InstallPath TEXT NOT NULL,
125 PRIMARY KEY (ModuleGuid, ModuleVersion, InstallPath)
126 )""" % self.ModInPkgTable
127 self.Cur.execute(SqlCommand)
128
129 SqlCommand = """
130 create table IF NOT EXISTS %s (
131 ModuleGuid TEXT NOT NULL,
132 ModuleVersion TEXT NOT NULL,
133 InstallTime REAL NOT NULL,
134 DpGuid TEXT,
135 DpVersion TEXT,
136 InstallPath TEXT NOT NULL,
137 PRIMARY KEY (ModuleGuid, ModuleVersion, InstallPath)
138 )""" % self.StandaloneModTable
139 self.Cur.execute(SqlCommand)
140
141 SqlCommand = """
142 create table IF NOT EXISTS %s (
143 ModuleGuid TEXT NOT NULL,
144 ModuleVersion TEXT NOT NULL,
145 InstallPath TEXT NOT NULL,
146 DepexGuid TEXT,
147 DepexVersion TEXT
148 )""" % self.ModDepexTable
149 self.Cur.execute(SqlCommand)
150
151 self.Conn.commit()
152
153 Logger.Verbose(ST.MSG_INIT_IPI_FINISH)
154
155 ## Add a distribution install information from DpObj
156 #
157 # @param DpObj:
158 # @param NewDpPkgFileName: New DpPkg File Name
159 # @param DpPkgFileName: DpPkg File Name
160 # @param RePackage: A RePackage
161 #
162 def AddDPObject(self, DpObj, NewDpPkgFileName, DpPkgFileName, RePackage):
163
164 for PkgKey in DpObj.PackageSurfaceArea.keys():
165 PkgGuid = PkgKey[0]
166 PkgVersion = PkgKey[1]
167 PkgInstallPath = PkgKey[2]
168 self._AddPackage(PkgGuid, PkgVersion, DpObj.Header.GetGuid(), \
169 DpObj.Header.GetVersion(), PkgInstallPath)
170 PkgObj = DpObj.PackageSurfaceArea[PkgKey]
171 for ModKey in PkgObj.GetModuleDict().keys():
172 ModGuid = ModKey[0]
173 ModVersion = ModKey[1]
174 ModInstallPath = ModKey[2]
175 ModInstallPath = \
176 os.path.normpath(os.path.join(PkgInstallPath, ModInstallPath))
177 self._AddModuleInPackage(ModGuid, ModVersion, PkgGuid, \
178 PkgVersion, ModInstallPath)
179 ModObj = PkgObj.GetModuleDict()[ModKey]
180 for Dep in ModObj.GetPackageDependencyList():
181 DepexGuid = Dep.GetGuid()
182 DepexVersion = Dep.GetVersion()
183 self._AddModuleDepex(ModGuid, ModVersion, ModInstallPath, \
184 DepexGuid, DepexVersion)
185 for (FilePath, Md5Sum) in PkgObj.FileList:
186 self._AddDpFilePathList(DpObj.Header.GetGuid(), \
187 DpObj.Header.GetVersion(), FilePath, \
188 Md5Sum)
189
190 for ModKey in DpObj.ModuleSurfaceArea.keys():
191 ModGuid = ModKey[0]
192 ModVersion = ModKey[1]
193 ModInstallPath = ModKey[2]
194 self._AddStandaloneModule(ModGuid, ModVersion, \
195 DpObj.Header.GetGuid(), \
196 DpObj.Header.GetVersion(), \
197 ModInstallPath)
198 ModObj = DpObj.ModuleSurfaceArea[ModKey]
199 for Dep in ModObj.GetPackageDependencyList():
200 DepexGuid = Dep.GetGuid()
201 DepexVersion = Dep.GetVersion()
202 self._AddModuleDepex(ModGuid, ModVersion, ModInstallPath, \
203 DepexGuid, DepexVersion)
204 for (Path, Md5Sum) in ModObj.FileList:
205 self._AddDpFilePathList(DpObj.Header.GetGuid(), \
206 DpObj.Header.GetVersion(), \
207 Path, Md5Sum)
208
209 #
210 # add tool/misc files
211 #
212 for (Path, Md5Sum) in DpObj.FileList:
213 self._AddDpFilePathList(DpObj.Header.GetGuid(), \
214 DpObj.Header.GetVersion(), Path, Md5Sum)
215
216 self._AddDp(DpObj.Header.GetGuid(), DpObj.Header.GetVersion(), \
217 NewDpPkgFileName, DpPkgFileName, RePackage)
218
219 self.Conn.commit()
220
221 ## Add a distribution install information
222 #
223 # @param Guid Guid of the distribution package
224 # @param Version Version of the distribution package
225 # @param NewDpFileName the saved filename of distribution package file
226 # @param DistributionFileName the filename of distribution package file
227 #
228 def _AddDp(self, Guid, Version, NewDpFileName, DistributionFileName, \
229 RePackage):
230
231 if Version == None or len(Version.strip()) == 0:
232 Version = 'N/A'
233
234 #
235 # Add newly installed DP information to DB.
236 #
237 if NewDpFileName == None or len(NewDpFileName.strip()) == 0:
238 PkgFileName = 'N/A'
239 else:
240 PkgFileName = NewDpFileName
241 CurrentTime = time.time()
242 SqlCommand = \
243 """insert into %s values('%s', '%s', %s, '%s', '%s', '%s')""" % \
244 (self.DpTable, Guid, Version, CurrentTime, PkgFileName, \
245 DistributionFileName, str(RePackage).upper())
246 self.Cur.execute(SqlCommand)
247
248
249 ## Add a file list from DP
250 #
251 # @param DpGuid: A DpGuid
252 # @param DpVersion: A DpVersion
253 # @param Path: A Path
254 # @param Path: A Md5Sum
255 #
256 def _AddDpFilePathList(self, DpGuid, DpVersion, Path, Md5Sum):
257
258 SqlCommand = """insert into %s values('%s', '%s', '%s', '%s')""" % \
259 (self.DpFileListTable, Path, DpGuid, DpVersion, Md5Sum)
260
261 self.Cur.execute(SqlCommand)
262
263 ## Add a package install information
264 #
265 # @param Guid: A package guid
266 # @param Version: A package version
267 # @param DpGuid: A DpGuid
268 # @param DpVersion: A DpVersion
269 # @param Path: A Path
270 #
271 def _AddPackage(self, Guid, Version, DpGuid=None, DpVersion=None, Path=''):
272
273 if Version == None or len(Version.strip()) == 0:
274 Version = 'N/A'
275
276 if DpGuid == None or len(DpGuid.strip()) == 0:
277 DpGuid = 'N/A'
278
279 if DpVersion == None or len(DpVersion.strip()) == 0:
280 DpVersion = 'N/A'
281
282 #
283 # Add newly installed package information to DB.
284 #
285 CurrentTime = time.time()
286 SqlCommand = \
287 """insert into %s values('%s', '%s', %s, '%s', '%s', '%s')""" % \
288 (self.PkgTable, Guid, Version, CurrentTime, DpGuid, DpVersion, Path)
289 self.Cur.execute(SqlCommand)
290
291 ## Add a module that from a package install information
292 #
293 # @param Guid: A package guid
294 # @param Version: A package version
295 # @param PkgGuid: A package guid
296 # @param PkgFileName: A package File Name
297 #
298 def _AddModuleInPackage(self, Guid, Version, PkgGuid=None, \
299 PkgVersion=None, Path=''):
300
301 if Version == None or len(Version.strip()) == 0:
302 Version = 'N/A'
303
304 if PkgGuid == None or len(PkgGuid.strip()) == 0:
305 PkgGuid = 'N/A'
306
307 if PkgVersion == None or len(PkgVersion.strip()) == 0:
308 PkgVersion = 'N/A'
309
310 #
311 # Add module from package information to DB.
312 #
313 CurrentTime = time.time()
314 SqlCommand = \
315 """insert into %s values('%s', '%s', %s, '%s', '%s', '%s')""" % \
316 (self.ModInPkgTable, Guid, Version, CurrentTime, PkgGuid, PkgVersion, \
317 Path)
318 self.Cur.execute(SqlCommand)
319
320 ## Add a module that is standalone install information
321 #
322 # @param Guid: a module Guid
323 # @param Version: a module Version
324 # @param DpGuid: a DpGuid
325 # @param DpVersion: a DpVersion
326 # @param Path: path
327 #
328 def _AddStandaloneModule(self, Guid, Version, DpGuid=None, \
329 DpVersion=None, Path=''):
330
331 if Version == None or len(Version.strip()) == 0:
332 Version = 'N/A'
333
334 if DpGuid == None or len(DpGuid.strip()) == 0:
335 DpGuid = 'N/A'
336
337 if DpVersion == None or len(DpVersion.strip()) == 0:
338 DpVersion = 'N/A'
339
340 #
341 # Add module standalone information to DB.
342 #
343 CurrentTime = time.time()
344 SqlCommand = \
345 """insert into %s values('%s', '%s', %s, '%s', '%s', '%s')""" % \
346 (self.StandaloneModTable, Guid, Version, CurrentTime, DpGuid, \
347 DpVersion, Path)
348 self.Cur.execute(SqlCommand)
349
350 ## Add a module depex
351 #
352 # @param Guid: a module Guid
353 # @param Version: a module Version
354 # @param DepexGuid: a module DepexGuid
355 # @param DepexVersion: a module DepexVersion
356 #
357 def _AddModuleDepex(self, Guid, Version, Path, DepexGuid=None, \
358 DepexVersion=None):
359
360 if DepexGuid == None or len(DepexGuid.strip()) == 0:
361 DepexGuid = 'N/A'
362
363 if DepexVersion == None or len(DepexVersion.strip()) == 0:
364 DepexVersion = 'N/A'
365
366 #
367 # Add module depex information to DB.
368 #
369 SqlCommand = """insert into %s values('%s', '%s', '%s', '%s', '%s')"""\
370 % (self.ModDepexTable, Guid, Version, Path, DepexGuid, DepexVersion)
371 self.Cur.execute(SqlCommand)
372
373 ## Remove a distribution install information, if no version specified,
374 # remove all DPs with this Guid.
375 #
376 # @param DpGuid: guid of dpex
377 # @param DpVersion: version of dpex
378 #
379 def RemoveDpObj(self, DpGuid, DpVersion):
380
381 PkgList = self.GetPackageListFromDp(DpGuid, DpVersion)
382 #
383 # delete from ModDepex the standalone module's dependency
384 #
385 SqlCommand = \
386 """delete from ModDepexInfo where ModDepexInfo.ModuleGuid in
387 (select ModuleGuid from StandaloneModInfo as B where B.DpGuid = '%s'
388 and B.DpVersion = '%s')
389 and ModDepexInfo.ModuleVersion in
390 (select ModuleVersion from StandaloneModInfo as B
391 where B.DpGuid = '%s' and B.DpVersion = '%s')
392 and ModDepexInfo.InstallPath in
393 (select InstallPath from StandaloneModInfo as B
394 where B.DpGuid = '%s' and B.DpVersion = '%s') """ % \
395 (DpGuid, DpVersion, DpGuid, DpVersion, DpGuid, DpVersion)
396
397 self.Cur.execute(SqlCommand)
398 #
399 # delete from ModDepex the from pkg module's dependency
400 #
401 for Pkg in PkgList:
402
403 SqlCommand = \
404 """delete from ModDepexInfo where ModDepexInfo.ModuleGuid in
405 (select ModuleGuid from ModInPkgInfo
406 where ModInPkgInfo.PackageGuid ='%s' and
407 ModInPkgInfo.PackageVersion = '%s')
408 and ModDepexInfo.ModuleVersion in
409 (select ModuleVersion from ModInPkgInfo
410 where ModInPkgInfo.PackageGuid ='%s' and
411 ModInPkgInfo.PackageVersion = '%s')
412 and ModDepexInfo.InstallPath in
413 (select InstallPath from ModInPkgInfo where
414 ModInPkgInfo.PackageGuid ='%s'
415 and ModInPkgInfo.PackageVersion = '%s')""" \
416 % (Pkg[0], Pkg[1],Pkg[0], Pkg[1],Pkg[0], Pkg[1])
417
418 self.Cur.execute(SqlCommand)
419 #
420 # delete the standalone module
421 #
422 SqlCommand = \
423 """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
424 (self.StandaloneModTable, DpGuid, DpVersion)
425 self.Cur.execute(SqlCommand)
426 #
427 # delete the from pkg module
428 #
429 for Pkg in PkgList:
430 SqlCommand = \
431 """delete from %s where %s.PackageGuid ='%s'
432 and %s.PackageVersion = '%s'""" % \
433 (self.ModInPkgTable, self.ModInPkgTable, Pkg[0], \
434 self.ModInPkgTable, Pkg[1])
435 self.Cur.execute(SqlCommand)
436 #
437 # delete packages
438 #
439 SqlCommand = \
440 """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
441 (self.PkgTable, DpGuid, DpVersion)
442 self.Cur.execute(SqlCommand)
443 #
444 # delete file list from DP
445 #
446 SqlCommand = \
447 """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
448 (self.DpFileListTable, DpGuid, DpVersion)
449 self.Cur.execute(SqlCommand)
450 #
451 # delete DP
452 #
453 SqlCommand = \
454 """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
455 (self.DpTable, DpGuid, DpVersion)
456 self.Cur.execute(SqlCommand)
457
458 self.Conn.commit()
459
460 ## Get a list of distribution install information.
461 #
462 # @param Guid: distribution package guid
463 # @param Version: distribution package version
464 #
465 def GetDp(self, Guid, Version):
466
467 if Version == None or len(Version.strip()) == 0:
468 Version = 'N/A'
469 Logger.Verbose(ST.MSG_GET_DP_INSTALL_LIST)
470 (DpGuid, DpVersion) = (Guid, Version)
471 SqlCommand = """select * from %s where DpGuid ='%s'""" % \
472 (self.DpTable, DpGuid)
473 self.Cur.execute(SqlCommand)
474
475 else:
476 Logger.Verbose(ST.MSG_GET_DP_INSTALL_INFO_START)
477 (DpGuid, DpVersion) = (Guid, Version)
478 SqlCommand = \
479 """select * from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
480 (self.DpTable, DpGuid, DpVersion)
481 self.Cur.execute(SqlCommand)
482
483 DpList = []
484 for DpInfo in self.Cur:
485 DpGuid = DpInfo[0]
486 DpVersion = DpInfo[1]
487 InstallTime = DpInfo[2]
488 PkgFileName = DpInfo[3]
489 DpList.append((DpGuid, DpVersion, InstallTime, PkgFileName))
490
491 Logger.Verbose(ST.MSG_GET_DP_INSTALL_INFO_FINISH)
492 return DpList
493
494 ## Get a list of distribution install dirs
495 #
496 # @param Guid: distribution package guid
497 # @param Version: distribution package version
498 #
499 def GetDpInstallDirList(self, Guid, Version):
500 SqlCommand = """select InstallPath from PkgInfo where DpGuid = '%s' and DpVersion = '%s'""" % (Guid, Version)
501 self.Cur.execute(SqlCommand)
502 DirList = []
503 for Result in self.Cur:
504 if Result[0] not in DirList:
505 DirList.append(Result[0])
506
507 SqlCommand = """select InstallPath from StandaloneModInfo where DpGuid = '%s' and DpVersion = '%s'""" % \
508 (Guid, Version)
509 self.Cur.execute(SqlCommand)
510 for Result in self.Cur:
511 if Result[0] not in DirList:
512 DirList.append(Result[0])
513
514 return DirList
515
516
517 ## Get a list of distribution install file path information.
518 #
519 # @param Guid: distribution package guid
520 # @param Version: distribution package version
521 #
522 def GetDpFileList(self, Guid, Version):
523
524 (DpGuid, DpVersion) = (Guid, Version)
525 SqlCommand = \
526 """select * from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
527 (self.DpFileListTable, DpGuid, DpVersion)
528 self.Cur.execute(SqlCommand)
529
530 PathList = []
531 for Result in self.Cur:
532 Path = Result[0]
533 Md5Sum = Result[3]
534 PathList.append((Path, Md5Sum))
535
536 return PathList
537
538 ## Get files' repackage attribute if present that are installed into current workspace
539 #
540 # @retval FileDict: a Dict of file, key is file path, value is (DpGuid, DpVersion, NewDpFileName, RePackage)
541 #
542 def GetRePkgDict(self):
543 SqlCommand = """select * from %s """ % (self.DpTable)
544 self.Cur.execute(SqlCommand)
545
546 DpInfoList = []
547 for Result in self.Cur:
548 DpInfoList.append(Result)
549
550 FileDict = {}
551 for Result in DpInfoList:
552 DpGuid = Result[0]
553 DpVersion = Result[1]
554 NewDpFileName = Result[3]
555 RePackage = Result[5]
556 if RePackage == 'TRUE':
557 RePackage = True
558 else:
559 RePackage = False
560 for FileInfo in self.GetDpFileList(DpGuid, DpVersion):
561 PathInfo = FileInfo[0]
562 FileDict[PathInfo] = DpGuid, DpVersion, NewDpFileName, RePackage
563
564 return FileDict
565
566 ## Get (Guid, Version) from distribution file name information.
567 #
568 # @param DistributionFile: Distribution File
569 #
570 def GetDpByName(self, DistributionFile):
571 SqlCommand = """select * from %s where NewPkgFileName like '%s'""" % \
572 (self.DpTable, '%' + DistributionFile)
573 self.Cur.execute(SqlCommand)
574
575 for Result in self.Cur:
576 DpGuid = Result[0]
577 DpVersion = Result[1]
578 NewDpFileName = Result[3]
579
580 return (DpGuid, DpVersion, NewDpFileName)
581 else:
582 return (None, None, None)
583
584 ## Get a list of package information.
585 #
586 # @param Guid: package guid
587 # @param Version: package version
588 #
589 def GetPackage(self, Guid, Version, DpGuid='', DpVersion=''):
590
591 if DpVersion == '' or DpGuid == '':
592
593 (PackageGuid, PackageVersion) = (Guid, Version)
594 SqlCommand = """select * from %s where PackageGuid ='%s'
595 and PackageVersion = '%s'""" % (self.PkgTable, PackageGuid, \
596 PackageVersion)
597 self.Cur.execute(SqlCommand)
598
599 elif Version == None or len(Version.strip()) == 0:
600
601 SqlCommand = """select * from %s where PackageGuid ='%s'""" % \
602 (self.PkgTable, Guid)
603 self.Cur.execute(SqlCommand)
604 else:
605 (PackageGuid, PackageVersion) = (Guid, Version)
606 SqlCommand = """select * from %s where PackageGuid ='%s' and
607 PackageVersion = '%s'
608 and DpGuid = '%s' and DpVersion = '%s'""" % \
609 (self.PkgTable, PackageGuid, PackageVersion, \
610 DpGuid, DpVersion)
611 self.Cur.execute(SqlCommand)
612
613 PkgList = []
614 for PkgInfo in self.Cur:
615 PkgGuid = PkgInfo[0]
616 PkgVersion = PkgInfo[1]
617 InstallTime = PkgInfo[2]
618 InstallPath = PkgInfo[5]
619 PkgList.append((PkgGuid, PkgVersion, InstallTime, DpGuid, \
620 DpVersion, InstallPath))
621
622 return PkgList
623
624
625 ## Get a list of module in package information.
626 #
627 # @param Guid: A module guid
628 # @param Version: A module version
629 #
630 def GetModInPackage(self, Guid, Version, PkgGuid='', PkgVersion=''):
631
632 if PkgVersion == '' or PkgGuid == '':
633
634 (ModuleGuid, ModuleVersion) = (Guid, Version)
635 SqlCommand = """select * from %s where ModuleGuid ='%s' and
636 ModuleVersion = '%s'""" % (self.ModInPkgTable, ModuleGuid, \
637 ModuleVersion)
638 self.Cur.execute(SqlCommand)
639
640 else:
641 (ModuleGuid, ModuleVersion) = (Guid, Version)
642 SqlCommand = """select * from %s where ModuleGuid ='%s' and
643 ModuleVersion = '%s' and PackageGuid ='%s'
644 and PackageVersion = '%s'
645 """ % (self.ModInPkgTable, ModuleGuid, \
646 ModuleVersion, PkgGuid, PkgVersion)
647 self.Cur.execute(SqlCommand)
648
649 ModList = []
650 for ModInfo in self.Cur:
651 ModGuid = ModInfo[0]
652 ModVersion = ModInfo[1]
653 InstallTime = ModInfo[2]
654 InstallPath = ModInfo[5]
655 ModList.append((ModGuid, ModVersion, InstallTime, PkgGuid, \
656 PkgVersion, InstallPath))
657
658 return ModList
659
660 ## Get a list of module standalone.
661 #
662 # @param Guid: A module guid
663 # @param Version: A module version
664 #
665 def GetStandaloneModule(self, Guid, Version, DpGuid='', DpVersion=''):
666
667 if DpGuid == '':
668 (ModuleGuid, ModuleVersion) = (Guid, Version)
669 SqlCommand = """select * from %s where ModuleGuid ='%s' and
670 ModuleVersion = '%s'""" % (self.StandaloneModTable, ModuleGuid, \
671 ModuleVersion)
672 self.Cur.execute(SqlCommand)
673
674 else:
675 (ModuleGuid, ModuleVersion) = (Guid, Version)
676 SqlCommand = """select * from %s where ModuleGuid ='%s' and
677 ModuleVersion = '%s' and DpGuid ='%s' and DpVersion = '%s'
678 """ % (self.StandaloneModTable, ModuleGuid, \
679 ModuleVersion, DpGuid, DpVersion)
680 self.Cur.execute(SqlCommand)
681
682 ModList = []
683 for ModInfo in self.Cur:
684 ModGuid = ModInfo[0]
685 ModVersion = ModInfo[1]
686 InstallTime = ModInfo[2]
687 InstallPath = ModInfo[5]
688 ModList.append((ModGuid, ModVersion, InstallTime, DpGuid, \
689 DpVersion, InstallPath))
690
691 return ModList
692
693 ## Get a list of module information that comes from DP.
694 #
695 # @param DpGuid: A Distrabution Guid
696 # @param DpVersion: A Distrabution version
697 #
698 def GetSModInsPathListFromDp(self, DpGuid, DpVersion):
699
700 PathList = []
701 SqlCommand = """select InstallPath from %s where DpGuid ='%s'
702 and DpVersion = '%s'
703 """ % (self.StandaloneModTable, DpGuid, DpVersion)
704 self.Cur.execute(SqlCommand)
705
706 for Result in self.Cur:
707 InstallPath = Result[0]
708 PathList.append(InstallPath)
709
710 return PathList
711
712 ## Get a list of package information.
713 #
714 # @param DpGuid: A Distrabution Guid
715 # @param DpVersion: A Distrabution version
716 #
717 def GetPackageListFromDp(self, DpGuid, DpVersion):
718
719 SqlCommand = """select * from %s where DpGuid ='%s' and
720 DpVersion = '%s' """ % (self.PkgTable, DpGuid, DpVersion)
721 self.Cur.execute(SqlCommand)
722
723 PkgList = []
724 for PkgInfo in self.Cur:
725 PkgGuid = PkgInfo[0]
726 PkgVersion = PkgInfo[1]
727 InstallPath = PkgInfo[5]
728 PkgList.append((PkgGuid, PkgVersion, InstallPath))
729
730 return PkgList
731
732 ## Get a list of modules that depends on package information from a DP.
733 #
734 # @param DpGuid: A Distrabution Guid
735 # @param DpVersion: A Distrabution version
736 #
737 def GetDpDependentModuleList(self, DpGuid, DpVersion):
738
739 ModList = []
740 PkgList = self.GetPackageListFromDp(DpGuid, DpVersion)
741 if len(PkgList) > 0:
742 return ModList
743
744 for Pkg in PkgList:
745 #
746 # get all in-package modules that depends on current
747 # Pkg (Guid match, Version match or NA) but not belong to
748 # current Pkg
749 #
750 SqlCommand = """select t1.ModuleGuid, t1.ModuleVersion,
751 t1.InstallPath from %s as t1, %s as t2 where
752 t1.ModuleGuid = t2.ModuleGuid and
753 t1.ModuleVersion = t2.ModuleVersion and t2.DepexGuid ='%s'
754 and (t2.DepexVersion = '%s' or t2.DepexVersion = 'N/A') and
755 t1.PackageGuid != '%s' and t1.PackageVersion != '%s'
756 """ % (self.ModInPkgTable, \
757 self.ModDepexTable, Pkg[0], Pkg[1], Pkg[0], \
758 Pkg[1])
759 self.Cur.execute(SqlCommand)
760 for ModInfo in self.Cur:
761 ModGuid = ModInfo[0]
762 ModVersion = ModInfo[1]
763 InstallPath = ModInfo[2]
764 ModList.append((ModGuid, ModVersion, InstallPath))
765
766 #
767 # get all modules from standalone modules that depends on current
768 #Pkg (Guid match, Version match or NA) but not in current dp
769 #
770 SqlCommand = \
771 """select t1.ModuleGuid, t1.ModuleVersion, t1.InstallPath
772 from %s as t1, %s as t2 where t1.ModuleGuid = t2.ModuleGuid and
773 t1.ModuleVersion = t2.ModuleVersion and t2.DepexGuid ='%s'
774 and (t2.DepexVersion = '%s' or t2.DepexVersion = 'N/A') and
775 t1.DpGuid != '%s' and t1.DpVersion != '%s'
776 """ % \
777 (self.StandaloneModTable, self.ModDepexTable, Pkg[0], \
778 Pkg[1], DpGuid, DpVersion)
779 self.Cur.execute(SqlCommand)
780 for ModInfo in self.Cur:
781 ModGuid = ModInfo[0]
782 ModVersion = ModInfo[1]
783 InstallPath = ModInfo[2]
784 ModList.append((ModGuid, ModVersion, InstallPath))
785
786
787 return ModList
788
789 ## Get Dp's list of modules.
790 #
791 # @param DpGuid: A Distrabution Guid
792 # @param DpVersion: A Distrabution version
793 #
794 def GetDpModuleList(self, DpGuid, DpVersion):
795 ModList = []
796 #
797 # get Dp module list from the DpFileList table
798 #
799 SqlCommand = """select FilePath
800 from %s
801 where DpGuid = '%s' and DpVersion = '%s' and
802 FilePath like '%%.inf'
803 """ % (self.DpFileListTable, DpGuid, DpVersion)
804 self.Cur.execute(SqlCommand)
805 for ModuleInfo in self.Cur:
806 FilePath = ModuleInfo[0]
807 ModList.append(FilePath)
808
809 return ModList
810
811
812 ## Get a module depex
813 #
814 # @param DpGuid: A module Guid
815 # @param DpVersion: A module version
816 # @param Path:
817 #
818 def GetModuleDepex(self, Guid, Version, Path):
819
820 #
821 # Get module depex information to DB.
822 #
823 SqlCommand = """select * from %s where ModuleGuid ='%s' and
824 ModuleVersion = '%s' and InstallPath ='%s'
825 """ % (self.ModDepexTable, Guid, Version, Path)
826 self.Cur.execute(SqlCommand)
827 self.Conn.commit()
828
829 DepexList = []
830 for DepInfo in self.Cur:
831 DepexGuid = DepInfo[3]
832 DepexVersion = DepInfo[4]
833 DepexList.append((DepexGuid, DepexVersion))
834
835 return DepexList
836
837 ## Close entire database
838 #
839 # Close the connection and cursor
840 #
841 def CloseDb(self):
842 #
843 # drop the dummy table
844 #
845 SqlCommand = """
846 drop table IF EXISTS %s
847 """ % self.DummyTable
848 self.Cur.execute(SqlCommand)
849 self.Conn.commit()
850
851 self.Cur.close()
852 self.Conn.close()
853
854 ## Convert To Sql String
855 #
856 # 1. Replace "'" with "''" in each item of StringList
857 #
858 # @param StringList: A list for strings to be converted
859 #
860 def __ConvertToSqlString(self, StringList):
861 if self.DpTable:
862 pass
863 return map(lambda s: s.replace("'", "''") , StringList)
864
865
866
867