## @file\r
# This file is for installed package information database operations\r
#\r
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>\r
#\r
# This program and the accompanying materials are licensed and made available \r
# under the terms and conditions of the BSD License which accompanies this \r
from Logger import StringTable as ST\r
from Logger.ToolError import UPT_ALREADY_RUNNING_ERROR\r
from Logger.ToolError import UPT_DB_UPDATE_ERROR\r
+import platform as pf\r
\r
## IpiDb\r
#\r
#\r
#\r
class IpiDatabase(object):\r
- def __init__(self, DbPath):\r
+ def __init__(self, DbPath, Workspace):\r
Dir = os.path.dirname(DbPath)\r
if not os.path.isdir(Dir):\r
os.mkdir(Dir)\r
- self.Conn = sqlite3.connect(DbPath, isolation_level='DEFERRED')\r
+ self.Conn = sqlite3.connect(unicode(DbPath), isolation_level='DEFERRED')\r
self.Conn.execute("PRAGMA page_size=4096")\r
self.Conn.execute("PRAGMA synchronous=OFF")\r
self.Cur = self.Conn.cursor()\r
self.ModDepexTable = 'ModDepexInfo'\r
self.DpFileListTable = 'DpFileListInfo'\r
self.DummyTable = 'Dummy'\r
+ self.Workspace = os.path.normpath(Workspace)\r
\r
## Initialize build database\r
#\r
\r
Logger.Verbose(ST.MSG_INIT_IPI_FINISH)\r
\r
+ def RollBack(self):\r
+ self.Conn.rollback()\r
+\r
+ def Commit(self):\r
+ self.Conn.commit()\r
+\r
## Add a distribution install information from DpObj\r
#\r
# @param DpObj:\r
self._AddDp(DpObj.Header.GetGuid(), DpObj.Header.GetVersion(), \\r
NewDpPkgFileName, DpPkgFileName, RePackage)\r
\r
- self.Conn.commit()\r
except sqlite3.IntegrityError, DetailMsg:\r
Logger.Error("UPT",\r
UPT_DB_UPDATE_ERROR,\r
def _AddDp(self, Guid, Version, NewDpFileName, DistributionFileName, \\r
RePackage):\r
\r
- if Version == None or len(Version.strip()) == 0:\r
+ if Version is None or len(Version.strip()) == 0:\r
Version = 'N/A'\r
\r
#\r
# Add newly installed DP information to DB.\r
#\r
- if NewDpFileName == None or len(NewDpFileName.strip()) == 0:\r
+ if NewDpFileName is None or len(NewDpFileName.strip()) == 0:\r
PkgFileName = 'N/A'\r
else:\r
PkgFileName = NewDpFileName\r
# @param Path: A Md5Sum\r
#\r
def _AddDpFilePathList(self, DpGuid, DpVersion, Path, Md5Sum):\r
- \r
+ Path = os.path.normpath(Path)\r
+ if pf.system() == 'Windows':\r
+ if Path.startswith(self.Workspace):\r
+ Path = Path[len(self.Workspace):]\r
+ else:\r
+ if Path.startswith(self.Workspace + os.sep):\r
+ Path = Path[len(self.Workspace)+1:]\r
SqlCommand = """insert into %s values('%s', '%s', '%s', '%s')""" % \\r
(self.DpFileListTable, Path, DpGuid, DpVersion, Md5Sum)\r
\r
#\r
def _AddPackage(self, Guid, Version, DpGuid=None, DpVersion=None, Path=''):\r
\r
- if Version == None or len(Version.strip()) == 0:\r
+ if Version is None or len(Version.strip()) == 0:\r
Version = 'N/A'\r
\r
- if DpGuid == None or len(DpGuid.strip()) == 0:\r
+ if DpGuid is None or len(DpGuid.strip()) == 0:\r
DpGuid = 'N/A'\r
\r
- if DpVersion == None or len(DpVersion.strip()) == 0:\r
+ if DpVersion is None or len(DpVersion.strip()) == 0:\r
DpVersion = 'N/A'\r
\r
#\r
def _AddModuleInPackage(self, Guid, Version, Name, PkgGuid=None, \\r
PkgVersion=None, Path=''):\r
\r
- if Version == None or len(Version.strip()) == 0:\r
+ if Version is None or len(Version.strip()) == 0:\r
Version = 'N/A'\r
\r
- if PkgGuid == None or len(PkgGuid.strip()) == 0:\r
+ if PkgGuid is None or len(PkgGuid.strip()) == 0:\r
PkgGuid = 'N/A'\r
\r
- if PkgVersion == None or len(PkgVersion.strip()) == 0:\r
+ if PkgVersion is None or len(PkgVersion.strip()) == 0:\r
PkgVersion = 'N/A'\r
+ \r
+ if os.name == 'posix':\r
+ Path = Path.replace('\\', os.sep)\r
+ else:\r
+ Path = Path.replace('/', os.sep)\r
\r
#\r
# Add module from package information to DB.\r
def _AddStandaloneModule(self, Guid, Version, Name, DpGuid=None, \\r
DpVersion=None, Path=''):\r
\r
- if Version == None or len(Version.strip()) == 0:\r
+ if Version is None or len(Version.strip()) == 0:\r
Version = 'N/A'\r
\r
- if DpGuid == None or len(DpGuid.strip()) == 0:\r
+ if DpGuid is None or len(DpGuid.strip()) == 0:\r
DpGuid = 'N/A'\r
\r
- if DpVersion == None or len(DpVersion.strip()) == 0:\r
+ if DpVersion is None or len(DpVersion.strip()) == 0:\r
DpVersion = 'N/A'\r
\r
#\r
def _AddModuleDepex(self, Guid, Version, Name, Path, DepexGuid=None, \\r
DepexVersion=None):\r
\r
- if DepexGuid == None or len(DepexGuid.strip()) == 0:\r
+ if DepexGuid is None or len(DepexGuid.strip()) == 0:\r
DepexGuid = 'N/A'\r
\r
- if DepexVersion == None or len(DepexVersion.strip()) == 0:\r
+ if DepexVersion is None or len(DepexVersion.strip()) == 0:\r
DepexVersion = 'N/A'\r
+ \r
+ if os.name == 'posix':\r
+ Path = Path.replace('\\', os.sep)\r
+ else:\r
+ Path = Path.replace('/', os.sep)\r
\r
#\r
# Add module depex information to DB.\r
(self.DpTable, DpGuid, DpVersion)\r
self.Cur.execute(SqlCommand)\r
\r
- self.Conn.commit()\r
+ #self.Conn.commit()\r
\r
## Get a list of distribution install information.\r
#\r
#\r
def GetDp(self, Guid, Version):\r
\r
- if Version == None or len(Version.strip()) == 0:\r
+ if Version is None or len(Version.strip()) == 0:\r
Version = 'N/A'\r
Logger.Verbose(ST.MSG_GET_DP_INSTALL_LIST)\r
(DpGuid, DpVersion) = (Guid, Version)\r
for Result in self.Cur:\r
Path = Result[0]\r
Md5Sum = Result[3]\r
- PathList.append((Path, Md5Sum))\r
+ PathList.append((os.path.join(self.Workspace, Path), Md5Sum))\r
\r
return PathList\r
\r
# @param DistributionFile: Distribution File \r
#\r
def GetDpByName(self, DistributionFile):\r
- SqlCommand = """select * from %s where NewPkgFileName like '%s'""" % \\r
- (self.DpTable, '%' + DistributionFile)\r
+ SqlCommand = """select * from %s where NewPkgFileName = '%s'""" % \\r
+ (self.DpTable, DistributionFile)\r
self.Cur.execute(SqlCommand)\r
\r
for Result in self.Cur:\r
PackageVersion)\r
self.Cur.execute(SqlCommand)\r
\r
- elif Version == None or len(Version.strip()) == 0:\r
+ elif Version is None or len(Version.strip()) == 0:\r
\r
SqlCommand = """select * from %s where PackageGuid ='%s'""" % \\r
(self.PkgTable, Guid)\r
self.Cur.execute(SqlCommand)\r
for ModuleInfo in self.Cur:\r
FilePath = ModuleInfo[0]\r
- ModList.append(FilePath)\r
+ ModList.append(os.path.join(self.Workspace, FilePath))\r
\r
return ModList \r
\r
ModuleVersion = '%s' and InstallPath ='%s'\r
""" % (self.ModDepexTable, Guid, Version, Path)\r
self.Cur.execute(SqlCommand)\r
- self.Conn.commit()\r
+\r
\r
DepexList = []\r
for DepInfo in self.Cur:\r
DepexList.append((DepexGuid, DepexVersion))\r
\r
return DepexList\r
- \r
+ \r
+ ## Inventory the distribution installed to current workspace\r
+ #\r
+ # Inventory the distribution installed to current workspace\r
+ # \r
+ def InventoryDistInstalled(self):\r
+ SqlCommand = """select * from %s """ % (self.DpTable)\r
+ self.Cur.execute(SqlCommand)\r
+ \r
+ DpInfoList = []\r
+ for Result in self.Cur:\r
+ DpGuid = Result[0]\r
+ DpVersion = Result[1]\r
+ DpAliasName = Result[3]\r
+ DpFileName = Result[4] \r
+ DpInfoList.append((DpGuid, DpVersion, DpFileName, DpAliasName))\r
+ \r
+ return DpInfoList \r
+\r
## Close entire database\r
#\r
# Close the connection and cursor\r