IpiDb.py revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
## @file
# This file is for installed package information database operations
#
# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
# distribution. The full text of the license may be found at
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
'''
IpiDb
'''
##
# Import Modules
#
import sqlite3
import time
## IpiDb
#
# This class represents the installed package information database
#
#
# @param object: Inherited from object class
# @param DbPath: A string for the path of the database
#
#
class IpiDatabase(object):
## Initialize build database
#
#
if not SkipLock:
try:
#
# Create a dummy table, if already existed,
# then UPT is already running
#
SqlCommand = """
create table %s (
Dummy TEXT NOT NULL,
PRIMARY KEY (Dummy)
except sqlite3.OperationalError:
)
#
# Create new table
#
SqlCommand = """
create table IF NOT EXISTS %s (
DpGuid TEXT NOT NULL,DpVersion TEXT NOT NULL,
InstallTime REAL NOT NULL,
NewPkgFileName TEXT NOT NULL,
PkgFileName TEXT NOT NULL,
RePackage TEXT NOT NULL,
PRIMARY KEY (DpGuid, DpVersion)
SqlCommand = """
create table IF NOT EXISTS %s (
FilePath TEXT NOT NULL,
DpGuid TEXT,
DpVersion TEXT,
Md5Sum TEXT,
PRIMARY KEY (FilePath)
SqlCommand = """
create table IF NOT EXISTS %s (
PackageGuid TEXT NOT NULL,
PackageVersion TEXT NOT NULL,
InstallTime REAL NOT NULL,
DpGuid TEXT,
DpVersion TEXT,
InstallPath TEXT NOT NULL,
PRIMARY KEY (PackageGuid, PackageVersion, InstallPath)
SqlCommand = """
create table IF NOT EXISTS %s (
ModuleGuid TEXT NOT NULL,
ModuleVersion TEXT NOT NULL,
ModuleName TEXT NOT NULL,
InstallTime REAL NOT NULL,
PackageGuid TEXT,
PackageVersion TEXT,
InstallPath TEXT NOT NULL,
PRIMARY KEY (ModuleGuid, ModuleVersion, ModuleName, InstallPath)
SqlCommand = """
create table IF NOT EXISTS %s (
ModuleGuid TEXT NOT NULL,
ModuleVersion TEXT NOT NULL,
ModuleName TEXT NOT NULL,
InstallTime REAL NOT NULL,
DpGuid TEXT,
DpVersion TEXT,
InstallPath TEXT NOT NULL,
PRIMARY KEY (ModuleGuid, ModuleVersion, ModuleName, InstallPath)
SqlCommand = """
create table IF NOT EXISTS %s (
ModuleGuid TEXT NOT NULL,
ModuleVersion TEXT NOT NULL,
ModuleName TEXT NOT NULL,
InstallPath TEXT NOT NULL,
DepexGuid TEXT,
DepexVersion TEXT
## Add a distribution install information from DpObj
#
# @param DpObj:
# @param NewDpPkgFileName: New DpPkg File Name
# @param DpPkgFileName: DpPkg File Name
# @param RePackage: A RePackage
#
try:
ModInstallPath = \
#
#
)
## Add a distribution install information
#
# @param Guid Guid of the distribution package
# @param Version Version of the distribution package
# @param NewDpFileName the saved filename of distribution package file
# @param DistributionFileName the filename of distribution package file
#
Version = 'N/A'
#
# Add newly installed DP information to DB.
#
PkgFileName = 'N/A'
else:
SqlCommand = \
"""insert into %s values('%s', '%s', %s, '%s', '%s', '%s')""" % \
## Add a file list from DP
#
# @param DpGuid: A DpGuid
# @param DpVersion: A DpVersion
# @param Path: A Path
# @param Path: A Md5Sum
#
SqlCommand = """insert into %s values('%s', '%s', '%s', '%s')""" % \
## Add a package install information
#
# @param Guid: A package guid
# @param Version: A package version
# @param DpGuid: A DpGuid
# @param DpVersion: A DpVersion
# @param Path: A Path
#
Version = 'N/A'
DpGuid = 'N/A'
DpVersion = 'N/A'
#
# Add newly installed package information to DB.
#
SqlCommand = \
"""insert into %s values('%s', '%s', %s, '%s', '%s', '%s')""" % \
## Add a module that from a package install information
#
# @param Guid: Module Guid
# @param Version: Module version
# @param Name: Module Name
# @param PkgGuid: Package Guid
# @param PkgVersion: Package version
# @param Path: Package relative path that module installs
#
Version = 'N/A'
PkgGuid = 'N/A'
PkgVersion = 'N/A'
#
# Add module from package information to DB.
#
SqlCommand = \
"""insert into %s values('%s', '%s', '%s', %s, '%s', '%s', '%s')""" % \
Path)
## Add a module that is standalone install information
#
# @param Guid: a module Guid
# @param Version: a module Version
# @param Name: a module name
# @param DpGuid: a DpGuid
# @param DpVersion: a DpVersion
# @param Path: path
#
Version = 'N/A'
DpGuid = 'N/A'
DpVersion = 'N/A'
#
# Add module standalone information to DB.
#
SqlCommand = \
"""insert into %s values('%s', '%s', '%s', %s, '%s', '%s', '%s')""" % \
## Add a module depex
#
# @param Guid: a module Guid
# @param Version: a module Version
# @param Name: a module name
# @param DepexGuid: a module DepexGuid
# @param DepexVersion: a module DepexVersion
#
DepexVersion=None):
DepexGuid = 'N/A'
DepexVersion = 'N/A'
#
# Add module depex information to DB.
#
SqlCommand = """insert into %s values('%s', '%s', '%s', '%s', '%s', '%s')"""\
## Remove a distribution install information, if no version specified,
# remove all DPs with this Guid.
#
# @param DpGuid: guid of dpex
# @param DpVersion: version of dpex
#
#
# delete from ModDepex the standalone module's dependency
#
SqlCommand = \
"""delete from ModDepexInfo where ModDepexInfo.ModuleGuid in
(select ModuleGuid from StandaloneModInfo as B where B.DpGuid = '%s'
and B.DpVersion = '%s')
and ModDepexInfo.ModuleVersion in
(select ModuleVersion from StandaloneModInfo as B
where B.DpGuid = '%s' and B.DpVersion = '%s')
and ModDepexInfo.ModuleName in
(select ModuleName from StandaloneModInfo as B
where B.DpGuid = '%s' and B.DpVersion = '%s')
and ModDepexInfo.InstallPath in
(select InstallPath from StandaloneModInfo as B
where B.DpGuid = '%s' and B.DpVersion = '%s') """ % \
#
# delete from ModDepex the from pkg module's dependency
#
SqlCommand = \
"""delete from ModDepexInfo where ModDepexInfo.ModuleGuid in
(select ModuleGuid from ModInPkgInfo
where ModInPkgInfo.PackageGuid ='%s' and
ModInPkgInfo.PackageVersion = '%s')
and ModDepexInfo.ModuleVersion in
(select ModuleVersion from ModInPkgInfo
where ModInPkgInfo.PackageGuid ='%s' and
ModInPkgInfo.PackageVersion = '%s')
and ModDepexInfo.ModuleName in
(select ModuleName from ModInPkgInfo
where ModInPkgInfo.PackageGuid ='%s' and
ModInPkgInfo.PackageVersion = '%s')
and ModDepexInfo.InstallPath in
(select InstallPath from ModInPkgInfo where
ModInPkgInfo.PackageGuid ='%s'
and ModInPkgInfo.PackageVersion = '%s')""" \
#
# delete the standalone module
#
SqlCommand = \
"""delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
#
# delete the from pkg module
#
SqlCommand = \
"""delete from %s where %s.PackageGuid ='%s'
and %s.PackageVersion = '%s'""" % \
#
# delete packages
#
SqlCommand = \
"""delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
#
# delete file list from DP
#
SqlCommand = \
"""delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
#
# delete DP
#
SqlCommand = \
"""delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
## Get a list of distribution install information.
#
# @param Guid: distribution package guid
# @param Version: distribution package version
#
Version = 'N/A'
SqlCommand = """select * from %s where DpGuid ='%s'""" % \
else:
SqlCommand = \
"""select * from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
DpList = []
return DpList
## Get a list of distribution install dirs
#
# @param Guid: distribution package guid
# @param Version: distribution package version
#
SqlCommand = """select InstallPath from PkgInfo where DpGuid = '%s' and DpVersion = '%s'""" % (Guid, Version)
DirList = []
SqlCommand = """select InstallPath from StandaloneModInfo where DpGuid = '%s' and DpVersion = '%s'""" % \
return DirList
## Get a list of distribution install file path information.
#
# @param Guid: distribution package guid
# @param Version: distribution package version
#
SqlCommand = \
"""select * from %s where DpGuid ='%s' and DpVersion = '%s'""" % \
PathList = []
return PathList
## Get files' repackage attribute if present that are installed into current workspace
#
# @retval FileDict: a Dict of file, key is file path, value is (DpGuid, DpVersion, NewDpFileName, RePackage)
#
def GetRePkgDict(self):
DpInfoList = []
FileDict = {}
for Result in DpInfoList:
if RePackage == 'TRUE':
else:
return FileDict
## Get (Guid, Version) from distribution file name information.
#
# @param DistributionFile: Distribution File
#
SqlCommand = """select * from %s where NewPkgFileName like '%s'""" % \
else:
return (None, None, None)
## Get a list of package information.
#
# @param Guid: package guid
# @param Version: package version
#
SqlCommand = """select * from %s where PackageGuid ='%s'
SqlCommand = """select * from %s where PackageGuid ='%s'""" % \
else:
SqlCommand = """select * from %s where PackageGuid ='%s' and
PackageVersion = '%s'
and DpGuid = '%s' and DpVersion = '%s'""" % \
PkgList = []
return PkgList
## Get a list of module in package information.
#
# @param Guid: A module guid
# @param Version: A module version
#
SqlCommand = """select * from %s where ModuleGuid ='%s' and
ModuleVersion = '%s' and InstallPath = '%s'
else:
SqlCommand = """select * from %s where ModuleGuid ='%s' and
ModuleVersion = '%s' and InstallPath = '%s'
and ModuleName = '%s' and PackageGuid ='%s'
and PackageVersion = '%s'
ModList = []
return ModList
## Get a list of module standalone.
#
# @param Guid: A module guid
# @param Version: A module version
#
if DpGuid == '':
SqlCommand = """select * from %s where ModuleGuid ='%s' and
ModuleVersion = '%s' and InstallPath = '%s'
else:
SqlCommand = """select * from %s where ModuleGuid ='%s' and
ModuleVersion = '%s' and InstallPath = '%s' and ModuleName = '%s' and DpGuid ='%s' and DpVersion = '%s'
ModList = []
return ModList
## Get a list of module information that comes from DP.
#
# @param DpGuid: A Distrabution Guid
# @param DpVersion: A Distrabution version
#
PathList = []
SqlCommand = """select InstallPath from %s where DpGuid ='%s'
and DpVersion = '%s'
return PathList
## Get a list of package information.
#
# @param DpGuid: A Distrabution Guid
# @param DpVersion: A Distrabution version
#
SqlCommand = """select * from %s where DpGuid ='%s' and
PkgList = []
return PkgList
## Get a list of modules that depends on package information from a DP.
#
# @param DpGuid: A Distrabution Guid
# @param DpVersion: A Distrabution version
#
ModList = []
return ModList
#
# get all in-package modules that depends on current
# Pkg (Guid match, Version match or NA) but not belong to
# current Pkg
#
SqlCommand = """select t1.ModuleGuid, t1.ModuleVersion,
t1.InstallPath from %s as t1, %s as t2 where
t1.ModuleGuid = t2.ModuleGuid and
t1.ModuleVersion = t2.ModuleVersion and t2.DepexGuid ='%s'
and (t2.DepexVersion = '%s' or t2.DepexVersion = 'N/A') and
t1.PackageGuid != '%s' and t1.PackageVersion != '%s'
Pkg[1])
#
# get all modules from standalone modules that depends on current
#Pkg (Guid match, Version match or NA) but not in current dp
#
SqlCommand = \
"""select t1.ModuleGuid, t1.ModuleVersion, t1.InstallPath
from %s as t1, %s as t2 where t1.ModuleGuid = t2.ModuleGuid and
t1.ModuleVersion = t2.ModuleVersion and t2.DepexGuid ='%s'
and (t2.DepexVersion = '%s' or t2.DepexVersion = 'N/A') and
t1.DpGuid != '%s' and t1.DpVersion != '%s'
""" % \
return ModList
## Get Dp's list of modules.
#
# @param DpGuid: A Distrabution Guid
# @param DpVersion: A Distrabution version
#
ModList = []
#
# get Dp module list from the DpFileList table
#
SqlCommand = """select FilePath
from %s
where DpGuid = '%s' and DpVersion = '%s' and
FilePath like '%%.inf'
return ModList
## Get a module depex
#
# @param DpGuid: A module Guid
# @param DpVersion: A module version
# @param Path:
#
#
# Get module depex information to DB.
#
SqlCommand = """select * from %s where ModuleGuid ='%s' and
ModuleVersion = '%s' and InstallPath ='%s'
DepexList = []
return DepexList
## Close entire database
#
# Close the connection and cursor
#
#
# drop the dummy table
#
SqlCommand = """
drop table IF EXISTS %s
## Convert To Sql String
#
# 1. Replace "'" with "''" in each item of StringList
#
# @param StringList: A list for strings to be converted
#
pass