2 # This file is for installed package information database operations
4 # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
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
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.
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
33 # This class represents the installed package information database
34 # Add/Remove/Get installed distribution package information here.
37 # @param object: Inherited from object class
38 # @param DbPath: A string for the path of the database
41 class IpiDatabase(object):
42 def __init__(self
, DbPath
):
43 Dir
= os
.path
.dirname(DbPath
)
44 if not os
.path
.isdir(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'
58 ## Initialize build database
61 def InitDatabase(self
, SkipLock
= False):
62 Logger
.Verbose(ST
.MSG_INIT_IPI_START
)
66 # Create a dummy table, if already existed,
67 # then UPT is already running
73 )""" % self
.DummyTable
74 self
.Cur
.execute(SqlCommand
)
76 except sqlite3
.OperationalError
:
78 UPT_ALREADY_RUNNING_ERROR
,
79 ST
.ERR_UPT_ALREADY_RUNNING_ERROR
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)
94 self
.Cur
.execute(SqlCommand
)
97 create table IF NOT EXISTS %s (
98 FilePath TEXT NOT NULL,
102 PRIMARY KEY (FilePath)
103 )""" % self
.DpFileListTable
104 self
.Cur
.execute(SqlCommand
)
107 create table IF NOT EXISTS %s (
108 PackageGuid TEXT NOT NULL,
109 PackageVersion TEXT NOT NULL,
110 InstallTime REAL NOT NULL,
113 InstallPath TEXT NOT NULL,
114 PRIMARY KEY (PackageGuid, PackageVersion, InstallPath)
116 self
.Cur
.execute(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,
126 InstallPath TEXT NOT NULL,
127 PRIMARY KEY (ModuleGuid, ModuleVersion, ModuleName, InstallPath)
128 )""" % self
.ModInPkgTable
129 self
.Cur
.execute(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,
139 InstallPath TEXT NOT NULL,
140 PRIMARY KEY (ModuleGuid, ModuleVersion, ModuleName, InstallPath)
141 )""" % self
.StandaloneModTable
142 self
.Cur
.execute(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,
152 )""" % self
.ModDepexTable
153 self
.Cur
.execute(SqlCommand
)
157 Logger
.Verbose(ST
.MSG_INIT_IPI_FINISH
)
159 ## Add a distribution install information from DpObj
162 # @param NewDpPkgFileName: New DpPkg File Name
163 # @param DpPkgFileName: DpPkg File Name
164 # @param RePackage: A RePackage
166 def AddDPObject(self
, DpObj
, NewDpPkgFileName
, DpPkgFileName
, RePackage
):
168 for PkgKey
in DpObj
.PackageSurfaceArea
.keys():
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():
177 ModVersion
= ModKey
[1]
179 ModInstallPath
= ModKey
[3]
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
, \
195 for ModKey
in DpObj
.ModuleSurfaceArea
.keys():
197 ModVersion
= ModKey
[1]
199 ModInstallPath
= ModKey
[3]
200 self
._AddStandaloneModule
(ModGuid
, ModVersion
, ModName
, \
201 DpObj
.Header
.GetGuid(), \
202 DpObj
.Header
.GetVersion(), \
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(), \
216 # add tool/misc files
218 for (Path
, Md5Sum
) in DpObj
.FileList
:
219 self
._AddDpFilePathList
(DpObj
.Header
.GetGuid(), \
220 DpObj
.Header
.GetVersion(), Path
, Md5Sum
)
222 self
._AddDp
(DpObj
.Header
.GetGuid(), DpObj
.Header
.GetVersion(), \
223 NewDpPkgFileName
, DpPkgFileName
, RePackage
)
226 except sqlite3
.IntegrityError
, DetailMsg
:
229 ST
.ERR_UPT_DB_UPDATE_ERROR
,
230 ExtraData
= DetailMsg
233 ## Add a distribution install information
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
240 def _AddDp(self
, Guid
, Version
, NewDpFileName
, DistributionFileName
, \
243 if Version
== None or len(Version
.strip()) == 0:
247 # Add newly installed DP information to DB.
249 if NewDpFileName
== None or len(NewDpFileName
.strip()) == 0:
252 PkgFileName
= NewDpFileName
253 CurrentTime
= time
.time()
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
)
261 ## Add a file list from DP
263 # @param DpGuid: A DpGuid
264 # @param DpVersion: A DpVersion
265 # @param Path: A Path
266 # @param Path: A Md5Sum
268 def _AddDpFilePathList(self
, DpGuid
, DpVersion
, Path
, Md5Sum
):
270 SqlCommand
= """insert into %s values('%s', '%s', '%s', '%s')""" % \
271 (self
.DpFileListTable
, Path
, DpGuid
, DpVersion
, Md5Sum
)
273 self
.Cur
.execute(SqlCommand
)
275 ## Add a package install information
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
283 def _AddPackage(self
, Guid
, Version
, DpGuid
=None, DpVersion
=None, Path
=''):
285 if Version
== None or len(Version
.strip()) == 0:
288 if DpGuid
== None or len(DpGuid
.strip()) == 0:
291 if DpVersion
== None or len(DpVersion
.strip()) == 0:
295 # Add newly installed package information to DB.
297 CurrentTime
= time
.time()
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
)
303 ## Add a module that from a package install information
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
312 def _AddModuleInPackage(self
, Guid
, Version
, Name
, PkgGuid
=None, \
313 PkgVersion
=None, Path
=''):
315 if Version
== None or len(Version
.strip()) == 0:
318 if PkgGuid
== None or len(PkgGuid
.strip()) == 0:
321 if PkgVersion
== None or len(PkgVersion
.strip()) == 0:
325 # Add module from package information to DB.
327 CurrentTime
= time
.time()
329 """insert into %s values('%s', '%s', '%s', %s, '%s', '%s', '%s')""" % \
330 (self
.ModInPkgTable
, Guid
, Version
, Name
, CurrentTime
, PkgGuid
, PkgVersion
, \
332 self
.Cur
.execute(SqlCommand
)
334 ## Add a module that is standalone install information
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
343 def _AddStandaloneModule(self
, Guid
, Version
, Name
, DpGuid
=None, \
344 DpVersion
=None, Path
=''):
346 if Version
== None or len(Version
.strip()) == 0:
349 if DpGuid
== None or len(DpGuid
.strip()) == 0:
352 if DpVersion
== None or len(DpVersion
.strip()) == 0:
356 # Add module standalone information to DB.
358 CurrentTime
= time
.time()
360 """insert into %s values('%s', '%s', '%s', %s, '%s', '%s', '%s')""" % \
361 (self
.StandaloneModTable
, Guid
, Version
, Name
, CurrentTime
, DpGuid
, \
363 self
.Cur
.execute(SqlCommand
)
365 ## Add a module depex
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
373 def _AddModuleDepex(self
, Guid
, Version
, Name
, Path
, DepexGuid
=None, \
376 if DepexGuid
== None or len(DepexGuid
.strip()) == 0:
379 if DepexVersion
== None or len(DepexVersion
.strip()) == 0:
383 # Add module depex information to DB.
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
)
389 ## Remove a distribution install information, if no version specified,
390 # remove all DPs with this Guid.
392 # @param DpGuid: guid of dpex
393 # @param DpVersion: version of dpex
395 def RemoveDpObj(self
, DpGuid
, DpVersion
):
397 PkgList
= self
.GetPackageListFromDp(DpGuid
, DpVersion
)
399 # delete from ModDepex the standalone module's dependency
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
)
416 self
.Cur
.execute(SqlCommand
)
418 # delete from ModDepex the from pkg module's dependency
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])
441 self
.Cur
.execute(SqlCommand
)
443 # delete the standalone module
446 """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
447 (self
.StandaloneModTable
, DpGuid
, DpVersion
)
448 self
.Cur
.execute(SqlCommand
)
450 # delete the from pkg module
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
)
463 """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
464 (self
.PkgTable
, DpGuid
, DpVersion
)
465 self
.Cur
.execute(SqlCommand
)
467 # delete file list from DP
470 """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
471 (self
.DpFileListTable
, DpGuid
, DpVersion
)
472 self
.Cur
.execute(SqlCommand
)
477 """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
478 (self
.DpTable
, DpGuid
, DpVersion
)
479 self
.Cur
.execute(SqlCommand
)
483 ## Get a list of distribution install information.
485 # @param Guid: distribution package guid
486 # @param Version: distribution package version
488 def GetDp(self
, Guid
, Version
):
490 if Version
== None or len(Version
.strip()) == 0:
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
)
499 Logger
.Verbose(ST
.MSG_GET_DP_INSTALL_INFO_START
)
500 (DpGuid
, DpVersion
) = (Guid
, Version
)
502 """select * from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
503 (self
.DpTable
, DpGuid
, DpVersion
)
504 self
.Cur
.execute(SqlCommand
)
507 for DpInfo
in self
.Cur
:
509 DpVersion
= DpInfo
[1]
510 InstallTime
= DpInfo
[2]
511 PkgFileName
= DpInfo
[3]
512 DpList
.append((DpGuid
, DpVersion
, InstallTime
, PkgFileName
))
514 Logger
.Verbose(ST
.MSG_GET_DP_INSTALL_INFO_FINISH
)
517 ## Get a list of distribution install dirs
519 # @param Guid: distribution package guid
520 # @param Version: distribution package version
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
)
526 for Result
in self
.Cur
:
527 if Result
[0] not in DirList
:
528 DirList
.append(Result
[0])
530 SqlCommand
= """select InstallPath from StandaloneModInfo where DpGuid = '%s' and DpVersion = '%s'""" % \
532 self
.Cur
.execute(SqlCommand
)
533 for Result
in self
.Cur
:
534 if Result
[0] not in DirList
:
535 DirList
.append(Result
[0])
540 ## Get a list of distribution install file path information.
542 # @param Guid: distribution package guid
543 # @param Version: distribution package version
545 def GetDpFileList(self
, Guid
, Version
):
547 (DpGuid
, DpVersion
) = (Guid
, Version
)
549 """select * from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
550 (self
.DpFileListTable
, DpGuid
, DpVersion
)
551 self
.Cur
.execute(SqlCommand
)
554 for Result
in self
.Cur
:
557 PathList
.append((Path
, Md5Sum
))
561 ## Get files' repackage attribute if present that are installed into current workspace
563 # @retval FileDict: a Dict of file, key is file path, value is (DpGuid, DpVersion, NewDpFileName, RePackage)
565 def GetRePkgDict(self
):
566 SqlCommand
= """select * from %s """ % (self
.DpTable
)
567 self
.Cur
.execute(SqlCommand
)
570 for Result
in self
.Cur
:
571 DpInfoList
.append(Result
)
574 for Result
in DpInfoList
:
576 DpVersion
= Result
[1]
577 NewDpFileName
= Result
[3]
578 RePackage
= Result
[5]
579 if RePackage
== 'TRUE':
583 for FileInfo
in self
.GetDpFileList(DpGuid
, DpVersion
):
584 PathInfo
= FileInfo
[0]
585 FileDict
[PathInfo
] = DpGuid
, DpVersion
, NewDpFileName
, RePackage
589 ## Get (Guid, Version) from distribution file name information.
591 # @param DistributionFile: Distribution File
593 def GetDpByName(self
, DistributionFile
):
594 SqlCommand
= """select * from %s where NewPkgFileName like '%s'""" % \
595 (self
.DpTable
, '%' + DistributionFile
)
596 self
.Cur
.execute(SqlCommand
)
598 for Result
in self
.Cur
:
600 DpVersion
= Result
[1]
601 NewDpFileName
= Result
[3]
603 return (DpGuid
, DpVersion
, NewDpFileName
)
605 return (None, None, None)
607 ## Get a list of package information.
609 # @param Guid: package guid
610 # @param Version: package version
612 def GetPackage(self
, Guid
, Version
, DpGuid
='', DpVersion
=''):
614 if DpVersion
== '' or DpGuid
== '':
616 (PackageGuid
, PackageVersion
) = (Guid
, Version
)
617 SqlCommand
= """select * from %s where PackageGuid ='%s'
618 and PackageVersion = '%s'""" % (self
.PkgTable
, PackageGuid
, \
620 self
.Cur
.execute(SqlCommand
)
622 elif Version
== None or len(Version
.strip()) == 0:
624 SqlCommand
= """select * from %s where PackageGuid ='%s'""" % \
625 (self
.PkgTable
, Guid
)
626 self
.Cur
.execute(SqlCommand
)
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
, \
634 self
.Cur
.execute(SqlCommand
)
637 for PkgInfo
in self
.Cur
:
639 PkgVersion
= PkgInfo
[1]
640 InstallTime
= PkgInfo
[2]
641 InstallPath
= PkgInfo
[5]
642 PkgList
.append((PkgGuid
, PkgVersion
, InstallTime
, DpGuid
, \
643 DpVersion
, InstallPath
))
648 ## Get a list of module in package information.
650 # @param Guid: A module guid
651 # @param Version: A module version
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
)
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
)
671 for ModInfo
in self
.Cur
:
673 ModVersion
= ModInfo
[1]
674 InstallTime
= ModInfo
[2]
675 InstallPath
= ModInfo
[5]
676 ModList
.append((ModGuid
, ModVersion
, InstallTime
, PkgGuid
, \
677 PkgVersion
, InstallPath
))
681 ## Get a list of module standalone.
683 # @param Guid: A module guid
684 # @param Version: A module version
686 def GetStandaloneModule(self
, Guid
, Version
, Name
, Path
, DpGuid
='', DpVersion
=''):
687 (ModuleGuid
, ModuleVersion
, ModuleName
, InstallPath
) = (Guid
, Version
, Name
, Path
)
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
)
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
)
703 for ModInfo
in self
.Cur
:
705 ModVersion
= ModInfo
[1]
706 InstallTime
= ModInfo
[2]
707 InstallPath
= ModInfo
[5]
708 ModList
.append((ModGuid
, ModVersion
, InstallTime
, DpGuid
, \
709 DpVersion
, InstallPath
))
713 ## Get a list of module information that comes from DP.
715 # @param DpGuid: A Distrabution Guid
716 # @param DpVersion: A Distrabution version
718 def GetSModInsPathListFromDp(self
, DpGuid
, DpVersion
):
721 SqlCommand
= """select InstallPath from %s where DpGuid ='%s'
723 """ % (self
.StandaloneModTable
, DpGuid
, DpVersion
)
724 self
.Cur
.execute(SqlCommand
)
726 for Result
in self
.Cur
:
727 InstallPath
= Result
[0]
728 PathList
.append(InstallPath
)
732 ## Get a list of package information.
734 # @param DpGuid: A Distrabution Guid
735 # @param DpVersion: A Distrabution version
737 def GetPackageListFromDp(self
, DpGuid
, DpVersion
):
739 SqlCommand
= """select * from %s where DpGuid ='%s' and
740 DpVersion = '%s' """ % (self
.PkgTable
, DpGuid
, DpVersion
)
741 self
.Cur
.execute(SqlCommand
)
744 for PkgInfo
in self
.Cur
:
746 PkgVersion
= PkgInfo
[1]
747 InstallPath
= PkgInfo
[5]
748 PkgList
.append((PkgGuid
, PkgVersion
, InstallPath
))
752 ## Get a list of modules that depends on package information from a DP.
754 # @param DpGuid: A Distrabution Guid
755 # @param DpVersion: A Distrabution version
757 def GetDpDependentModuleList(self
, DpGuid
, DpVersion
):
760 PkgList
= self
.GetPackageListFromDp(DpGuid
, DpVersion
)
766 # get all in-package modules that depends on current
767 # Pkg (Guid match, Version match or NA) but not belong to
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], \
779 self
.Cur
.execute(SqlCommand
)
780 for ModInfo
in self
.Cur
:
782 ModVersion
= ModInfo
[1]
783 InstallPath
= ModInfo
[2]
784 ModList
.append((ModGuid
, ModVersion
, InstallPath
))
787 # get all modules from standalone modules that depends on current
788 #Pkg (Guid match, Version match or NA) but not in current dp
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'
797 (self
.StandaloneModTable
, self
.ModDepexTable
, Pkg
[0], \
798 Pkg
[1], DpGuid
, DpVersion
)
799 self
.Cur
.execute(SqlCommand
)
800 for ModInfo
in self
.Cur
:
802 ModVersion
= ModInfo
[1]
803 InstallPath
= ModInfo
[2]
804 ModList
.append((ModGuid
, ModVersion
, InstallPath
))
809 ## Get Dp's list of modules.
811 # @param DpGuid: A Distrabution Guid
812 # @param DpVersion: A Distrabution version
814 def GetDpModuleList(self
, DpGuid
, DpVersion
):
817 # get Dp module list from the DpFileList table
819 SqlCommand
= """select FilePath
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
)
832 ## Get a module depex
834 # @param DpGuid: A module Guid
835 # @param DpVersion: A module version
838 def GetModuleDepex(self
, Guid
, Version
, Path
):
841 # Get module depex information to DB.
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
)
850 for DepInfo
in self
.Cur
:
851 DepexGuid
= DepInfo
[3]
852 DepexVersion
= DepInfo
[4]
853 DepexList
.append((DepexGuid
, DepexVersion
))
857 ## Close entire database
859 # Close the connection and cursor
863 # drop the dummy table
866 drop table IF EXISTS %s
867 """ % self
.DummyTable
868 self
.Cur
.execute(SqlCommand
)
874 ## Convert To Sql String
876 # 1. Replace "'" with "''" in each item of StringList
878 # @param StringList: A list for strings to be converted
880 def __ConvertToSqlString(self
, StringList
):
883 return map(lambda s
: s
.replace("'", "''") , StringList
)