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
32 # This class represents the installed package information database
33 # Add/Remove/Get installed distribution package information here.
36 # @param object: Inherited from object class
37 # @param DbPath: A string for the path of the database
40 class IpiDatabase(object):
41 def __init__(self
, DbPath
):
42 Dir
= os
.path
.dirname(DbPath
)
43 if not os
.path
.isdir(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'
57 ## Initialize build database
60 def InitDatabase(self
, SkipLock
= False):
61 Logger
.Verbose(ST
.MSG_INIT_IPI_START
)
65 # Create a dummy table, if already existed,
66 # then UPT is already running
72 )""" % self
.DummyTable
73 self
.Cur
.execute(SqlCommand
)
75 except sqlite3
.OperationalError
:
77 UPT_ALREADY_RUNNING_ERROR
,
78 ST
.ERR_UPT_ALREADY_RUNNING_ERROR
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)
93 self
.Cur
.execute(SqlCommand
)
96 create table IF NOT EXISTS %s (
97 FilePath TEXT NOT NULL,
101 PRIMARY KEY (FilePath)
102 )""" % self
.DpFileListTable
103 self
.Cur
.execute(SqlCommand
)
106 create table IF NOT EXISTS %s (
107 PackageGuid TEXT NOT NULL,
108 PackageVersion TEXT NOT NULL,
109 InstallTime REAL NOT NULL,
112 InstallPath TEXT NOT NULL,
113 PRIMARY KEY (PackageGuid, PackageVersion, InstallPath)
115 self
.Cur
.execute(SqlCommand
)
118 create table IF NOT EXISTS %s (
119 ModuleGuid TEXT NOT NULL,
120 ModuleVersion TEXT NOT NULL,
121 InstallTime REAL NOT NULL,
124 InstallPath TEXT NOT NULL,
125 PRIMARY KEY (ModuleGuid, ModuleVersion, InstallPath)
126 )""" % self
.ModInPkgTable
127 self
.Cur
.execute(SqlCommand
)
130 create table IF NOT EXISTS %s (
131 ModuleGuid TEXT NOT NULL,
132 ModuleVersion TEXT NOT NULL,
133 InstallTime REAL NOT NULL,
136 InstallPath TEXT NOT NULL,
137 PRIMARY KEY (ModuleGuid, ModuleVersion, InstallPath)
138 )""" % self
.StandaloneModTable
139 self
.Cur
.execute(SqlCommand
)
142 create table IF NOT EXISTS %s (
143 ModuleGuid TEXT NOT NULL,
144 ModuleVersion TEXT NOT NULL,
145 InstallPath TEXT NOT NULL,
148 )""" % self
.ModDepexTable
149 self
.Cur
.execute(SqlCommand
)
153 Logger
.Verbose(ST
.MSG_INIT_IPI_FINISH
)
155 ## Add a distribution install information from DpObj
158 # @param NewDpPkgFileName: New DpPkg File Name
159 # @param DpPkgFileName: DpPkg File Name
160 # @param RePackage: A RePackage
162 def AddDPObject(self
, DpObj
, NewDpPkgFileName
, DpPkgFileName
, RePackage
):
164 for PkgKey
in DpObj
.PackageSurfaceArea
.keys():
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():
173 ModVersion
= ModKey
[1]
174 ModInstallPath
= ModKey
[2]
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
, \
190 for ModKey
in DpObj
.ModuleSurfaceArea
.keys():
192 ModVersion
= ModKey
[1]
193 ModInstallPath
= ModKey
[2]
194 self
._AddStandaloneModule
(ModGuid
, ModVersion
, \
195 DpObj
.Header
.GetGuid(), \
196 DpObj
.Header
.GetVersion(), \
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(), \
210 # add tool/misc files
212 for (Path
, Md5Sum
) in DpObj
.FileList
:
213 self
._AddDpFilePathList
(DpObj
.Header
.GetGuid(), \
214 DpObj
.Header
.GetVersion(), Path
, Md5Sum
)
216 self
._AddDp
(DpObj
.Header
.GetGuid(), DpObj
.Header
.GetVersion(), \
217 NewDpPkgFileName
, DpPkgFileName
, RePackage
)
221 ## Add a distribution install information
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
228 def _AddDp(self
, Guid
, Version
, NewDpFileName
, DistributionFileName
, \
231 if Version
== None or len(Version
.strip()) == 0:
235 # Add newly installed DP information to DB.
237 if NewDpFileName
== None or len(NewDpFileName
.strip()) == 0:
240 PkgFileName
= NewDpFileName
241 CurrentTime
= time
.time()
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
)
249 ## Add a file list from DP
251 # @param DpGuid: A DpGuid
252 # @param DpVersion: A DpVersion
253 # @param Path: A Path
254 # @param Path: A Md5Sum
256 def _AddDpFilePathList(self
, DpGuid
, DpVersion
, Path
, Md5Sum
):
258 SqlCommand
= """insert into %s values('%s', '%s', '%s', '%s')""" % \
259 (self
.DpFileListTable
, Path
, DpGuid
, DpVersion
, Md5Sum
)
261 self
.Cur
.execute(SqlCommand
)
263 ## Add a package install information
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
271 def _AddPackage(self
, Guid
, Version
, DpGuid
=None, DpVersion
=None, Path
=''):
273 if Version
== None or len(Version
.strip()) == 0:
276 if DpGuid
== None or len(DpGuid
.strip()) == 0:
279 if DpVersion
== None or len(DpVersion
.strip()) == 0:
283 # Add newly installed package information to DB.
285 CurrentTime
= time
.time()
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
)
291 ## Add a module that from a package install information
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
298 def _AddModuleInPackage(self
, Guid
, Version
, PkgGuid
=None, \
299 PkgVersion
=None, Path
=''):
301 if Version
== None or len(Version
.strip()) == 0:
304 if PkgGuid
== None or len(PkgGuid
.strip()) == 0:
307 if PkgVersion
== None or len(PkgVersion
.strip()) == 0:
311 # Add module from package information to DB.
313 CurrentTime
= time
.time()
315 """insert into %s values('%s', '%s', %s, '%s', '%s', '%s')""" % \
316 (self
.ModInPkgTable
, Guid
, Version
, CurrentTime
, PkgGuid
, PkgVersion
, \
318 self
.Cur
.execute(SqlCommand
)
320 ## Add a module that is standalone install information
322 # @param Guid: a module Guid
323 # @param Version: a module Version
324 # @param DpGuid: a DpGuid
325 # @param DpVersion: a DpVersion
328 def _AddStandaloneModule(self
, Guid
, Version
, DpGuid
=None, \
329 DpVersion
=None, Path
=''):
331 if Version
== None or len(Version
.strip()) == 0:
334 if DpGuid
== None or len(DpGuid
.strip()) == 0:
337 if DpVersion
== None or len(DpVersion
.strip()) == 0:
341 # Add module standalone information to DB.
343 CurrentTime
= time
.time()
345 """insert into %s values('%s', '%s', %s, '%s', '%s', '%s')""" % \
346 (self
.StandaloneModTable
, Guid
, Version
, CurrentTime
, DpGuid
, \
348 self
.Cur
.execute(SqlCommand
)
350 ## Add a module depex
352 # @param Guid: a module Guid
353 # @param Version: a module Version
354 # @param DepexGuid: a module DepexGuid
355 # @param DepexVersion: a module DepexVersion
357 def _AddModuleDepex(self
, Guid
, Version
, Path
, DepexGuid
=None, \
360 if DepexGuid
== None or len(DepexGuid
.strip()) == 0:
363 if DepexVersion
== None or len(DepexVersion
.strip()) == 0:
367 # Add module depex information to DB.
369 SqlCommand
= """insert into %s values('%s', '%s', '%s', '%s', '%s')"""\
370 % (self
.ModDepexTable
, Guid
, Version
, Path
, DepexGuid
, DepexVersion
)
371 self
.Cur
.execute(SqlCommand
)
373 ## Remove a distribution install information, if no version specified,
374 # remove all DPs with this Guid.
376 # @param DpGuid: guid of dpex
377 # @param DpVersion: version of dpex
379 def RemoveDpObj(self
, DpGuid
, DpVersion
):
381 PkgList
= self
.GetPackageListFromDp(DpGuid
, DpVersion
)
383 # delete from ModDepex the standalone module's dependency
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
)
397 self
.Cur
.execute(SqlCommand
)
399 # delete from ModDepex the from pkg module's dependency
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])
418 self
.Cur
.execute(SqlCommand
)
420 # delete the standalone module
423 """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
424 (self
.StandaloneModTable
, DpGuid
, DpVersion
)
425 self
.Cur
.execute(SqlCommand
)
427 # delete the from pkg module
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
)
440 """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
441 (self
.PkgTable
, DpGuid
, DpVersion
)
442 self
.Cur
.execute(SqlCommand
)
444 # delete file list from DP
447 """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
448 (self
.DpFileListTable
, DpGuid
, DpVersion
)
449 self
.Cur
.execute(SqlCommand
)
454 """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
455 (self
.DpTable
, DpGuid
, DpVersion
)
456 self
.Cur
.execute(SqlCommand
)
460 ## Get a list of distribution install information.
462 # @param Guid: distribution package guid
463 # @param Version: distribution package version
465 def GetDp(self
, Guid
, Version
):
467 if Version
== None or len(Version
.strip()) == 0:
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
)
476 Logger
.Verbose(ST
.MSG_GET_DP_INSTALL_INFO_START
)
477 (DpGuid
, DpVersion
) = (Guid
, Version
)
479 """select * from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
480 (self
.DpTable
, DpGuid
, DpVersion
)
481 self
.Cur
.execute(SqlCommand
)
484 for DpInfo
in self
.Cur
:
486 DpVersion
= DpInfo
[1]
487 InstallTime
= DpInfo
[2]
488 PkgFileName
= DpInfo
[3]
489 DpList
.append((DpGuid
, DpVersion
, InstallTime
, PkgFileName
))
491 Logger
.Verbose(ST
.MSG_GET_DP_INSTALL_INFO_FINISH
)
494 ## Get a list of distribution install dirs
496 # @param Guid: distribution package guid
497 # @param Version: distribution package version
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
)
503 for Result
in self
.Cur
:
504 if Result
[0] not in DirList
:
505 DirList
.append(Result
[0])
507 SqlCommand
= """select InstallPath from StandaloneModInfo where DpGuid = '%s' and DpVersion = '%s'""" % \
509 self
.Cur
.execute(SqlCommand
)
510 for Result
in self
.Cur
:
511 if Result
[0] not in DirList
:
512 DirList
.append(Result
[0])
517 ## Get a list of distribution install file path information.
519 # @param Guid: distribution package guid
520 # @param Version: distribution package version
522 def GetDpFileList(self
, Guid
, Version
):
524 (DpGuid
, DpVersion
) = (Guid
, Version
)
526 """select * from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
527 (self
.DpFileListTable
, DpGuid
, DpVersion
)
528 self
.Cur
.execute(SqlCommand
)
531 for Result
in self
.Cur
:
534 PathList
.append((Path
, Md5Sum
))
538 ## Get files' repackage attribute if present that are installed into current workspace
540 # @retval FileDict: a Dict of file, key is file path, value is (DpGuid, DpVersion, NewDpFileName, RePackage)
542 def GetRePkgDict(self
):
543 SqlCommand
= """select * from %s """ % (self
.DpTable
)
544 self
.Cur
.execute(SqlCommand
)
547 for Result
in self
.Cur
:
548 DpInfoList
.append(Result
)
551 for Result
in DpInfoList
:
553 DpVersion
= Result
[1]
554 NewDpFileName
= Result
[3]
555 RePackage
= Result
[5]
556 if RePackage
== 'TRUE':
560 for FileInfo
in self
.GetDpFileList(DpGuid
, DpVersion
):
561 PathInfo
= FileInfo
[0]
562 FileDict
[PathInfo
] = DpGuid
, DpVersion
, NewDpFileName
, RePackage
566 ## Get (Guid, Version) from distribution file name information.
568 # @param DistributionFile: Distribution File
570 def GetDpByName(self
, DistributionFile
):
571 SqlCommand
= """select * from %s where NewPkgFileName like '%s'""" % \
572 (self
.DpTable
, '%' + DistributionFile
)
573 self
.Cur
.execute(SqlCommand
)
575 for Result
in self
.Cur
:
577 DpVersion
= Result
[1]
578 NewDpFileName
= Result
[3]
580 return (DpGuid
, DpVersion
, NewDpFileName
)
582 return (None, None, None)
584 ## Get a list of package information.
586 # @param Guid: package guid
587 # @param Version: package version
589 def GetPackage(self
, Guid
, Version
, DpGuid
='', DpVersion
=''):
591 if DpVersion
== '' or DpGuid
== '':
593 (PackageGuid
, PackageVersion
) = (Guid
, Version
)
594 SqlCommand
= """select * from %s where PackageGuid ='%s'
595 and PackageVersion = '%s'""" % (self
.PkgTable
, PackageGuid
, \
597 self
.Cur
.execute(SqlCommand
)
599 elif Version
== None or len(Version
.strip()) == 0:
601 SqlCommand
= """select * from %s where PackageGuid ='%s'""" % \
602 (self
.PkgTable
, Guid
)
603 self
.Cur
.execute(SqlCommand
)
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
, \
611 self
.Cur
.execute(SqlCommand
)
614 for PkgInfo
in self
.Cur
:
616 PkgVersion
= PkgInfo
[1]
617 InstallTime
= PkgInfo
[2]
618 InstallPath
= PkgInfo
[5]
619 PkgList
.append((PkgGuid
, PkgVersion
, InstallTime
, DpGuid
, \
620 DpVersion
, InstallPath
))
625 ## Get a list of module in package information.
627 # @param Guid: A module guid
628 # @param Version: A module version
630 def GetModInPackage(self
, Guid
, Version
, PkgGuid
='', PkgVersion
=''):
632 if PkgVersion
== '' or PkgGuid
== '':
634 (ModuleGuid
, ModuleVersion
) = (Guid
, Version
)
635 SqlCommand
= """select * from %s where ModuleGuid ='%s' and
636 ModuleVersion = '%s'""" % (self
.ModInPkgTable
, ModuleGuid
, \
638 self
.Cur
.execute(SqlCommand
)
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
)
650 for ModInfo
in self
.Cur
:
652 ModVersion
= ModInfo
[1]
653 InstallTime
= ModInfo
[2]
654 InstallPath
= ModInfo
[5]
655 ModList
.append((ModGuid
, ModVersion
, InstallTime
, PkgGuid
, \
656 PkgVersion
, InstallPath
))
660 ## Get a list of module standalone.
662 # @param Guid: A module guid
663 # @param Version: A module version
665 def GetStandaloneModule(self
, Guid
, Version
, DpGuid
='', DpVersion
=''):
668 (ModuleGuid
, ModuleVersion
) = (Guid
, Version
)
669 SqlCommand
= """select * from %s where ModuleGuid ='%s' and
670 ModuleVersion = '%s'""" % (self
.StandaloneModTable
, ModuleGuid
, \
672 self
.Cur
.execute(SqlCommand
)
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
)
683 for ModInfo
in self
.Cur
:
685 ModVersion
= ModInfo
[1]
686 InstallTime
= ModInfo
[2]
687 InstallPath
= ModInfo
[5]
688 ModList
.append((ModGuid
, ModVersion
, InstallTime
, DpGuid
, \
689 DpVersion
, InstallPath
))
693 ## Get a list of module information that comes from DP.
695 # @param DpGuid: A Distrabution Guid
696 # @param DpVersion: A Distrabution version
698 def GetSModInsPathListFromDp(self
, DpGuid
, DpVersion
):
701 SqlCommand
= """select InstallPath from %s where DpGuid ='%s'
703 """ % (self
.StandaloneModTable
, DpGuid
, DpVersion
)
704 self
.Cur
.execute(SqlCommand
)
706 for Result
in self
.Cur
:
707 InstallPath
= Result
[0]
708 PathList
.append(InstallPath
)
712 ## Get a list of package information.
714 # @param DpGuid: A Distrabution Guid
715 # @param DpVersion: A Distrabution version
717 def GetPackageListFromDp(self
, DpGuid
, DpVersion
):
719 SqlCommand
= """select * from %s where DpGuid ='%s' and
720 DpVersion = '%s' """ % (self
.PkgTable
, DpGuid
, DpVersion
)
721 self
.Cur
.execute(SqlCommand
)
724 for PkgInfo
in self
.Cur
:
726 PkgVersion
= PkgInfo
[1]
727 InstallPath
= PkgInfo
[5]
728 PkgList
.append((PkgGuid
, PkgVersion
, InstallPath
))
732 ## Get a list of modules that depends on package information from a DP.
734 # @param DpGuid: A Distrabution Guid
735 # @param DpVersion: A Distrabution version
737 def GetDpDependentModuleList(self
, DpGuid
, DpVersion
):
740 PkgList
= self
.GetPackageListFromDp(DpGuid
, DpVersion
)
746 # get all in-package modules that depends on current
747 # Pkg (Guid match, Version match or NA) but not belong to
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], \
759 self
.Cur
.execute(SqlCommand
)
760 for ModInfo
in self
.Cur
:
762 ModVersion
= ModInfo
[1]
763 InstallPath
= ModInfo
[2]
764 ModList
.append((ModGuid
, ModVersion
, InstallPath
))
767 # get all modules from standalone modules that depends on current
768 #Pkg (Guid match, Version match or NA) but not in current dp
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'
777 (self
.StandaloneModTable
, self
.ModDepexTable
, Pkg
[0], \
778 Pkg
[1], DpGuid
, DpVersion
)
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
))
789 ## Get Dp's list of modules.
791 # @param DpGuid: A Distrabution Guid
792 # @param DpVersion: A Distrabution version
794 def GetDpModuleList(self
, DpGuid
, DpVersion
):
797 # get Dp module list from the DpFileList table
799 SqlCommand
= """select FilePath
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
)
812 ## Get a module depex
814 # @param DpGuid: A module Guid
815 # @param DpVersion: A module version
818 def GetModuleDepex(self
, Guid
, Version
, Path
):
821 # Get module depex information to DB.
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
)
830 for DepInfo
in self
.Cur
:
831 DepexGuid
= DepInfo
[3]
832 DepexVersion
= DepInfo
[4]
833 DepexList
.append((DepexGuid
, DepexVersion
))
837 ## Close entire database
839 # Close the connection and cursor
843 # drop the dummy table
846 drop table IF EXISTS %s
847 """ % self
.DummyTable
848 self
.Cur
.execute(SqlCommand
)
854 ## Convert To Sql String
856 # 1. Replace "'" with "''" in each item of StringList
858 # @param StringList: A list for strings to be converted
860 def __ConvertToSqlString(self
, StringList
):
863 return map(lambda s
: s
.replace("'", "''") , StringList
)