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