]>
Commit | Line | Data |
---|---|---|
4234283c LG |
1 | ## @file\r |
2 | # This file is for installed package information database operations\r | |
3 | #\r | |
4 | # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r | |
5 | #\r | |
6 | # This program and the accompanying materials are licensed and made available \r | |
7 | # under the terms and conditions of the BSD License which accompanies this \r | |
8 | # distribution. The full text of the license may be found at \r | |
9 | # http://opensource.org/licenses/bsd-license.php\r | |
10 | #\r | |
11 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | #\r | |
14 | \r | |
15 | '''\r | |
16 | IpiDb\r | |
17 | '''\r | |
18 | \r | |
19 | ##\r | |
20 | # Import Modules\r | |
21 | #\r | |
22 | import sqlite3\r | |
23 | import os.path\r | |
24 | import time\r | |
25 | \r | |
26 | import Logger.Log as Logger\r | |
27 | from Logger import StringTable as ST\r | |
28 | from Logger.ToolError import UPT_ALREADY_RUNNING_ERROR\r | |
29 | \r | |
30 | ## IpiDb\r | |
31 | #\r | |
32 | # This class represents the installed package information database\r | |
33 | # Add/Remove/Get installed distribution package information here.\r | |
34 | # \r | |
35 | # \r | |
36 | # @param object: Inherited from object class\r | |
37 | # @param DbPath: A string for the path of the database\r | |
38 | #\r | |
39 | #\r | |
40 | class IpiDatabase(object):\r | |
41 | def __init__(self, DbPath):\r | |
42 | Dir = os.path.dirname(DbPath)\r | |
43 | if not os.path.isdir(Dir):\r | |
44 | os.mkdir(Dir)\r | |
45 | self.Conn = sqlite3.connect(DbPath, isolation_level='DEFERRED')\r | |
46 | self.Conn.execute("PRAGMA page_size=4096")\r | |
47 | self.Conn.execute("PRAGMA synchronous=OFF")\r | |
48 | self.Cur = self.Conn.cursor()\r | |
49 | self.DpTable = 'DpInfo'\r | |
50 | self.PkgTable = 'PkgInfo'\r | |
51 | self.ModInPkgTable = 'ModInPkgInfo'\r | |
52 | self.StandaloneModTable = 'StandaloneModInfo'\r | |
53 | self.ModDepexTable = 'ModDepexInfo'\r | |
54 | self.DpFileListTable = 'DpFileListInfo'\r | |
55 | self.DummyTable = 'Dummy'\r | |
56 | \r | |
57 | ## Initialize build database\r | |
58 | #\r | |
59 | #\r | |
60 | def InitDatabase(self, SkipLock = False):\r | |
61 | Logger.Verbose(ST.MSG_INIT_IPI_START)\r | |
62 | if not SkipLock:\r | |
63 | try:\r | |
64 | #\r | |
65 | # Create a dummy table, if already existed,\r | |
66 | # then UPT is already running\r | |
67 | #\r | |
68 | SqlCommand = """\r | |
69 | create table %s (\r | |
70 | Dummy TEXT NOT NULL,\r | |
71 | PRIMARY KEY (Dummy) \r | |
72 | )""" % self.DummyTable\r | |
73 | self.Cur.execute(SqlCommand)\r | |
74 | self.Conn.commit()\r | |
75 | except sqlite3.OperationalError:\r | |
76 | Logger.Error("UPT", \r | |
77 | UPT_ALREADY_RUNNING_ERROR, \r | |
78 | ST.ERR_UPT_ALREADY_RUNNING_ERROR\r | |
79 | )\r | |
80 | \r | |
81 | #\r | |
82 | # Create new table\r | |
83 | #\r | |
84 | SqlCommand = """\r | |
85 | create table IF NOT EXISTS %s (\r | |
86 | DpGuid TEXT NOT NULL,DpVersion TEXT NOT NULL,\r | |
87 | InstallTime REAL NOT NULL,\r | |
88 | NewPkgFileName TEXT NOT NULL,\r | |
89 | PkgFileName TEXT NOT NULL, \r | |
90 | RePackage TEXT NOT NULL,\r | |
91 | PRIMARY KEY (DpGuid, DpVersion) \r | |
92 | )""" % self.DpTable\r | |
93 | self.Cur.execute(SqlCommand)\r | |
94 | \r | |
95 | SqlCommand = """\r | |
96 | create table IF NOT EXISTS %s (\r | |
97 | FilePath TEXT NOT NULL,\r | |
98 | DpGuid TEXT,\r | |
99 | DpVersion TEXT,\r | |
100 | Md5Sum TEXT,\r | |
101 | PRIMARY KEY (FilePath)\r | |
102 | )""" % self.DpFileListTable\r | |
103 | self.Cur.execute(SqlCommand)\r | |
104 | \r | |
105 | SqlCommand = """\r | |
106 | create table IF NOT EXISTS %s (\r | |
107 | PackageGuid TEXT NOT NULL,\r | |
108 | PackageVersion TEXT NOT NULL,\r | |
109 | InstallTime REAL NOT NULL,\r | |
110 | DpGuid TEXT,\r | |
111 | DpVersion TEXT,\r | |
112 | InstallPath TEXT NOT NULL,\r | |
113 | PRIMARY KEY (PackageGuid, PackageVersion, InstallPath)\r | |
114 | )""" % self.PkgTable\r | |
115 | self.Cur.execute(SqlCommand)\r | |
116 | \r | |
117 | SqlCommand = """\r | |
118 | create table IF NOT EXISTS %s (\r | |
119 | ModuleGuid TEXT NOT NULL,\r | |
120 | ModuleVersion TEXT NOT NULL,\r | |
121 | InstallTime REAL NOT NULL,\r | |
122 | PackageGuid TEXT,\r | |
123 | PackageVersion TEXT,\r | |
124 | InstallPath TEXT NOT NULL,\r | |
125 | PRIMARY KEY (ModuleGuid, ModuleVersion, InstallPath)\r | |
126 | )""" % self.ModInPkgTable\r | |
127 | self.Cur.execute(SqlCommand)\r | |
128 | \r | |
129 | SqlCommand = """\r | |
130 | create table IF NOT EXISTS %s (\r | |
131 | ModuleGuid TEXT NOT NULL,\r | |
132 | ModuleVersion TEXT NOT NULL,\r | |
133 | InstallTime REAL NOT NULL,\r | |
134 | DpGuid TEXT,\r | |
135 | DpVersion TEXT,\r | |
136 | InstallPath TEXT NOT NULL,\r | |
137 | PRIMARY KEY (ModuleGuid, ModuleVersion, InstallPath)\r | |
138 | )""" % self.StandaloneModTable\r | |
139 | self.Cur.execute(SqlCommand)\r | |
140 | \r | |
141 | SqlCommand = """\r | |
142 | create table IF NOT EXISTS %s (\r | |
143 | ModuleGuid TEXT NOT NULL,\r | |
144 | ModuleVersion TEXT NOT NULL,\r | |
145 | InstallPath TEXT NOT NULL,\r | |
146 | DepexGuid TEXT,\r | |
147 | DepexVersion TEXT\r | |
148 | )""" % self.ModDepexTable\r | |
149 | self.Cur.execute(SqlCommand)\r | |
150 | \r | |
151 | self.Conn.commit()\r | |
152 | \r | |
153 | Logger.Verbose(ST.MSG_INIT_IPI_FINISH)\r | |
154 | \r | |
155 | ## Add a distribution install information from DpObj\r | |
156 | #\r | |
157 | # @param DpObj:\r | |
158 | # @param NewDpPkgFileName: New DpPkg File Name\r | |
159 | # @param DpPkgFileName: DpPkg File Name\r | |
160 | # @param RePackage: A RePackage\r | |
161 | #\r | |
162 | def AddDPObject(self, DpObj, NewDpPkgFileName, DpPkgFileName, RePackage):\r | |
163 | \r | |
164 | for PkgKey in DpObj.PackageSurfaceArea.keys():\r | |
165 | PkgGuid = PkgKey[0]\r | |
166 | PkgVersion = PkgKey[1]\r | |
167 | PkgInstallPath = PkgKey[2]\r | |
168 | self._AddPackage(PkgGuid, PkgVersion, DpObj.Header.GetGuid(), \\r | |
169 | DpObj.Header.GetVersion(), PkgInstallPath)\r | |
170 | PkgObj = DpObj.PackageSurfaceArea[PkgKey]\r | |
171 | for ModKey in PkgObj.GetModuleDict().keys():\r | |
172 | ModGuid = ModKey[0]\r | |
173 | ModVersion = ModKey[1]\r | |
174 | ModInstallPath = ModKey[2]\r | |
175 | ModInstallPath = \\r | |
176 | os.path.normpath(os.path.join(PkgInstallPath, ModInstallPath))\r | |
177 | self._AddModuleInPackage(ModGuid, ModVersion, PkgGuid, \\r | |
178 | PkgVersion, ModInstallPath)\r | |
179 | ModObj = PkgObj.GetModuleDict()[ModKey]\r | |
180 | for Dep in ModObj.GetPackageDependencyList():\r | |
181 | DepexGuid = Dep.GetGuid()\r | |
182 | DepexVersion = Dep.GetVersion()\r | |
183 | self._AddModuleDepex(ModGuid, ModVersion, ModInstallPath, \\r | |
184 | DepexGuid, DepexVersion)\r | |
185 | for (FilePath, Md5Sum) in PkgObj.FileList:\r | |
186 | self._AddDpFilePathList(DpObj.Header.GetGuid(), \\r | |
187 | DpObj.Header.GetVersion(), FilePath, \\r | |
188 | Md5Sum)\r | |
189 | \r | |
190 | for ModKey in DpObj.ModuleSurfaceArea.keys():\r | |
191 | ModGuid = ModKey[0]\r | |
192 | ModVersion = ModKey[1]\r | |
193 | ModInstallPath = ModKey[2]\r | |
194 | self._AddStandaloneModule(ModGuid, ModVersion, \\r | |
195 | DpObj.Header.GetGuid(), \\r | |
196 | DpObj.Header.GetVersion(), \\r | |
197 | ModInstallPath)\r | |
198 | ModObj = DpObj.ModuleSurfaceArea[ModKey]\r | |
199 | for Dep in ModObj.GetPackageDependencyList():\r | |
200 | DepexGuid = Dep.GetGuid()\r | |
201 | DepexVersion = Dep.GetVersion()\r | |
202 | self._AddModuleDepex(ModGuid, ModVersion, ModInstallPath, \\r | |
203 | DepexGuid, DepexVersion)\r | |
204 | for (Path, Md5Sum) in ModObj.FileList:\r | |
205 | self._AddDpFilePathList(DpObj.Header.GetGuid(), \\r | |
206 | DpObj.Header.GetVersion(), \\r | |
207 | Path, Md5Sum)\r | |
208 | \r | |
209 | #\r | |
210 | # add tool/misc files\r | |
211 | #\r | |
212 | for (Path, Md5Sum) in DpObj.FileList:\r | |
213 | self._AddDpFilePathList(DpObj.Header.GetGuid(), \\r | |
214 | DpObj.Header.GetVersion(), Path, Md5Sum)\r | |
215 | \r | |
216 | self._AddDp(DpObj.Header.GetGuid(), DpObj.Header.GetVersion(), \\r | |
217 | NewDpPkgFileName, DpPkgFileName, RePackage)\r | |
218 | \r | |
219 | self.Conn.commit()\r | |
220 | \r | |
221 | ## Add a distribution install information\r | |
222 | #\r | |
223 | # @param Guid Guid of the distribution package \r | |
224 | # @param Version Version of the distribution package \r | |
225 | # @param NewDpFileName the saved filename of distribution package file\r | |
226 | # @param DistributionFileName the filename of distribution package file\r | |
227 | #\r | |
228 | def _AddDp(self, Guid, Version, NewDpFileName, DistributionFileName, \\r | |
229 | RePackage):\r | |
230 | \r | |
231 | if Version == None or len(Version.strip()) == 0:\r | |
232 | Version = 'N/A'\r | |
233 | \r | |
234 | #\r | |
235 | # Add newly installed DP information to DB.\r | |
236 | #\r | |
237 | if NewDpFileName == None or len(NewDpFileName.strip()) == 0:\r | |
238 | PkgFileName = 'N/A'\r | |
239 | else:\r | |
240 | PkgFileName = NewDpFileName\r | |
241 | CurrentTime = time.time()\r | |
242 | SqlCommand = \\r | |
243 | """insert into %s values('%s', '%s', %s, '%s', '%s', '%s')""" % \\r | |
244 | (self.DpTable, Guid, Version, CurrentTime, PkgFileName, \\r | |
245 | DistributionFileName, str(RePackage).upper())\r | |
246 | self.Cur.execute(SqlCommand)\r | |
247 | \r | |
248 | \r | |
249 | ## Add a file list from DP\r | |
250 | #\r | |
251 | # @param DpGuid: A DpGuid \r | |
252 | # @param DpVersion: A DpVersion\r | |
253 | # @param Path: A Path\r | |
254 | # @param Path: A Md5Sum\r | |
255 | #\r | |
256 | def _AddDpFilePathList(self, DpGuid, DpVersion, Path, Md5Sum):\r | |
257 | \r | |
258 | SqlCommand = """insert into %s values('%s', '%s', '%s', '%s')""" % \\r | |
259 | (self.DpFileListTable, Path, DpGuid, DpVersion, Md5Sum)\r | |
260 | \r | |
261 | self.Cur.execute(SqlCommand)\r | |
262 | \r | |
263 | ## Add a package install information\r | |
264 | #\r | |
265 | # @param Guid: A package guid \r | |
266 | # @param Version: A package version\r | |
267 | # @param DpGuid: A DpGuid \r | |
268 | # @param DpVersion: A DpVersion\r | |
269 | # @param Path: A Path\r | |
270 | #\r | |
271 | def _AddPackage(self, Guid, Version, DpGuid=None, DpVersion=None, Path=''):\r | |
272 | \r | |
273 | if Version == None or len(Version.strip()) == 0:\r | |
274 | Version = 'N/A'\r | |
275 | \r | |
276 | if DpGuid == None or len(DpGuid.strip()) == 0:\r | |
277 | DpGuid = 'N/A'\r | |
278 | \r | |
279 | if DpVersion == None or len(DpVersion.strip()) == 0:\r | |
280 | DpVersion = 'N/A'\r | |
281 | \r | |
282 | #\r | |
283 | # Add newly installed package information to DB.\r | |
284 | #\r | |
285 | CurrentTime = time.time()\r | |
286 | SqlCommand = \\r | |
287 | """insert into %s values('%s', '%s', %s, '%s', '%s', '%s')""" % \\r | |
288 | (self.PkgTable, Guid, Version, CurrentTime, DpGuid, DpVersion, Path)\r | |
289 | self.Cur.execute(SqlCommand)\r | |
290 | \r | |
291 | ## Add a module that from a package install information\r | |
292 | #\r | |
293 | # @param Guid: A package guid \r | |
294 | # @param Version: A package version\r | |
295 | # @param PkgGuid: A package guid\r | |
296 | # @param PkgFileName: A package File Name\r | |
297 | #\r | |
298 | def _AddModuleInPackage(self, Guid, Version, PkgGuid=None, \\r | |
299 | PkgVersion=None, Path=''):\r | |
300 | \r | |
301 | if Version == None or len(Version.strip()) == 0:\r | |
302 | Version = 'N/A'\r | |
303 | \r | |
304 | if PkgGuid == None or len(PkgGuid.strip()) == 0:\r | |
305 | PkgGuid = 'N/A'\r | |
306 | \r | |
307 | if PkgVersion == None or len(PkgVersion.strip()) == 0:\r | |
308 | PkgVersion = 'N/A'\r | |
309 | \r | |
310 | #\r | |
311 | # Add module from package information to DB.\r | |
312 | #\r | |
313 | CurrentTime = time.time()\r | |
314 | SqlCommand = \\r | |
315 | """insert into %s values('%s', '%s', %s, '%s', '%s', '%s')""" % \\r | |
316 | (self.ModInPkgTable, Guid, Version, CurrentTime, PkgGuid, PkgVersion, \\r | |
317 | Path)\r | |
318 | self.Cur.execute(SqlCommand)\r | |
319 | \r | |
320 | ## Add a module that is standalone install information\r | |
321 | #\r | |
322 | # @param Guid: a module Guid\r | |
323 | # @param Version: a module Version\r | |
324 | # @param DpGuid: a DpGuid\r | |
325 | # @param DpVersion: a DpVersion\r | |
326 | # @param Path: path\r | |
327 | #\r | |
328 | def _AddStandaloneModule(self, Guid, Version, DpGuid=None, \\r | |
329 | DpVersion=None, Path=''):\r | |
330 | \r | |
331 | if Version == None or len(Version.strip()) == 0:\r | |
332 | Version = 'N/A'\r | |
333 | \r | |
334 | if DpGuid == None or len(DpGuid.strip()) == 0:\r | |
335 | DpGuid = 'N/A'\r | |
336 | \r | |
337 | if DpVersion == None or len(DpVersion.strip()) == 0:\r | |
338 | DpVersion = 'N/A'\r | |
339 | \r | |
340 | #\r | |
341 | # Add module standalone information to DB.\r | |
342 | #\r | |
343 | CurrentTime = time.time()\r | |
344 | SqlCommand = \\r | |
345 | """insert into %s values('%s', '%s', %s, '%s', '%s', '%s')""" % \\r | |
346 | (self.StandaloneModTable, Guid, Version, CurrentTime, DpGuid, \\r | |
347 | DpVersion, Path)\r | |
348 | self.Cur.execute(SqlCommand)\r | |
349 | \r | |
350 | ## Add a module depex\r | |
351 | #\r | |
352 | # @param Guid: a module Guid\r | |
353 | # @param Version: a module Version\r | |
354 | # @param DepexGuid: a module DepexGuid\r | |
355 | # @param DepexVersion: a module DepexVersion\r | |
356 | #\r | |
357 | def _AddModuleDepex(self, Guid, Version, Path, DepexGuid=None, \\r | |
358 | DepexVersion=None):\r | |
359 | \r | |
360 | if DepexGuid == None or len(DepexGuid.strip()) == 0:\r | |
361 | DepexGuid = 'N/A'\r | |
362 | \r | |
363 | if DepexVersion == None or len(DepexVersion.strip()) == 0:\r | |
364 | DepexVersion = 'N/A'\r | |
365 | \r | |
366 | #\r | |
367 | # Add module depex information to DB.\r | |
368 | #\r | |
369 | SqlCommand = """insert into %s values('%s', '%s', '%s', '%s', '%s')"""\\r | |
370 | % (self.ModDepexTable, Guid, Version, Path, DepexGuid, DepexVersion)\r | |
371 | self.Cur.execute(SqlCommand)\r | |
372 | \r | |
373 | ## Remove a distribution install information, if no version specified, \r | |
374 | # remove all DPs with this Guid.\r | |
375 | #\r | |
376 | # @param DpGuid: guid of dpex \r | |
377 | # @param DpVersion: version of dpex\r | |
378 | #\r | |
379 | def RemoveDpObj(self, DpGuid, DpVersion):\r | |
380 | \r | |
381 | PkgList = self.GetPackageListFromDp(DpGuid, DpVersion)\r | |
382 | #\r | |
383 | # delete from ModDepex the standalone module's dependency\r | |
384 | #\r | |
385 | SqlCommand = \\r | |
386 | """delete from ModDepexInfo where ModDepexInfo.ModuleGuid in \r | |
387 | (select ModuleGuid from StandaloneModInfo as B where B.DpGuid = '%s' \r | |
388 | and B.DpVersion = '%s')\r | |
389 | and ModDepexInfo.ModuleVersion in\r | |
390 | (select ModuleVersion from StandaloneModInfo as B \r | |
391 | where B.DpGuid = '%s' and B.DpVersion = '%s')\r | |
392 | and ModDepexInfo.InstallPath in\r | |
393 | (select InstallPath from StandaloneModInfo as B \r | |
394 | where B.DpGuid = '%s' and B.DpVersion = '%s') """ % \\r | |
395 | (DpGuid, DpVersion, DpGuid, DpVersion, DpGuid, DpVersion)\r | |
396 | \r | |
397 | self.Cur.execute(SqlCommand)\r | |
398 | #\r | |
399 | # delete from ModDepex the from pkg module's dependency\r | |
400 | #\r | |
401 | for Pkg in PkgList:\r | |
402 | \r | |
403 | SqlCommand = \\r | |
404 | """delete from ModDepexInfo where ModDepexInfo.ModuleGuid in \r | |
405 | (select ModuleGuid from ModInPkgInfo \r | |
406 | where ModInPkgInfo.PackageGuid ='%s' and \r | |
407 | ModInPkgInfo.PackageVersion = '%s')\r | |
408 | and ModDepexInfo.ModuleVersion in\r | |
409 | (select ModuleVersion from ModInPkgInfo \r | |
410 | where ModInPkgInfo.PackageGuid ='%s' and \r | |
411 | ModInPkgInfo.PackageVersion = '%s')\r | |
412 | and ModDepexInfo.InstallPath in\r | |
413 | (select InstallPath from ModInPkgInfo where \r | |
414 | ModInPkgInfo.PackageGuid ='%s' \r | |
415 | and ModInPkgInfo.PackageVersion = '%s')""" \\r | |
416 | % (Pkg[0], Pkg[1],Pkg[0], Pkg[1],Pkg[0], Pkg[1])\r | |
417 | \r | |
418 | self.Cur.execute(SqlCommand)\r | |
419 | #\r | |
420 | # delete the standalone module\r | |
421 | #\r | |
422 | SqlCommand = \\r | |
423 | """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \\r | |
424 | (self.StandaloneModTable, DpGuid, DpVersion)\r | |
425 | self.Cur.execute(SqlCommand)\r | |
426 | #\r | |
427 | # delete the from pkg module\r | |
428 | #\r | |
429 | for Pkg in PkgList:\r | |
430 | SqlCommand = \\r | |
431 | """delete from %s where %s.PackageGuid ='%s' \r | |
432 | and %s.PackageVersion = '%s'""" % \\r | |
433 | (self.ModInPkgTable, self.ModInPkgTable, Pkg[0], \\r | |
434 | self.ModInPkgTable, Pkg[1])\r | |
435 | self.Cur.execute(SqlCommand)\r | |
436 | #\r | |
437 | # delete packages\r | |
438 | #\r | |
439 | SqlCommand = \\r | |
440 | """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \\r | |
441 | (self.PkgTable, DpGuid, DpVersion)\r | |
442 | self.Cur.execute(SqlCommand)\r | |
443 | #\r | |
444 | # delete file list from DP\r | |
445 | #\r | |
446 | SqlCommand = \\r | |
447 | """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \\r | |
448 | (self.DpFileListTable, DpGuid, DpVersion)\r | |
449 | self.Cur.execute(SqlCommand)\r | |
450 | # \r | |
451 | # delete DP\r | |
452 | #\r | |
453 | SqlCommand = \\r | |
454 | """delete from %s where DpGuid ='%s' and DpVersion = '%s'""" % \\r | |
455 | (self.DpTable, DpGuid, DpVersion)\r | |
456 | self.Cur.execute(SqlCommand)\r | |
457 | \r | |
458 | self.Conn.commit()\r | |
459 | \r | |
460 | ## Get a list of distribution install information.\r | |
461 | #\r | |
462 | # @param Guid: distribution package guid \r | |
463 | # @param Version: distribution package version \r | |
464 | #\r | |
465 | def GetDp(self, Guid, Version):\r | |
466 | \r | |
467 | if Version == None or len(Version.strip()) == 0:\r | |
468 | Version = 'N/A'\r | |
469 | Logger.Verbose(ST.MSG_GET_DP_INSTALL_LIST)\r | |
470 | (DpGuid, DpVersion) = (Guid, Version)\r | |
471 | SqlCommand = """select * from %s where DpGuid ='%s'""" % \\r | |
472 | (self.DpTable, DpGuid)\r | |
473 | self.Cur.execute(SqlCommand)\r | |
474 | \r | |
475 | else:\r | |
476 | Logger.Verbose(ST.MSG_GET_DP_INSTALL_INFO_START)\r | |
477 | (DpGuid, DpVersion) = (Guid, Version)\r | |
478 | SqlCommand = \\r | |
479 | """select * from %s where DpGuid ='%s' and DpVersion = '%s'""" % \\r | |
480 | (self.DpTable, DpGuid, DpVersion)\r | |
481 | self.Cur.execute(SqlCommand)\r | |
482 | \r | |
483 | DpList = []\r | |
484 | for DpInfo in self.Cur:\r | |
485 | DpGuid = DpInfo[0]\r | |
486 | DpVersion = DpInfo[1]\r | |
487 | InstallTime = DpInfo[2]\r | |
488 | PkgFileName = DpInfo[3]\r | |
489 | DpList.append((DpGuid, DpVersion, InstallTime, PkgFileName))\r | |
490 | \r | |
491 | Logger.Verbose(ST.MSG_GET_DP_INSTALL_INFO_FINISH) \r | |
492 | return DpList\r | |
493 | \r | |
494 | ## Get a list of distribution install dirs\r | |
495 | #\r | |
496 | # @param Guid: distribution package guid \r | |
497 | # @param Version: distribution package version \r | |
498 | #\r | |
499 | def GetDpInstallDirList(self, Guid, Version):\r | |
500 | SqlCommand = """select InstallPath from PkgInfo where DpGuid = '%s' and DpVersion = '%s'""" % (Guid, Version)\r | |
501 | self.Cur.execute(SqlCommand)\r | |
502 | DirList = []\r | |
503 | for Result in self.Cur:\r | |
504 | if Result[0] not in DirList:\r | |
505 | DirList.append(Result[0])\r | |
506 | \r | |
507 | SqlCommand = """select InstallPath from StandaloneModInfo where DpGuid = '%s' and DpVersion = '%s'""" % \\r | |
508 | (Guid, Version)\r | |
509 | self.Cur.execute(SqlCommand)\r | |
510 | for Result in self.Cur:\r | |
511 | if Result[0] not in DirList:\r | |
512 | DirList.append(Result[0])\r | |
513 | \r | |
514 | return DirList\r | |
515 | \r | |
516 | \r | |
517 | ## Get a list of distribution install file path information.\r | |
518 | #\r | |
519 | # @param Guid: distribution package guid \r | |
520 | # @param Version: distribution package version \r | |
521 | #\r | |
522 | def GetDpFileList(self, Guid, Version):\r | |
523 | \r | |
524 | (DpGuid, DpVersion) = (Guid, Version)\r | |
525 | SqlCommand = \\r | |
526 | """select * from %s where DpGuid ='%s' and DpVersion = '%s'""" % \\r | |
527 | (self.DpFileListTable, DpGuid, DpVersion)\r | |
528 | self.Cur.execute(SqlCommand)\r | |
529 | \r | |
530 | PathList = []\r | |
531 | for Result in self.Cur:\r | |
532 | Path = Result[0]\r | |
533 | Md5Sum = Result[3]\r | |
534 | PathList.append((Path, Md5Sum))\r | |
535 | \r | |
536 | return PathList\r | |
537 | \r | |
538 | ## Get files' repackage attribute if present that are installed into current workspace\r | |
539 | #\r | |
540 | # @retval FileDict: a Dict of file, key is file path, value is (DpGuid, DpVersion, NewDpFileName, RePackage)\r | |
541 | #\r | |
542 | def GetRePkgDict(self):\r | |
543 | SqlCommand = """select * from %s """ % (self.DpTable)\r | |
544 | self.Cur.execute(SqlCommand)\r | |
545 | \r | |
546 | DpInfoList = []\r | |
547 | for Result in self.Cur:\r | |
548 | DpInfoList.append(Result)\r | |
549 | \r | |
550 | FileDict = {} \r | |
551 | for Result in DpInfoList:\r | |
552 | DpGuid = Result[0]\r | |
553 | DpVersion = Result[1]\r | |
554 | NewDpFileName = Result[3]\r | |
555 | RePackage = Result[5]\r | |
556 | if RePackage == 'TRUE':\r | |
557 | RePackage = True\r | |
558 | else:\r | |
559 | RePackage = False\r | |
560 | for FileInfo in self.GetDpFileList(DpGuid, DpVersion):\r | |
561 | PathInfo = FileInfo[0]\r | |
562 | FileDict[PathInfo] = DpGuid, DpVersion, NewDpFileName, RePackage\r | |
563 | \r | |
564 | return FileDict\r | |
565 | \r | |
566 | ## Get (Guid, Version) from distribution file name information.\r | |
567 | #\r | |
568 | # @param DistributionFile: Distribution File \r | |
569 | #\r | |
570 | def GetDpByName(self, DistributionFile):\r | |
571 | SqlCommand = """select * from %s where NewPkgFileName like '%s'""" % \\r | |
572 | (self.DpTable, '%' + DistributionFile)\r | |
573 | self.Cur.execute(SqlCommand)\r | |
574 | \r | |
575 | for Result in self.Cur:\r | |
576 | DpGuid = Result[0]\r | |
577 | DpVersion = Result[1]\r | |
578 | NewDpFileName = Result[3]\r | |
579 | \r | |
580 | return (DpGuid, DpVersion, NewDpFileName)\r | |
581 | else:\r | |
582 | return (None, None, None)\r | |
583 | \r | |
584 | ## Get a list of package information.\r | |
585 | #\r | |
586 | # @param Guid: package guid \r | |
587 | # @param Version: package version\r | |
588 | #\r | |
589 | def GetPackage(self, Guid, Version, DpGuid='', DpVersion=''):\r | |
590 | \r | |
591 | if DpVersion == '' or DpGuid == '':\r | |
592 | \r | |
593 | (PackageGuid, PackageVersion) = (Guid, Version)\r | |
594 | SqlCommand = """select * from %s where PackageGuid ='%s' \r | |
595 | and PackageVersion = '%s'""" % (self.PkgTable, PackageGuid, \\r | |
596 | PackageVersion)\r | |
597 | self.Cur.execute(SqlCommand)\r | |
598 | \r | |
599 | elif Version == None or len(Version.strip()) == 0:\r | |
600 | \r | |
601 | SqlCommand = """select * from %s where PackageGuid ='%s'""" % \\r | |
602 | (self.PkgTable, Guid)\r | |
603 | self.Cur.execute(SqlCommand)\r | |
604 | else:\r | |
605 | (PackageGuid, PackageVersion) = (Guid, Version)\r | |
606 | SqlCommand = """select * from %s where PackageGuid ='%s' and \r | |
607 | PackageVersion = '%s'\r | |
608 | and DpGuid = '%s' and DpVersion = '%s'""" % \\r | |
609 | (self.PkgTable, PackageGuid, PackageVersion, \\r | |
610 | DpGuid, DpVersion)\r | |
611 | self.Cur.execute(SqlCommand)\r | |
612 | \r | |
613 | PkgList = []\r | |
614 | for PkgInfo in self.Cur:\r | |
615 | PkgGuid = PkgInfo[0]\r | |
616 | PkgVersion = PkgInfo[1]\r | |
617 | InstallTime = PkgInfo[2]\r | |
618 | InstallPath = PkgInfo[5]\r | |
619 | PkgList.append((PkgGuid, PkgVersion, InstallTime, DpGuid, \\r | |
620 | DpVersion, InstallPath))\r | |
621 | \r | |
622 | return PkgList\r | |
623 | \r | |
624 | \r | |
625 | ## Get a list of module in package information.\r | |
626 | #\r | |
627 | # @param Guid: A module guid\r | |
628 | # @param Version: A module version\r | |
629 | #\r | |
630 | def GetModInPackage(self, Guid, Version, PkgGuid='', PkgVersion=''):\r | |
631 | \r | |
632 | if PkgVersion == '' or PkgGuid == '':\r | |
633 | \r | |
634 | (ModuleGuid, ModuleVersion) = (Guid, Version)\r | |
635 | SqlCommand = """select * from %s where ModuleGuid ='%s' and \r | |
636 | ModuleVersion = '%s'""" % (self.ModInPkgTable, ModuleGuid, \\r | |
637 | ModuleVersion)\r | |
638 | self.Cur.execute(SqlCommand)\r | |
639 | \r | |
640 | else:\r | |
641 | (ModuleGuid, ModuleVersion) = (Guid, Version)\r | |
642 | SqlCommand = """select * from %s where ModuleGuid ='%s' and \r | |
643 | ModuleVersion = '%s' and PackageGuid ='%s' \r | |
644 | and PackageVersion = '%s'\r | |
645 | """ % (self.ModInPkgTable, ModuleGuid, \\r | |
646 | ModuleVersion, PkgGuid, PkgVersion)\r | |
647 | self.Cur.execute(SqlCommand)\r | |
648 | \r | |
649 | ModList = []\r | |
650 | for ModInfo in self.Cur:\r | |
651 | ModGuid = ModInfo[0]\r | |
652 | ModVersion = ModInfo[1]\r | |
653 | InstallTime = ModInfo[2]\r | |
654 | InstallPath = ModInfo[5]\r | |
655 | ModList.append((ModGuid, ModVersion, InstallTime, PkgGuid, \\r | |
656 | PkgVersion, InstallPath))\r | |
657 | \r | |
658 | return ModList\r | |
659 | \r | |
660 | ## Get a list of module standalone.\r | |
661 | #\r | |
662 | # @param Guid: A module guid \r | |
663 | # @param Version: A module version \r | |
664 | #\r | |
665 | def GetStandaloneModule(self, Guid, Version, DpGuid='', DpVersion=''):\r | |
666 | \r | |
667 | if DpGuid == '':\r | |
668 | (ModuleGuid, ModuleVersion) = (Guid, Version)\r | |
669 | SqlCommand = """select * from %s where ModuleGuid ='%s' and \r | |
670 | ModuleVersion = '%s'""" % (self.StandaloneModTable, ModuleGuid, \\r | |
671 | ModuleVersion)\r | |
672 | self.Cur.execute(SqlCommand)\r | |
673 | \r | |
674 | else:\r | |
675 | (ModuleGuid, ModuleVersion) = (Guid, Version)\r | |
676 | SqlCommand = """select * from %s where ModuleGuid ='%s' and \r | |
677 | ModuleVersion = '%s' and DpGuid ='%s' and DpVersion = '%s'\r | |
678 | """ % (self.StandaloneModTable, ModuleGuid, \\r | |
679 | ModuleVersion, DpGuid, DpVersion)\r | |
680 | self.Cur.execute(SqlCommand)\r | |
681 | \r | |
682 | ModList = []\r | |
683 | for ModInfo in self.Cur:\r | |
684 | ModGuid = ModInfo[0]\r | |
685 | ModVersion = ModInfo[1]\r | |
686 | InstallTime = ModInfo[2]\r | |
687 | InstallPath = ModInfo[5]\r | |
688 | ModList.append((ModGuid, ModVersion, InstallTime, DpGuid, \\r | |
689 | DpVersion, InstallPath))\r | |
690 | \r | |
691 | return ModList\r | |
692 | \r | |
693 | ## Get a list of module information that comes from DP.\r | |
694 | #\r | |
695 | # @param DpGuid: A Distrabution Guid \r | |
696 | # @param DpVersion: A Distrabution version \r | |
697 | #\r | |
698 | def GetSModInsPathListFromDp(self, DpGuid, DpVersion):\r | |
699 | \r | |
700 | PathList = []\r | |
701 | SqlCommand = """select InstallPath from %s where DpGuid ='%s' \r | |
702 | and DpVersion = '%s'\r | |
703 | """ % (self.StandaloneModTable, DpGuid, DpVersion)\r | |
704 | self.Cur.execute(SqlCommand)\r | |
705 | \r | |
706 | for Result in self.Cur:\r | |
707 | InstallPath = Result[0]\r | |
708 | PathList.append(InstallPath)\r | |
709 | \r | |
710 | return PathList\r | |
711 | \r | |
712 | ## Get a list of package information.\r | |
713 | #\r | |
714 | # @param DpGuid: A Distrabution Guid \r | |
715 | # @param DpVersion: A Distrabution version \r | |
716 | #\r | |
717 | def GetPackageListFromDp(self, DpGuid, DpVersion):\r | |
718 | \r | |
719 | SqlCommand = """select * from %s where DpGuid ='%s' and \r | |
720 | DpVersion = '%s' """ % (self.PkgTable, DpGuid, DpVersion)\r | |
721 | self.Cur.execute(SqlCommand)\r | |
722 | \r | |
723 | PkgList = []\r | |
724 | for PkgInfo in self.Cur:\r | |
725 | PkgGuid = PkgInfo[0]\r | |
726 | PkgVersion = PkgInfo[1]\r | |
727 | InstallPath = PkgInfo[5]\r | |
728 | PkgList.append((PkgGuid, PkgVersion, InstallPath))\r | |
729 | \r | |
730 | return PkgList\r | |
731 | \r | |
732 | ## Get a list of modules that depends on package information from a DP.\r | |
733 | #\r | |
734 | # @param DpGuid: A Distrabution Guid \r | |
735 | # @param DpVersion: A Distrabution version \r | |
736 | #\r | |
737 | def GetDpDependentModuleList(self, DpGuid, DpVersion):\r | |
738 | \r | |
739 | ModList = []\r | |
740 | PkgList = self.GetPackageListFromDp(DpGuid, DpVersion)\r | |
741 | if len(PkgList) > 0:\r | |
742 | return ModList\r | |
743 | \r | |
744 | for Pkg in PkgList:\r | |
745 | #\r | |
746 | # get all in-package modules that depends on current \r | |
747 | # Pkg (Guid match, Version match or NA) but not belong to \r | |
748 | # current Pkg\r | |
749 | #\r | |
750 | SqlCommand = """select t1.ModuleGuid, t1.ModuleVersion, \r | |
751 | t1.InstallPath from %s as t1, %s as t2 where \r | |
752 | t1.ModuleGuid = t2.ModuleGuid and \r | |
753 | t1.ModuleVersion = t2.ModuleVersion and t2.DepexGuid ='%s' \r | |
754 | and (t2.DepexVersion = '%s' or t2.DepexVersion = 'N/A') and\r | |
755 | t1.PackageGuid != '%s' and t1.PackageVersion != '%s'\r | |
756 | """ % (self.ModInPkgTable, \\r | |
757 | self.ModDepexTable, Pkg[0], Pkg[1], Pkg[0], \\r | |
758 | Pkg[1])\r | |
759 | self.Cur.execute(SqlCommand)\r | |
760 | for ModInfo in self.Cur:\r | |
761 | ModGuid = ModInfo[0]\r | |
762 | ModVersion = ModInfo[1]\r | |
763 | InstallPath = ModInfo[2]\r | |
764 | ModList.append((ModGuid, ModVersion, InstallPath))\r | |
765 | \r | |
766 | #\r | |
767 | # get all modules from standalone modules that depends on current \r | |
768 | #Pkg (Guid match, Version match or NA) but not in current dp\r | |
769 | #\r | |
770 | SqlCommand = \\r | |
771 | """select t1.ModuleGuid, t1.ModuleVersion, t1.InstallPath \r | |
772 | from %s as t1, %s as t2 where t1.ModuleGuid = t2.ModuleGuid and \r | |
773 | t1.ModuleVersion = t2.ModuleVersion and t2.DepexGuid ='%s' \r | |
774 | and (t2.DepexVersion = '%s' or t2.DepexVersion = 'N/A') and\r | |
775 | t1.DpGuid != '%s' and t1.DpVersion != '%s'\r | |
776 | """ % \\r | |
777 | (self.StandaloneModTable, self.ModDepexTable, Pkg[0], \\r | |
778 | Pkg[1], DpGuid, DpVersion)\r | |
779 | self.Cur.execute(SqlCommand)\r | |
780 | for ModInfo in self.Cur:\r | |
781 | ModGuid = ModInfo[0]\r | |
782 | ModVersion = ModInfo[1]\r | |
783 | InstallPath = ModInfo[2]\r | |
784 | ModList.append((ModGuid, ModVersion, InstallPath))\r | |
785 | \r | |
786 | \r | |
787 | return ModList\r | |
788 | \r | |
789 | ## Get Dp's list of modules.\r | |
790 | #\r | |
791 | # @param DpGuid: A Distrabution Guid \r | |
792 | # @param DpVersion: A Distrabution version \r | |
793 | #\r | |
794 | def GetDpModuleList(self, DpGuid, DpVersion): \r | |
795 | ModList = []\r | |
796 | #\r | |
797 | # get Dp module list from the DpFileList table\r | |
798 | #\r | |
799 | SqlCommand = """select FilePath \r | |
800 | from %s\r | |
801 | where DpGuid = '%s' and DpVersion = '%s' and \r | |
802 | FilePath like '%%.inf'\r | |
803 | """ % (self.DpFileListTable, DpGuid, DpVersion)\r | |
804 | self.Cur.execute(SqlCommand)\r | |
805 | for ModuleInfo in self.Cur:\r | |
806 | FilePath = ModuleInfo[0]\r | |
807 | ModList.append(FilePath)\r | |
808 | \r | |
809 | return ModList \r | |
810 | \r | |
811 | \r | |
812 | ## Get a module depex\r | |
813 | #\r | |
814 | # @param DpGuid: A module Guid \r | |
815 | # @param DpVersion: A module version \r | |
816 | # @param Path:\r | |
817 | #\r | |
818 | def GetModuleDepex(self, Guid, Version, Path):\r | |
819 | \r | |
820 | #\r | |
821 | # Get module depex information to DB.\r | |
822 | #\r | |
823 | SqlCommand = """select * from %s where ModuleGuid ='%s' and \r | |
824 | ModuleVersion = '%s' and InstallPath ='%s'\r | |
825 | """ % (self.ModDepexTable, Guid, Version, Path)\r | |
826 | self.Cur.execute(SqlCommand)\r | |
827 | self.Conn.commit()\r | |
828 | \r | |
829 | DepexList = []\r | |
830 | for DepInfo in self.Cur:\r | |
831 | DepexGuid = DepInfo[3]\r | |
832 | DepexVersion = DepInfo[4]\r | |
833 | DepexList.append((DepexGuid, DepexVersion))\r | |
834 | \r | |
835 | return DepexList\r | |
836 | \r | |
837 | ## Close entire database\r | |
838 | #\r | |
839 | # Close the connection and cursor\r | |
840 | #\r | |
841 | def CloseDb(self):\r | |
842 | #\r | |
843 | # drop the dummy table\r | |
844 | #\r | |
845 | SqlCommand = """\r | |
846 | drop table IF EXISTS %s \r | |
847 | """ % self.DummyTable\r | |
848 | self.Cur.execute(SqlCommand)\r | |
849 | self.Conn.commit()\r | |
850 | \r | |
851 | self.Cur.close()\r | |
852 | self.Conn.close()\r | |
853 | \r | |
854 | ## Convert To Sql String\r | |
855 | #\r | |
856 | # 1. Replace "'" with "''" in each item of StringList\r | |
857 | # \r | |
858 | # @param StringList: A list for strings to be converted\r | |
859 | #\r | |
860 | def __ConvertToSqlString(self, StringList):\r | |
861 | if self.DpTable:\r | |
862 | pass\r | |
863 | return map(lambda s: s.replace("'", "''") , StringList)\r | |
864 | \r | |
865 | \r | |
866 | \r | |
867 |