2011-05-27 06:31:45 +00:00
|
|
|
import logging
|
|
|
|
import os.path
|
|
|
|
import errno
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
import prserv
|
2013-08-31 22:41:35 +00:00
|
|
|
import time
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
import sqlite3
|
|
|
|
except ImportError:
|
|
|
|
from pysqlite2 import dbapi2 as sqlite3
|
|
|
|
|
2012-01-10 06:13:50 +00:00
|
|
|
logger = logging.getLogger("BitBake.PRserv")
|
|
|
|
|
2011-05-27 06:31:45 +00:00
|
|
|
sqlversion = sqlite3.sqlite_version_info
|
|
|
|
if sqlversion[0] < 3 or (sqlversion[0] == 3 and sqlversion[1] < 3):
|
|
|
|
raise Exception("sqlite3 version 3.3.0 or later is required.")
|
|
|
|
|
2013-08-28 16:06:10 +00:00
|
|
|
class PRTable(object):
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
def __init__(self, conn, table, nohist):
|
|
|
|
self.conn = conn
|
|
|
|
self.nohist = nohist
|
|
|
|
if nohist:
|
|
|
|
self.table = "%s_nohist" % table
|
|
|
|
else:
|
|
|
|
self.table = "%s_hist" % table
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
self._execute("CREATE TABLE IF NOT EXISTS %s \
|
|
|
|
(version TEXT NOT NULL, \
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
pkgarch TEXT NOT NULL, \
|
2011-05-27 06:31:45 +00:00
|
|
|
checksum TEXT NOT NULL, \
|
|
|
|
value INTEGER, \
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
PRIMARY KEY (version, pkgarch, checksum));" % self.table)
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
def _execute(self, *query):
|
|
|
|
"""Execute a query, waiting to acquire a lock if necessary"""
|
2013-08-31 22:41:35 +00:00
|
|
|
start = time.time()
|
|
|
|
end = start + 20
|
2011-05-27 06:31:45 +00:00
|
|
|
while True:
|
|
|
|
try:
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
return self.conn.execute(*query)
|
2011-05-27 06:31:45 +00:00
|
|
|
except sqlite3.OperationalError as exc:
|
2013-08-31 22:41:35 +00:00
|
|
|
if 'is locked' in str(exc) and end > time.time():
|
2011-05-27 06:31:45 +00:00
|
|
|
continue
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
raise exc
|
2011-05-27 06:31:45 +00:00
|
|
|
|
2013-09-08 09:45:54 +00:00
|
|
|
def sync(self):
|
|
|
|
self.conn.commit()
|
|
|
|
self._execute("BEGIN EXCLUSIVE TRANSACTION")
|
|
|
|
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
def _getValueHist(self, version, pkgarch, checksum):
|
|
|
|
data=self._execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=?;" % self.table,
|
|
|
|
(version, pkgarch, checksum))
|
2011-05-27 06:31:45 +00:00
|
|
|
row=data.fetchone()
|
|
|
|
if row != None:
|
|
|
|
return row[0]
|
|
|
|
else:
|
|
|
|
#no value found, try to insert
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
try:
|
2013-08-31 22:42:13 +00:00
|
|
|
self._execute("INSERT INTO %s VALUES (?, ?, ?, (select ifnull(max(value)+1,0) from %s where version=? AND pkgarch=?));"
|
2011-05-27 06:31:45 +00:00
|
|
|
% (self.table,self.table),
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
(version,pkgarch, checksum,version, pkgarch))
|
|
|
|
except sqlite3.IntegrityError as exc:
|
2012-01-10 06:13:50 +00:00
|
|
|
logger.error(str(exc))
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
|
|
|
|
data=self._execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=?;" % self.table,
|
|
|
|
(version, pkgarch, checksum))
|
|
|
|
row=data.fetchone()
|
|
|
|
if row != None:
|
|
|
|
return row[0]
|
|
|
|
else:
|
|
|
|
raise prserv.NotFoundError
|
|
|
|
|
|
|
|
def _getValueNohist(self, version, pkgarch, checksum):
|
|
|
|
data=self._execute("SELECT value FROM %s \
|
|
|
|
WHERE version=? AND pkgarch=? AND checksum=? AND \
|
|
|
|
value >= (select max(value) from %s where version=? AND pkgarch=?);"
|
|
|
|
% (self.table, self.table),
|
|
|
|
(version, pkgarch, checksum, version, pkgarch))
|
|
|
|
row=data.fetchone()
|
|
|
|
if row != None:
|
|
|
|
return row[0]
|
|
|
|
else:
|
|
|
|
#no value found, try to insert
|
|
|
|
try:
|
|
|
|
self._execute("INSERT OR REPLACE INTO %s VALUES (?, ?, ?, (select ifnull(max(value)+1,0) from %s where version=? AND pkgarch=?));"
|
|
|
|
% (self.table,self.table),
|
|
|
|
(version, pkgarch, checksum, version, pkgarch))
|
|
|
|
except sqlite3.IntegrityError as exc:
|
2012-01-10 06:13:50 +00:00
|
|
|
logger.error(str(exc))
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
self.conn.rollback()
|
|
|
|
|
|
|
|
data=self._execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=?;" % self.table,
|
|
|
|
(version, pkgarch, checksum))
|
2011-05-27 06:31:45 +00:00
|
|
|
row=data.fetchone()
|
|
|
|
if row != None:
|
|
|
|
return row[0]
|
|
|
|
else:
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
raise prserv.NotFoundError
|
|
|
|
|
|
|
|
def getValue(self, version, pkgarch, checksum):
|
|
|
|
if self.nohist:
|
|
|
|
return self._getValueNohist(version, pkgarch, checksum)
|
|
|
|
else:
|
|
|
|
return self._getValueHist(version, pkgarch, checksum)
|
|
|
|
|
|
|
|
def _importHist(self, version, pkgarch, checksum, value):
|
|
|
|
val = None
|
|
|
|
data = self._execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=?;" % self.table,
|
|
|
|
(version, pkgarch, checksum))
|
|
|
|
row = data.fetchone()
|
|
|
|
if row != None:
|
|
|
|
val=row[0]
|
|
|
|
else:
|
|
|
|
#no value found, try to insert
|
|
|
|
try:
|
2013-08-31 22:42:13 +00:00
|
|
|
self._execute("INSERT INTO %s VALUES (?, ?, ?, ?);" % (self.table),
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
(version, pkgarch, checksum, value))
|
|
|
|
except sqlite3.IntegrityError as exc:
|
2012-01-10 06:13:50 +00:00
|
|
|
logger.error(str(exc))
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
|
|
|
|
data = self._execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=?;" % self.table,
|
|
|
|
(version, pkgarch, checksum))
|
|
|
|
row = data.fetchone()
|
|
|
|
if row != None:
|
|
|
|
val = row[0]
|
|
|
|
return val
|
|
|
|
|
|
|
|
def _importNohist(self, version, pkgarch, checksum, value):
|
|
|
|
try:
|
|
|
|
#try to insert
|
2013-08-31 22:42:13 +00:00
|
|
|
self._execute("INSERT INTO %s VALUES (?, ?, ?, ?);" % (self.table),
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
(version, pkgarch, checksum,value))
|
|
|
|
except sqlite3.IntegrityError as exc:
|
|
|
|
#already have the record, try to update
|
|
|
|
try:
|
|
|
|
self._execute("UPDATE %s SET value=? WHERE version=? AND pkgarch=? AND checksum=? AND value<?"
|
|
|
|
% (self.table),
|
|
|
|
(value,version,pkgarch,checksum,value))
|
|
|
|
except sqlite3.IntegrityError as exc:
|
2012-01-10 06:13:50 +00:00
|
|
|
logger.error(str(exc))
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
|
|
|
|
data = self._execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=? AND value>=?;" % self.table,
|
|
|
|
(version,pkgarch,checksum,value))
|
|
|
|
row=data.fetchone()
|
|
|
|
if row != None:
|
|
|
|
return row[0]
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def importone(self, version, pkgarch, checksum, value):
|
|
|
|
if self.nohist:
|
|
|
|
return self._importNohist(version, pkgarch, checksum, value)
|
|
|
|
else:
|
|
|
|
return self._importHist(version, pkgarch, checksum, value)
|
|
|
|
|
|
|
|
def export(self, version, pkgarch, checksum, colinfo):
|
|
|
|
metainfo = {}
|
|
|
|
#column info
|
|
|
|
if colinfo:
|
|
|
|
metainfo['tbl_name'] = self.table
|
|
|
|
metainfo['core_ver'] = prserv.__version__
|
|
|
|
metainfo['col_info'] = []
|
|
|
|
data = self._execute("PRAGMA table_info(%s);" % self.table)
|
|
|
|
for row in data:
|
|
|
|
col = {}
|
|
|
|
col['name'] = row['name']
|
|
|
|
col['type'] = row['type']
|
|
|
|
col['notnull'] = row['notnull']
|
|
|
|
col['dflt_value'] = row['dflt_value']
|
|
|
|
col['pk'] = row['pk']
|
|
|
|
metainfo['col_info'].append(col)
|
|
|
|
|
|
|
|
#data info
|
|
|
|
datainfo = []
|
|
|
|
|
|
|
|
if self.nohist:
|
|
|
|
sqlstmt = "SELECT T1.version, T1.pkgarch, T1.checksum, T1.value FROM %s as T1, \
|
|
|
|
(SELECT version,pkgarch,max(value) as maxvalue FROM %s GROUP BY version,pkgarch) as T2 \
|
|
|
|
WHERE T1.version=T2.version AND T1.pkgarch=T2.pkgarch AND T1.value=T2.maxvalue " % (self.table, self.table)
|
|
|
|
else:
|
|
|
|
sqlstmt = "SELECT * FROM %s as T1 WHERE 1=1 " % self.table
|
|
|
|
sqlarg = []
|
|
|
|
where = ""
|
|
|
|
if version:
|
|
|
|
where += "AND T1.version=? "
|
|
|
|
sqlarg.append(str(version))
|
|
|
|
if pkgarch:
|
|
|
|
where += "AND T1.pkgarch=? "
|
|
|
|
sqlarg.append(str(pkgarch))
|
|
|
|
if checksum:
|
|
|
|
where += "AND T1.checksum=? "
|
|
|
|
sqlarg.append(str(checksum))
|
|
|
|
|
|
|
|
sqlstmt += where + ";"
|
|
|
|
|
|
|
|
if len(sqlarg):
|
|
|
|
data = self._execute(sqlstmt, tuple(sqlarg))
|
|
|
|
else:
|
|
|
|
data = self._execute(sqlstmt)
|
|
|
|
for row in data:
|
|
|
|
if row['version']:
|
|
|
|
col = {}
|
|
|
|
col['version'] = row['version']
|
|
|
|
col['pkgarch'] = row['pkgarch']
|
|
|
|
col['checksum'] = row['checksum']
|
|
|
|
col['value'] = row['value']
|
|
|
|
datainfo.append(col)
|
|
|
|
return (metainfo, datainfo)
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
class PRData(object):
|
|
|
|
"""Object representing the PR database"""
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
def __init__(self, filename, nohist=True):
|
2011-05-27 06:31:45 +00:00
|
|
|
self.filename=os.path.abspath(filename)
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
self.nohist=nohist
|
2011-05-27 06:31:45 +00:00
|
|
|
#build directory hierarchy
|
|
|
|
try:
|
|
|
|
os.makedirs(os.path.dirname(self.filename))
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.EEXIST:
|
|
|
|
raise e
|
2013-08-31 22:42:57 +00:00
|
|
|
self.connection=sqlite3.connect(self.filename, isolation_level="EXCLUSIVE", check_same_thread = False)
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
self.connection.row_factory=sqlite3.Row
|
2011-05-27 06:31:45 +00:00
|
|
|
self._tables={}
|
|
|
|
|
|
|
|
def __del__(self):
|
|
|
|
self.connection.close()
|
|
|
|
|
|
|
|
def __getitem__(self,tblname):
|
|
|
|
if not isinstance(tblname, basestring):
|
|
|
|
raise TypeError("tblname argument must be a string, not '%s'" %
|
|
|
|
type(tblname))
|
|
|
|
if tblname in self._tables:
|
|
|
|
return self._tables[tblname]
|
|
|
|
else:
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
tableobj = self._tables[tblname] = PRTable(self.connection, tblname, self.nohist)
|
2011-05-27 06:31:45 +00:00
|
|
|
return tableobj
|
|
|
|
|
|
|
|
def __delitem__(self, tblname):
|
|
|
|
if tblname in self._tables:
|
|
|
|
del self._tables[tblname]
|
2012-01-10 06:13:50 +00:00
|
|
|
logger.info("drop table %s" % (tblname))
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
self.connection.execute("DROP TABLE IF EXISTS %s;" % tblname)
|