2 # This file is for installed package information database operations
4 # Copyright (c) 2011 - 2014, 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
34 # This class represents the installed package information database
35 # Add/Remove/Get installed distribution package information here.
38 # @param object: Inherited from object class
39 # @param DbPath: A string for the path of the database
42 class IpiDatabase(object):
43 def __init__(self
, DbPath
, Workspace
):
44 Dir
= os
.path
.dirname(DbPath
)
45 if not os
.path
.isdir(Dir
):
47 self
.Conn
= sqlite3
.connect(DbPath
, isolation_level
='DEFERRED')
48 self
.Conn
.execute("PRAGMA page_size=4096")
49 self
.Conn
.execute("PRAGMA synchronous=OFF")
50 self
.Cur
= self
.Conn
.cursor()
51 self
.DpTable
= 'DpInfo'
52 self
.PkgTable
= 'PkgInfo'
53 self
.ModInPkgTable
= 'ModInPkgInfo'
54 self
.StandaloneModTable
= 'StandaloneModInfo'
55 self
.ModDepexTable
= 'ModDepexInfo'
56 self
.DpFileListTable
= 'DpFileListInfo'
57 self
.DummyTable
= 'Dummy'
58 self
.Workspace
= os
.path
.normpath(Workspace
)
60 ## Initialize build database
63 def InitDatabase(self
, SkipLock
= False):
64 Logger
.Verbose(ST
.MSG_INIT_IPI_START
)
68 # Create a dummy table, if already existed,
69 # then UPT is already running
75 )""" % self
.DummyTable
76 self
.Cur
.execute(SqlCommand
)
78 except sqlite3
.OperationalError
:
80 UPT_ALREADY_RUNNING_ERROR
,
81 ST
.ERR_UPT_ALREADY_RUNNING_ERROR
88 create table IF NOT EXISTS %s (
89 DpGuid TEXT NOT NULL,DpVersion TEXT NOT NULL,
90 InstallTime REAL NOT NULL,
91 NewPkgFileName TEXT NOT NULL,
92 PkgFileName TEXT NOT NULL,
93 RePackage TEXT NOT NULL,
94 PRIMARY KEY (DpGuid, DpVersion)
96 self
.Cur
.execute(SqlCommand
)
99 create table IF NOT EXISTS %s (
100 FilePath TEXT NOT NULL,
104 PRIMARY KEY (FilePath)
105 )""" % self
.DpFileListTable
106 self
.Cur
.execute(SqlCommand
)
109 create table IF NOT EXISTS %s (
110 PackageGuid TEXT NOT NULL,
111 PackageVersion TEXT NOT NULL,
112 InstallTime REAL NOT NULL,
115 InstallPath TEXT NOT NULL,
116 PRIMARY KEY (PackageGuid, PackageVersion, InstallPath)
118 self
.Cur
.execute(SqlCommand
)
121 create table IF NOT EXISTS %s (
122 ModuleGuid TEXT NOT NULL,
123 ModuleVersion TEXT NOT NULL,
124 ModuleName TEXT NOT NULL,
125 InstallTime REAL NOT NULL,
128 InstallPath TEXT NOT NULL,
129 PRIMARY KEY (ModuleGuid, ModuleVersion, ModuleName, InstallPath)
130 )""" % self
.ModInPkgTable
131 self
.Cur
.execute(SqlCommand
)
134 create table IF NOT EXISTS %s (
135 ModuleGuid TEXT NOT NULL,
136 ModuleVersion TEXT NOT NULL,
137 ModuleName TEXT NOT NULL,
138 InstallTime REAL NOT NULL,
141 InstallPath TEXT NOT NULL,
142 PRIMARY KEY (ModuleGuid, ModuleVersion, ModuleName, InstallPath)
143 )""" % self
.StandaloneModTable
144 self
.Cur
.execute(SqlCommand
)
147 create table IF NOT EXISTS %s (
148 ModuleGuid TEXT NOT NULL,
149 ModuleVersion TEXT NOT NULL,
150 ModuleName TEXT NOT NULL,
151 InstallPath TEXT NOT NULL,
154 )""" % self
.ModDepexTable
155 self
.Cur
.execute(SqlCommand
)
159 Logger
.Verbose(ST
.MSG_INIT_IPI_FINISH
)
167 ## Add a distribution install information from DpObj
170 # @param NewDpPkgFileName: New DpPkg File Name
171 # @param DpPkgFileName: DpPkg File Name
172 # @param RePackage: A RePackage
174 def AddDPObject(self
, DpObj
, NewDpPkgFileName
, DpPkgFileName
, RePackage
):
176 for PkgKey
in DpObj
.PackageSurfaceArea
.keys():
178 PkgVersion
= PkgKey
[1]
179 PkgInstallPath
= PkgKey
[2]
180 self
._AddPackage
(PkgGuid
, PkgVersion
, DpObj
.Header
.GetGuid(), \
181 DpObj
.Header
.GetVersion(), PkgInstallPath
)
182 PkgObj
= DpObj
.PackageSurfaceArea
[PkgKey
]
183 for ModKey
in PkgObj
.GetModuleDict().keys():
185 ModVersion
= ModKey
[1]
187 ModInstallPath
= ModKey
[3]
189 os
.path
.normpath(os
.path
.join(PkgInstallPath
, ModInstallPath
))
190 self
._AddModuleInPackage
(ModGuid
, ModVersion
, ModName
, PkgGuid
, \
191 PkgVersion
, ModInstallPath
)
192 ModObj
= PkgObj
.GetModuleDict()[ModKey
]
193 for Dep
in ModObj
.GetPackageDependencyList():
194 DepexGuid
= Dep
.GetGuid()
195 DepexVersion
= Dep
.GetVersion()
196 self
._AddModuleDepex
(ModGuid
, ModVersion
, ModName
, ModInstallPath
, \
197 DepexGuid
, DepexVersion
)
198 for (FilePath
, Md5Sum
) in PkgObj
.FileList
:
199 self
._AddDpFilePathList
(DpObj
.Header
.GetGuid(), \
200 DpObj
.Header
.GetVersion(), FilePath
, \
203 for ModKey
in DpObj
.ModuleSurfaceArea
.keys():
205 ModVersion
= ModKey
[1]
207 ModInstallPath
= ModKey
[3]
208 self
._AddStandaloneModule
(ModGuid
, ModVersion
, ModName
, \
209 DpObj
.Header
.GetGuid(), \
210 DpObj
.Header
.GetVersion(), \
212 ModObj
= DpObj
.ModuleSurfaceArea
[ModKey
]
213 for Dep
in ModObj
.GetPackageDependencyList():
214 DepexGuid
= Dep
.GetGuid()
215 DepexVersion
= Dep
.GetVersion()
216 self
._AddModuleDepex
(ModGuid
, ModVersion
, ModName
, ModInstallPath
, \
217 DepexGuid
, DepexVersion
)
218 for (Path
, Md5Sum
) in ModObj
.FileList
:
219 self
._AddDpFilePathList
(DpObj
.Header
.GetGuid(), \
220 DpObj
.Header
.GetVersion(), \
224 # add tool/misc files
226 for (Path
, Md5Sum
) in DpObj
.FileList
:
227 self
._AddDpFilePathList
(DpObj
.Header
.GetGuid(), \
228 DpObj
.Header
.GetVersion(), Path
, Md5Sum
)
230 self
._AddDp
(DpObj
.Header
.GetGuid(), DpObj
.Header
.GetVersion(), \
231 NewDpPkgFileName
, DpPkgFileName
, RePackage
)
233 except sqlite3
.IntegrityError
, DetailMsg
:
236 ST
.ERR_UPT_DB_UPDATE_ERROR
,
237 ExtraData
= DetailMsg
240 ## Add a distribution install information
242 # @param Guid Guid of the distribution package
243 # @param Version Version of the distribution package
244 # @param NewDpFileName the saved filename of distribution package file
245 # @param DistributionFileName the filename of distribution package file
247 def _AddDp(self
, Guid
, Version
, NewDpFileName
, DistributionFileName
, \
250 if Version
== None or len(Version
.strip()) == 0:
254 # Add newly installed DP information to DB.
256 if NewDpFileName
== None or len(NewDpFileName
.strip()) == 0:
259 PkgFileName
= NewDpFileName
260 CurrentTime
= time
.time()
262 """insert into %s values('%s', '%s', %s, '%s', '%s', '%s')""" % \
263 (self
.DpTable
, Guid
, Version
, CurrentTime
, PkgFileName
, \
264 DistributionFileName
, str(RePackage
).upper())
265 self
.Cur
.execute(SqlCommand
)
268 ## Add a file list from DP
270 # @param DpGuid: A DpGuid
271 # @param DpVersion: A DpVersion
272 # @param Path: A Path
273 # @param Path: A Md5Sum
275 def _AddDpFilePathList(self
, DpGuid
, DpVersion
, Path
, Md5Sum
):
276 Path
= os
.path
.normpath(Path
)
277 if pf
.system() == 'Windows':
278 if Path
.startswith(self
.Workspace
):
279 Path
= Path
[len(self
.Workspace
):]
281 if Path
.startswith(self
.Workspace
+ os
.sep
):
282 Path
= Path
[len(self
.Workspace
)+1:]
283 SqlCommand
= """insert into %s values('%s', '%s', '%s', '%s')""" % \
284 (self
.DpFileListTable
, Path
, DpGuid
, DpVersion
, Md5Sum
)
286 self
.Cur
.execute(SqlCommand
)
288 ## Add a package install information
290 # @param Guid: A package guid
291 # @param Version: A package version
292 # @param DpGuid: A DpGuid
293 # @param DpVersion: A DpVersion
294 # @param Path: A Path
296 def _AddPackage(self
, Guid
, Version
, DpGuid
=None, DpVersion
=None, Path
=''):
298 if Version
== None or len(Version
.strip()) == 0:
301 if DpGuid
== None or len(DpGuid
.strip()) == 0:
304 if DpVersion
== None or len(DpVersion
.strip()) == 0:
308 # Add newly installed package information to DB.
310 CurrentTime
= time
.time()
312 """insert into %s values('%s', '%s', %s, '%s', '%s', '%s')""" % \
313 (self
.PkgTable
, Guid
, Version
, CurrentTime
, DpGuid
, DpVersion
, Path
)
314 self
.Cur
.execute(SqlCommand
)
316 ## Add a module that from a package install information
318 # @param Guid: Module Guid
319 # @param Version: Module version
320 # @param Name: Module Name
321 # @param PkgGuid: Package Guid
322 # @param PkgVersion: Package version
323 # @param Path: Package relative path that module installs
325 def _AddModuleInPackage(self
, Guid
, Version
, Name
, PkgGuid
=None, \
326 PkgVersion
=None, Path
=''):
328 if Version
== None or len(Version
.strip()) == 0:
331 if PkgGuid
== None or len(PkgGuid
.strip()) == 0:
334 if PkgVersion
== None or len(PkgVersion
.strip()) == 0:
337 if os
.name
== 'posix':
338 Path
= Path
.replace('\\', os
.sep
)
340 Path
= Path
.replace('/', os
.sep
)
343 # Add module from package information to DB.
345 CurrentTime
= time
.time()
347 """insert into %s values('%s', '%s', '%s', %s, '%s', '%s', '%s')""" % \
348 (self
.ModInPkgTable
, Guid
, Version
, Name
, CurrentTime
, PkgGuid
, PkgVersion
, \
350 self
.Cur
.execute(SqlCommand
)
352 ## Add a module that is standalone install information
354 # @param Guid: a module Guid
355 # @param Version: a module Version
356 # @param Name: a module name
357 # @param DpGuid: a DpGuid
358 # @param DpVersion: a DpVersion
361 def _AddStandaloneModule(self
, Guid
, Version
, Name
, DpGuid
=None, \
362 DpVersion
=None, Path
=''):
364 if Version
== None or len(Version
.strip()) == 0:
367 if DpGuid
== None or len(DpGuid
.strip()) == 0:
370 if DpVersion
== None or len(DpVersion
.strip()) == 0:
374 # Add module standalone information to DB.
376 CurrentTime
= time
.time()
378 """insert into %s values('%s', '%s', '%s', %s, '%s', '%s', '%s')""" % \
379 (self
.StandaloneModTable
, Guid
, Version
, Name
, CurrentTime
, DpGuid
, \
381 self
.Cur
.execute(SqlCommand
)
383 ## Add a module depex
385 # @param Guid: a module Guid
386 # @param Version: a module Version
387 # @param Name: a module name
388 # @param DepexGuid: a module DepexGuid
389 # @param DepexVersion: a module DepexVersion
391 def _AddModuleDepex(self
, Guid
, Version
, Name
, Path
, DepexGuid
=None, \
394 if DepexGuid
== None or len(DepexGuid
.strip()) == 0:
397 if DepexVersion
== None or len(DepexVersion
.strip()) == 0:
400 if os
.name
== 'posix':
401 Path
= Path
.replace('\\', os
.sep
)
403 Path
= Path
.replace('/', os
.sep
)
406 # Add module depex information to DB.
408 SqlCommand
= """insert into %s values('%s', '%s', '%s', '%s', '%s', '%s')"""\
409 % (self
.ModDepexTable
, Guid
, Version
, Name
, Path
, DepexGuid
, DepexVersion
)
410 self
.Cur
.execute(SqlCommand
)
412 ## Remove a distribution install information, if no version specified,
413 # remove all DPs with this Guid.
415 # @param DpGuid: guid of dpex
416 # @param DpVersion: version of dpex
418 def RemoveDpObj(self
, DpGuid
, DpVersion
):
420 PkgList
= self
.GetPackageListFromDp(DpGuid
, DpVersion
)
422 # delete from ModDepex the standalone module's dependency
425 """delete from ModDepexInfo where ModDepexInfo.ModuleGuid in
426 (select ModuleGuid from StandaloneModInfo as B where B.DpGuid = '%s'
427 and B.DpVersion = '%s')
428 and ModDepexInfo.ModuleVersion in
429 (select ModuleVersion from StandaloneModInfo as B
430 where B.DpGuid = '%s' and B.DpVersion = '%s')
431 and ModDepexInfo.ModuleName in
432 (select ModuleName from StandaloneModInfo as B
433 where B.DpGuid = '%s' and B.DpVersion = '%s')
434 and ModDepexInfo.InstallPath in
435 (select InstallPath from StandaloneModInfo as B
436 where B.DpGuid = '%s' and B.DpVersion = '%s') """ % \
437 (DpGuid
, DpVersion
, DpGuid
, DpVersion
, DpGuid
, DpVersion
, DpGuid
, DpVersion
)
439 self
.Cur
.execute(SqlCommand
)
441 # delete from ModDepex the from pkg module's dependency
446 """delete from ModDepexInfo where ModDepexInfo.ModuleGuid in
447 (select ModuleGuid from ModInPkgInfo
448 where ModInPkgInfo.PackageGuid ='%s' and
449 ModInPkgInfo.PackageVersion = '%s')
450 and ModDepexInfo.ModuleVersion in
451 (select ModuleVersion from ModInPkgInfo
452 where ModInPkgInfo.PackageGuid ='%s' and
453 ModInPkgInfo.PackageVersion = '%s')
454 and ModDepexInfo.ModuleName in
455 (select ModuleName from ModInPkgInfo
456 where ModInPkgInfo.PackageGuid ='%s' and
457 ModInPkgInfo.PackageVersion = '%s')
458 and ModDepexInfo.InstallPath in
459 (select InstallPath from ModInPkgInfo where
460 ModInPkgInfo.PackageGuid ='%s'
461 and ModInPkgInfo.PackageVersion = '%s')""" \
462 % (Pkg
[0], Pkg
[1], Pkg
[0], Pkg
[1], Pkg
[0], Pkg
[1],Pkg
[0], Pkg
[1])
464 self
.Cur
.execute(SqlCommand
)
466 # delete the standalone module
469 """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
470 (self
.StandaloneModTable
, DpGuid
, DpVersion
)
471 self
.Cur
.execute(SqlCommand
)
473 # delete the from pkg module
477 """delete from %s where %s.PackageGuid ='%s'
478 and %s.PackageVersion = '%s'""" % \
479 (self
.ModInPkgTable
, self
.ModInPkgTable
, Pkg
[0], \
480 self
.ModInPkgTable
, Pkg
[1])
481 self
.Cur
.execute(SqlCommand
)
486 """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
487 (self
.PkgTable
, DpGuid
, DpVersion
)
488 self
.Cur
.execute(SqlCommand
)
490 # delete file list from DP
493 """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
494 (self
.DpFileListTable
, DpGuid
, DpVersion
)
495 self
.Cur
.execute(SqlCommand
)
500 """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
501 (self
.DpTable
, DpGuid
, DpVersion
)
502 self
.Cur
.execute(SqlCommand
)
506 ## Get a list of distribution install information.
508 # @param Guid: distribution package guid
509 # @param Version: distribution package version
511 def GetDp(self
, Guid
, Version
):
513 if Version
== None or len(Version
.strip()) == 0:
515 Logger
.Verbose(ST
.MSG_GET_DP_INSTALL_LIST
)
516 (DpGuid
, DpVersion
) = (Guid
, Version
)
517 SqlCommand
= """select * from %s where DpGuid ='%s'""" % \
518 (self
.DpTable
, DpGuid
)
519 self
.Cur
.execute(SqlCommand
)
522 Logger
.Verbose(ST
.MSG_GET_DP_INSTALL_INFO_START
)
523 (DpGuid
, DpVersion
) = (Guid
, Version
)
525 """select * from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
526 (self
.DpTable
, DpGuid
, DpVersion
)
527 self
.Cur
.execute(SqlCommand
)
530 for DpInfo
in self
.Cur
:
532 DpVersion
= DpInfo
[1]
533 InstallTime
= DpInfo
[2]
534 PkgFileName
= DpInfo
[3]
535 DpList
.append((DpGuid
, DpVersion
, InstallTime
, PkgFileName
))
537 Logger
.Verbose(ST
.MSG_GET_DP_INSTALL_INFO_FINISH
)
540 ## Get a list of distribution install dirs
542 # @param Guid: distribution package guid
543 # @param Version: distribution package version
545 def GetDpInstallDirList(self
, Guid
, Version
):
546 SqlCommand
= """select InstallPath from PkgInfo where DpGuid = '%s' and DpVersion = '%s'""" % (Guid
, Version
)
547 self
.Cur
.execute(SqlCommand
)
549 for Result
in self
.Cur
:
550 if Result
[0] not in DirList
:
551 DirList
.append(Result
[0])
553 SqlCommand
= """select InstallPath from StandaloneModInfo where DpGuid = '%s' and DpVersion = '%s'""" % \
555 self
.Cur
.execute(SqlCommand
)
556 for Result
in self
.Cur
:
557 if Result
[0] not in DirList
:
558 DirList
.append(Result
[0])
563 ## Get a list of distribution install file path information.
565 # @param Guid: distribution package guid
566 # @param Version: distribution package version
568 def GetDpFileList(self
, Guid
, Version
):
570 (DpGuid
, DpVersion
) = (Guid
, Version
)
572 """select * from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
573 (self
.DpFileListTable
, DpGuid
, DpVersion
)
574 self
.Cur
.execute(SqlCommand
)
577 for Result
in self
.Cur
:
580 PathList
.append((os
.path
.join(self
.Workspace
, Path
), Md5Sum
))
584 ## Get files' repackage attribute if present that are installed into current workspace
586 # @retval FileDict: a Dict of file, key is file path, value is (DpGuid, DpVersion, NewDpFileName, RePackage)
588 def GetRePkgDict(self
):
589 SqlCommand
= """select * from %s """ % (self
.DpTable
)
590 self
.Cur
.execute(SqlCommand
)
593 for Result
in self
.Cur
:
594 DpInfoList
.append(Result
)
597 for Result
in DpInfoList
:
599 DpVersion
= Result
[1]
600 NewDpFileName
= Result
[3]
601 RePackage
= Result
[5]
602 if RePackage
== 'TRUE':
606 for FileInfo
in self
.GetDpFileList(DpGuid
, DpVersion
):
607 PathInfo
= FileInfo
[0]
608 FileDict
[PathInfo
] = DpGuid
, DpVersion
, NewDpFileName
, RePackage
612 ## Get (Guid, Version) from distribution file name information.
614 # @param DistributionFile: Distribution File
616 def GetDpByName(self
, DistributionFile
):
617 SqlCommand
= """select * from %s where NewPkgFileName like '%s'""" % \
618 (self
.DpTable
, '%' + DistributionFile
)
619 self
.Cur
.execute(SqlCommand
)
621 for Result
in self
.Cur
:
623 DpVersion
= Result
[1]
624 NewDpFileName
= Result
[3]
626 return (DpGuid
, DpVersion
, NewDpFileName
)
628 return (None, None, None)
630 ## Get a list of package information.
632 # @param Guid: package guid
633 # @param Version: package version
635 def GetPackage(self
, Guid
, Version
, DpGuid
='', DpVersion
=''):
637 if DpVersion
== '' or DpGuid
== '':
639 (PackageGuid
, PackageVersion
) = (Guid
, Version
)
640 SqlCommand
= """select * from %s where PackageGuid ='%s'
641 and PackageVersion = '%s'""" % (self
.PkgTable
, PackageGuid
, \
643 self
.Cur
.execute(SqlCommand
)
645 elif Version
== None or len(Version
.strip()) == 0:
647 SqlCommand
= """select * from %s where PackageGuid ='%s'""" % \
648 (self
.PkgTable
, Guid
)
649 self
.Cur
.execute(SqlCommand
)
651 (PackageGuid
, PackageVersion
) = (Guid
, Version
)
652 SqlCommand
= """select * from %s where PackageGuid ='%s' and
653 PackageVersion = '%s'
654 and DpGuid = '%s' and DpVersion = '%s'""" % \
655 (self
.PkgTable
, PackageGuid
, PackageVersion
, \
657 self
.Cur
.execute(SqlCommand
)
660 for PkgInfo
in self
.Cur
:
662 PkgVersion
= PkgInfo
[1]
663 InstallTime
= PkgInfo
[2]
664 InstallPath
= PkgInfo
[5]
665 PkgList
.append((PkgGuid
, PkgVersion
, InstallTime
, DpGuid
, \
666 DpVersion
, InstallPath
))
671 ## Get a list of module in package information.
673 # @param Guid: A module guid
674 # @param Version: A module version
676 def GetModInPackage(self
, Guid
, Version
, Name
, Path
, PkgGuid
='', PkgVersion
=''):
677 (ModuleGuid
, ModuleVersion
, ModuleName
, InstallPath
) = (Guid
, Version
, Name
, Path
)
678 if PkgVersion
== '' or PkgGuid
== '':
679 SqlCommand
= """select * from %s where ModuleGuid ='%s' and
680 ModuleVersion = '%s' and InstallPath = '%s'
681 and ModuleName = '%s'""" % (self
.ModInPkgTable
, ModuleGuid
, \
682 ModuleVersion
, InstallPath
, ModuleName
)
683 self
.Cur
.execute(SqlCommand
)
685 SqlCommand
= """select * from %s where ModuleGuid ='%s' and
686 ModuleVersion = '%s' and InstallPath = '%s'
687 and ModuleName = '%s' and PackageGuid ='%s'
688 and PackageVersion = '%s'
689 """ % (self
.ModInPkgTable
, ModuleGuid
, \
690 ModuleVersion
, InstallPath
, ModuleName
, PkgGuid
, PkgVersion
)
691 self
.Cur
.execute(SqlCommand
)
694 for ModInfo
in self
.Cur
:
696 ModVersion
= ModInfo
[1]
697 InstallTime
= ModInfo
[2]
698 InstallPath
= ModInfo
[5]
699 ModList
.append((ModGuid
, ModVersion
, InstallTime
, PkgGuid
, \
700 PkgVersion
, InstallPath
))
704 ## Get a list of module standalone.
706 # @param Guid: A module guid
707 # @param Version: A module version
709 def GetStandaloneModule(self
, Guid
, Version
, Name
, Path
, DpGuid
='', DpVersion
=''):
710 (ModuleGuid
, ModuleVersion
, ModuleName
, InstallPath
) = (Guid
, Version
, Name
, Path
)
712 SqlCommand
= """select * from %s where ModuleGuid ='%s' and
713 ModuleVersion = '%s' and InstallPath = '%s'
714 and ModuleName = '%s'""" % (self
.StandaloneModTable
, ModuleGuid
, \
715 ModuleVersion
, InstallPath
, ModuleName
)
716 self
.Cur
.execute(SqlCommand
)
719 SqlCommand
= """select * from %s where ModuleGuid ='%s' and
720 ModuleVersion = '%s' and InstallPath = '%s' and ModuleName = '%s' and DpGuid ='%s' and DpVersion = '%s'
721 """ % (self
.StandaloneModTable
, ModuleGuid
, \
722 ModuleVersion
, ModuleName
, InstallPath
, DpGuid
, DpVersion
)
723 self
.Cur
.execute(SqlCommand
)
726 for ModInfo
in self
.Cur
:
728 ModVersion
= ModInfo
[1]
729 InstallTime
= ModInfo
[2]
730 InstallPath
= ModInfo
[5]
731 ModList
.append((ModGuid
, ModVersion
, InstallTime
, DpGuid
, \
732 DpVersion
, InstallPath
))
736 ## Get a list of module information that comes from DP.
738 # @param DpGuid: A Distrabution Guid
739 # @param DpVersion: A Distrabution version
741 def GetSModInsPathListFromDp(self
, DpGuid
, DpVersion
):
744 SqlCommand
= """select InstallPath from %s where DpGuid ='%s'
746 """ % (self
.StandaloneModTable
, DpGuid
, DpVersion
)
747 self
.Cur
.execute(SqlCommand
)
749 for Result
in self
.Cur
:
750 InstallPath
= Result
[0]
751 PathList
.append(InstallPath
)
755 ## Get a list of package information.
757 # @param DpGuid: A Distrabution Guid
758 # @param DpVersion: A Distrabution version
760 def GetPackageListFromDp(self
, DpGuid
, DpVersion
):
762 SqlCommand
= """select * from %s where DpGuid ='%s' and
763 DpVersion = '%s' """ % (self
.PkgTable
, DpGuid
, DpVersion
)
764 self
.Cur
.execute(SqlCommand
)
767 for PkgInfo
in self
.Cur
:
769 PkgVersion
= PkgInfo
[1]
770 InstallPath
= PkgInfo
[5]
771 PkgList
.append((PkgGuid
, PkgVersion
, InstallPath
))
775 ## Get a list of modules that depends on package information from a DP.
777 # @param DpGuid: A Distrabution Guid
778 # @param DpVersion: A Distrabution version
780 def GetDpDependentModuleList(self
, DpGuid
, DpVersion
):
783 PkgList
= self
.GetPackageListFromDp(DpGuid
, DpVersion
)
789 # get all in-package modules that depends on current
790 # Pkg (Guid match, Version match or NA) but not belong to
793 SqlCommand
= """select t1.ModuleGuid, t1.ModuleVersion,
794 t1.InstallPath from %s as t1, %s as t2 where
795 t1.ModuleGuid = t2.ModuleGuid and
796 t1.ModuleVersion = t2.ModuleVersion and t2.DepexGuid ='%s'
797 and (t2.DepexVersion = '%s' or t2.DepexVersion = 'N/A') and
798 t1.PackageGuid != '%s' and t1.PackageVersion != '%s'
799 """ % (self
.ModInPkgTable
, \
800 self
.ModDepexTable
, Pkg
[0], Pkg
[1], Pkg
[0], \
802 self
.Cur
.execute(SqlCommand
)
803 for ModInfo
in self
.Cur
:
805 ModVersion
= ModInfo
[1]
806 InstallPath
= ModInfo
[2]
807 ModList
.append((ModGuid
, ModVersion
, InstallPath
))
810 # get all modules from standalone modules that depends on current
811 #Pkg (Guid match, Version match or NA) but not in current dp
814 """select t1.ModuleGuid, t1.ModuleVersion, t1.InstallPath
815 from %s as t1, %s as t2 where t1.ModuleGuid = t2.ModuleGuid and
816 t1.ModuleVersion = t2.ModuleVersion and t2.DepexGuid ='%s'
817 and (t2.DepexVersion = '%s' or t2.DepexVersion = 'N/A') and
818 t1.DpGuid != '%s' and t1.DpVersion != '%s'
820 (self
.StandaloneModTable
, self
.ModDepexTable
, Pkg
[0], \
821 Pkg
[1], DpGuid
, DpVersion
)
822 self
.Cur
.execute(SqlCommand
)
823 for ModInfo
in self
.Cur
:
825 ModVersion
= ModInfo
[1]
826 InstallPath
= ModInfo
[2]
827 ModList
.append((ModGuid
, ModVersion
, InstallPath
))
832 ## Get Dp's list of modules.
834 # @param DpGuid: A Distrabution Guid
835 # @param DpVersion: A Distrabution version
837 def GetDpModuleList(self
, DpGuid
, DpVersion
):
840 # get Dp module list from the DpFileList table
842 SqlCommand
= """select FilePath
844 where DpGuid = '%s' and DpVersion = '%s' and
845 FilePath like '%%.inf'
846 """ % (self
.DpFileListTable
, DpGuid
, DpVersion
)
847 self
.Cur
.execute(SqlCommand
)
848 for ModuleInfo
in self
.Cur
:
849 FilePath
= ModuleInfo
[0]
850 ModList
.append(os
.path
.join(self
.Workspace
, FilePath
))
855 ## Get a module depex
857 # @param DpGuid: A module Guid
858 # @param DpVersion: A module version
861 def GetModuleDepex(self
, Guid
, Version
, Path
):
864 # Get module depex information to DB.
866 SqlCommand
= """select * from %s where ModuleGuid ='%s' and
867 ModuleVersion = '%s' and InstallPath ='%s'
868 """ % (self
.ModDepexTable
, Guid
, Version
, Path
)
869 self
.Cur
.execute(SqlCommand
)
873 for DepInfo
in self
.Cur
:
874 DepexGuid
= DepInfo
[3]
875 DepexVersion
= DepInfo
[4]
876 DepexList
.append((DepexGuid
, DepexVersion
))
880 ## Inventory the distribution installed to current workspace
882 # Inventory the distribution installed to current workspace
884 def InventoryDistInstalled(self
):
885 SqlCommand
= """select * from %s """ % (self
.DpTable
)
886 self
.Cur
.execute(SqlCommand
)
889 for Result
in self
.Cur
:
891 DpVersion
= Result
[1]
892 DpAliasName
= Result
[3]
893 DpFileName
= Result
[4]
894 DpInfoList
.append((DpGuid
, DpVersion
, DpFileName
, DpAliasName
))
898 ## Close entire database
900 # Close the connection and cursor
904 # drop the dummy table
907 drop table IF EXISTS %s
908 """ % self
.DummyTable
909 self
.Cur
.execute(SqlCommand
)
915 ## Convert To Sql String
917 # 1. Replace "'" with "''" in each item of StringList
919 # @param StringList: A list for strings to be converted
921 def __ConvertToSqlString(self
, StringList
):
924 return map(lambda s
: s
.replace("'", "''") , StringList
)